]> git.sesse.net Git - backup.sh/blobdiff - backup.sh
Deal with nice and/or ionice not existing on the target system.
[backup.sh] / backup.sh
index 7fc7ffb0018fecd951b3d64249637aa5ea28cc71..71ebfe1084897fe525dd14091340d4c100a74ccb 100755 (executable)
--- a/backup.sh
+++ b/backup.sh
@@ -107,6 +107,16 @@ backup()
                lastcmd="--listed-incremental=$remotesnar"
        fi
 
+       # The file is usually stored to disk with a simple cat > $TARFILE,
+       # but in some cases, like backing up to a remote and untrusted
+       # file system, it could be useful to replace it with e.g.
+       # a GPG command line.
+       if [ -f $confdir/storageprogram.$computer ]; then
+               storageprogram=`cat $confdir/storageprogram.$computer`
+       else
+               storageprogram=cat
+       fi
+
        # We try to run tar on the remote computer
        #    c create archive
        #    C change to directory first
@@ -118,8 +128,8 @@ backup()
        #    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 -n $username@$computer \"nice -n 19 ionice -c3 tar --one-file-system --use-compress-program $compressor -cf - -C $filesystem . $lastcmd \
-               --exclude-from=$remotehome/.backup/exclude\" | pee \"cat > $TARFILE\" \"tar tzvf -\""
+       TARCMD="ssh -n $username@$computer \"$nice tar --one-file-system --use-compress-program $compressor -cf - -C $filesystem . $lastcmd \
+               --exclude-from=$remotehome/.backup/exclude\" | pee \"$storageprogram > $TARFILE\" \"tar tzvf -\""
        infomsg "Running $TARCMD"
        eval $TARCMD > $DATE.idx
 
@@ -161,6 +171,8 @@ backup()
 #  - No touching of .lastbackup for Nagios.
 #  - Failed tar operations may go undetected, since we only see the error code
 #    the last process in the pipe chain, which is gpg.
+#  - No storageprogram support (see above), because the file is typically already
+#    encrypted.
 nonprivbackup()
 {
        infomsg "$computer:$filesystem $backuplevel non-privileged backup"
@@ -234,6 +246,14 @@ else
        compressor=gzip
 fi
 
+# Check if nice and ionice are available
+if ssh -n $username@$computer "nice -n 19 ionice -c3 /bin/true 2>/dev/null"; then
+       nice="nice -n 19 ionice -c3"
+else
+       infomsg "nice and/or ionice missing; will run at normal priority."
+       nice=""
+fi
+
 # Check dump bit in fstab
 filesystems=`ssh -n $username@$computer "cat /etc/fstab" \
        | grep -v nfs \
@@ -315,7 +335,7 @@ for filesystem in $filesystems; do
 
        # Check if this box has a custom number of full backups
        if [ -f $confdir/maksfulle.$computer.$sfilesystem ]; then
-               mf=$((`cat $confdir/maksfulle.$computer`+1))
+               mf=$((`cat $confdir/maksfulle.$computer.$sfilesystem`+1))
        elif [ -f $confdir/maksfulle.$computer ] ; then
                mf=$((`cat $confdir/maksfulle.$computer`+1))
        else