X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=backup.sh;h=1c188b2dc8441f575d692c2970b187521aee1281;hb=a886ec4506ccd6939637e0412b0b053efb666418;hp=ce6c6d4cac516305b35b52b14c9cc613b5d713ef;hpb=64da3228b66d5687c89f26328ed354ccdcd02aea;p=backup.sh diff --git a/backup.sh b/backup.sh index ce6c6d4..1c188b2 100755 --- a/backup.sh +++ b/backup.sh @@ -20,13 +20,6 @@ # # The script is halfway Norwegian and halfway English. Newer modifications are # in English, we should probably stick to that. -# -# Known issues: -# -# o $R has no proper meaning because of the forking subshell stuff. We need a -# more robust way of returning non-zero on errors, which we probably don't -# right now. -# # The computer to backup. computer=$1 @@ -70,15 +63,6 @@ fi; touch $LOCKFILE echo $$ > $LOCKFILE -#syntax of remotestat: -#hostname:/directory/ -remotestatf=$confdir/remotestat -[ -f $remotestatf ] && remotestat=`cat $remotestatf` -### - -PATH=/local/bin:$PATH:/store/bin -export PATH - echo `date`": Backup run starting" >&2 umask 027 @@ -93,7 +77,7 @@ backup() echo -n `date` >&2 printf " $computer: $computer:$filesystem $backuplevel backup\n" >&2 - if [ "$backuplevel" = "daglig" ] || [ "$backuplevel" = "incremental" ] + if [ "$backuplevel" = "daglig" ] then lastd=`cat ../.date` lastcmd="--newer='$lastd'" @@ -105,23 +89,23 @@ backup() exf=`ssh root@$computer "ls ~/.backup/exclude"` # We try to run tar on the remote computer - # z gzip it # c create archive # C change to directory first # . where to start taring (see C) # $lastcmd only files newer than this # --one-file-system don't traverse file systems + # --use-compress-program compress it using gzip or pigz # --exclude-from file to get exclusion pattern from # Pipe the stuff over ssh to ourselves, run pee to cat the contents to a # file and build a file list, respectivly. TARFILE=$DATE.tmp - TARCMD="ssh root@$computer \"nice -n 19 ionice -c3 tar --one-file-system -zcf - -C $filesystem . $lastcmd \ + TARCMD="ssh root@$computer \"nice -n 19 ionice -c3 tar --one-file-system --use-compress-program $compressor -cf - -C $filesystem . $lastcmd \ --exclude-from=$exf\" | pee \"cat > $TARFILE\" \"tar tzvf -\"" echo `date`" $computer: Running $TARCMD" >&2 eval $TARCMD > $DATE.idx - if [ -s $TARFILE ]; then - # File is >0 in size, we assume it worked. + if [ $? -eq 0 ] && [ -s $TARFILE ]; then + # File is >0 in size and neither cat or tar tzvf failed; we assume it worked. # Move tar file in place mv $TARFILE $DATE.tgz @@ -152,6 +136,10 @@ backup() # Check that the target filesystem is mounted (actually check that it's not # the root filesystem) + if [ ! -d "$storagedir/$computer" ]; then + echo `date`" $computer: Target filesystem ($storagedir/$computer) does not exist. Aborting" + die + fi rootfilesystem=`df -P /` targetfilesystem=`df -P "$storagedir/$computer"` if [ "$rootfilesystem" == "$targetfilesystem" ]; then @@ -168,6 +156,14 @@ backup() # We don't want to return 0 die fi + + # Check if pigz is available + if ssh -n root@$computer "pigz -V 2>/dev/null"; then + compressor=pigz + else + echo `date`" $computer: pigz missing; falling back to gzip." + compressor=gzip + fi filesystems=""