#!/bin/bash # # This is a dump script from "info tar" # with lots of modifications. # # Lots of help from info bash and from the web pages # http://www.student.nada.kth.se/~d96-jja/bash/bashtut.html # http://www.gnu.org/manual/bash/html_mono/bashref.html # Warning! \ then space at the end of a line causes no end of problems # # example recovery (done as root): # # cd /backup # tar zxvf dump0.tgz --listed-incremental dump0.inc home/bvds # tar zxvf dump1.tgz --listed-incremental dump1.inc home/bvds # tar zxvf dump2.tgz --listed-incremental dump2.inc home/bvds # # # Files to back up # files="/chez /etc /var /usr/local" # echo " backup script $0 for files" echo " ${files}" echo " This is a version for at home use" # # Zip drives are usually DOS formatted so # we have to be careful about using DOS-like names # # Directory to put backups in # dir="/backup" # # If the machine with the backup directory has # been rebooted, then the nfs volume becomes readonly. # mount $dir # # file with number of backups performed on top of # current level 0 dump. # countfile="${dir}/dump.cnt" # # # Count number of dumps and find level # if [ $# -eq 0 ]; then if [ -e $countfile ]; then count=$(( $(cat $countfile) + 1 )) level=0 j=$count until [ $j -eq 0 ]; do level=$(( $level+(j&1) )) j=$(( j>>1 )) # echo "in loop level is $level" done else echo " Can't find file $countfile, exiting" exit fi else level=$1 count=$(( (1<<$level) -1 )) fi # # This is for testing purposes # #echo "count=$count level=$level" #exit # # Move older copies to backup directory # This moves all files at the present level and higher # if [ ! -d ${dir}/backback ]; then mkdir ${dir}/backback; fi if [ ! -d ${dir}/back ]; then mkdir ${dir}/back; fi # i=$level while [ -e ${dir}/dump${i}.tgz ]; do if [ -e ${dir}/back/dump${i}.tgz ]; then mv ${dir}/back/dump${i}.* ${dir}/backback echo " Moving ${dir}/back/dump${i}.* to ${dir}/backback" fi mv ${dir}/dump${i}.* ${dir}/back echo " Moving ${dir}/dump${i}.* to ${dir}/back" i=$(( i+1 )) done # # # For dump levels higher than zero, find previous # snapshot file and copy it. # if [ $level -ne 0 ]; then datfile=${dir}/dump$(( $level -1 )).inc if [ -e $datfile ]; then cp $datfile ${dir}/dump${level}.inc else echo "Snapshot file $datfile doesn't exist, exiting" exit fi fi # # perform tar using snapshot file # # turned off verbose -v # The 2>&1 is supposed to redirect the STDERR to STDOUT # echo " Starting level $level dump, this is dump number $count." tar -z -c \ -f $dir/dump${level}.tgz\ --label="User dump on date $(date)"\ --listed-incremental=$dir/dump${level}.inc\ --exclude='/chez/carla/scratch'\ --exclude='/chez/carla/brettshome.tar.gz'\ ${files} # # save count in count file # echo $count > $countfile # # We don't want users to read the dump files # chmod 600 ${dir}/dump${level}.tgz chmod 600 ${dir}/dump${level}.inc # umount $dir #