From: Paul F. <pg...@fo...> - 2004-02-27 16:59:31
|
hello -- i know that this topic is well trodden, and i did get quite a bit of info from the archives -- if there's a FAQ i should read, please be kind. :-) i want to periodically move a copy of my backed up data out of the house. i bought a large removeable disk to use for this. i realize that copying the pool is prohibitively expensive, due to the number of hard links. i can live with that. (though it was kind of a surprise, the first time i tried. :-) so what i want is a script which creates a tarball of the current state of every share, and copies them to my removeable disk. using some examples from the archives, i've come up with the script below. i'd be happy to trade it in for someone else's well-tested version, and i'd be equally happy to have someone critique what i've done. i'm most concerned with my technique for fetching the number of the most recent backup -- is my egrep/tail/awk going to do the trick? (i read that this will be available more directly in 2.1 -- correct?) is there a more effective way to loop through the shares on all of my hosts, rather than hard-coding the list as i have done? (i think i read that this, too, is being addressed in 2.1?) and is my understanding correct, that BackupPC_tarCreate will give full contents, whether asked for a full or incremental backup? anyway, my script appears below. any comments welcome... paul p.s. and, since i'm new on the list: thanks for a _great_ backup system! i recommend it whenever the topic comes up. =--------------------- paul fox, pg...@fo... (arlington, ma, where it's 34.7 degrees) -------cut here -------- #!/bin/sh # mount a specific usb-connected disk on /offsite, create backup # tarballs there, and unmount if [ ! -f /proc/scsi/usb-storage-0/1 ] then echo no usb device found >&2 exit 1 fi if ! egrep -q 'Maxtor 5 Model: A300J0' /proc/scsi/scsi then echo wrong usb device found >&2 exit 1 fi if ! mount /offsite then echo could not mount sda1 on /offsite exit 1 fi # try to ensure we always unmount trap "umount /offsite" 0 # rotating date-based backup directories -- must be expunged manually dir=/offsite/bck/$(date +%Y-%m-%d) if ! mkdir $dir then echo could not mkdir $dir exit 1 fi # create a tarfile for a share doit() { if [ $# != 2 ] then echo doit needs two args: host and sharename exit 1 fi host=$1 share=$2 # convert '/' to '-' sharename=$(echo $share | sed -e 's/\//-/g' -e 's/^-//' ) if [ ! "$sharename" ] # all gone? must have been '/' then sharename=root fi mkdir -p $dir/$host back=$(lastback $host) bin/BackupPC_tarCreate -h $host -n $back -s $share / | gzip -c > $dir/$host/$sharename.tgz } lastback() { host=$1 log=/big/backuppc/pc/$host/LOG egrep '(full|incr) backup [[:digit:]]+ complete' $log | tail -1 | awk '{print $5}' } # enumerate the hosts, and their shares doit firethorn / doit firethorn /var doit firethorn /var2 doit tumbleweed / doit tumbleweed /boot doit grass / doit grass /boot doit gutso / doit gutso /boot doit gutso /usr2 doit gutso /dos |