Welcome! Log In Create A New Profile

Advanced

A script to backup rootfs.

Posted by syong 
A script to backup rootfs.
July 14, 2013 09:51PM
I use it to backup my rootfs on a 2G USB stick and transfer my rootfs to a NSA320 from POGO E02.

(%3)(21:40)(punk)~> sudo cat /root/bin/dumpdisk
#!/bin/sh

if [ $# -ne 1 -a $# -ne 2 ] || [ ! -b $1 ]; then
        echo "`basename $0` <destination(e.g. /dev/sdc)> [hostname]"
else
        _T=ext3
        umount ${1}1
        echo "`basename $0` on `date '+%Y_%m_%d'` to $1 $2" >> /root/bin/log && \
        dd if=/dev/zero of=$1 bs=1M count=1 && \
        sync && sync && sync && \
        parted $1 --script mklabel msdos && \
        parted $1 --script mkpart primary $_T 2048s 3932159s && \
        mkfs.$_T ${1}1 && mount ${1}1 /mnt && cd /mnt && \
        dump 0af - / | restore rf - && cd / && \
        if [ $# -eq 2 ]; then
                _T=`hostname`
                sed -i "s|dc_other_hostnames='$_T'|dc_other_hostnames='$2'|" /mnt/etc/exim4/update-exim4.conf.conf
                sed -i "s|$_T|$2|" /mnt/etc/hostname
                sed -i "s|127.0.0.1\tlocalhost $_T|127.0.0.1 localhost $2|" /mnt/etc/hosts
                sed -i "s|$_T|$2|" /mnt/etc/mailname
                sed -i "s|root:x:0:0:$_T root:/root:/bin/bash|root:x:0:0:$2 root:/root:/bin/bash|" /mnt/etc/passwd
                sed -i "s|root:x:0:0:$_T root:/root:/bin/bash|root:x:0:0:$2 root:/root:/bin/bash|" /mnt/etc/passwd-
                sed -i "s|interfaces = $_T|interfaces = $2|" /mnt/etc/samba/smb.conf
        fi && \
        sync && sync && sync && \
        umount /mnt && \
        tune2fs ${1}1 -U `blkid -s UUID -o value /dev/sda1` -L USBROOT && \
        sync && sync && sync && \
        echo "Done"
fi

#parted $1 --script mkpart primary $_T 2048s 3932159s && \
#parted $1 --script mkpart primary $_T 2048s -- -1 && \

We all know that power tool is dangerous; use it with caution. No warranty granted.

-syong
Re: A script to backup rootfs.
July 14, 2013 10:35PM
Nice script!

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: