]> git.sesse.net Git - backup.sh/blobdiff - backup.sh
Support changing compressors (e.g. to get zstd or xz).
[backup.sh] / backup.sh
index b808d5611e49636cec8adf41705ab2f7b6aaac01..e64312f529f68b3021a2751c2c75ef186092f85a 100755 (executable)
--- a/backup.sh
+++ b/backup.sh
@@ -90,7 +90,7 @@ backup()
 
        localsnar="${storagedir}/${computer}/${sfilesystem}/.incremental.snar"
        remotesnar="$remotehome/.backup/${sfilesystem}.snar"
-       if [ "$backuplevel" = "daglig" ]; then
+       if [ "$backuplevel" = "daily" ]; then
                # If incremental backup, we need to copy the incremental status to $computer.
                # If it does not exist, whine a bit and then run date-based instead.
                if [ -s "$localsnar" ]; then
@@ -117,6 +117,13 @@ backup()
        # a GPG command line.
        storageprogram=$( findconf storageprogram $computer $sfilesystem )
 
+       # Find compressor and decompressor for this filesystem.
+       fscompressor=$( findconf compressor $computer $filesystem )
+       if [ -z "$fscompressor" ]; then
+               fscompressor=$compressor
+       fi
+       decompressor=$( findconf decompressor $computer $filesystem )
+
        # We try to run tar on the remote computer
        #    c create archive
        #    C change to directory first
@@ -128,8 +135,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 tar --one-file-system --use-compress-program $compressor -cf - -C $filesystem . $lastcmd \
-               --exclude-from=$remotehome/.backup/exclude\" | pee \"$storageprogram > $TARFILE\" \"tar tzvf -\""
+       TARCMD="ssh -n $username@$computer \"$nice tar --one-file-system --use-compress-program $fscompressor -cf - -C $filesystem . $lastcmd \
+               --exclude-from=$remotehome/.backup/exclude\" | pee \"$storageprogram > $TARFILE\" \"$decompressor | tar tvf -\""
        infomsg "Running $TARCMD"
        eval $TARCMD > $DATE.idx
 
@@ -177,7 +184,7 @@ nonprivbackup()
 {
        infomsg "$computer:$filesystem $backuplevel non-privileged backup"
 
-       if [ "$backuplevel" = "daglig" ]; then
+       if [ "$backuplevel" = "daily" ]; then
                lastd=`cat ../.date`
                lastcmd="'$lastd'"
        else
@@ -236,12 +243,15 @@ if [ -z "$remotehome" ]; then
        diemsg "Could not expand ~ for user $username"
 fi
 
-# Check if pigz is available
-if ssh -n $username@$computer "pigz -V 2>/dev/null"; then
-       compressor=pigz
-else
-       infomsg "pigz missing; falling back to gzip."
-       compressor=gzip
+# Check if pigz is available. Note that this may be overridden per-filesystem later.
+compressor=$( findconf compressor $computer )
+if [ -z "$compressor" ]; then
+       if ssh -n $username@$computer "pigz -V 2>/dev/null"; then
+               compressor=pigz
+       else
+               infomsg "pigz missing; falling back to gzip."
+               compressor=gzip
+       fi
 fi
 
 # Check if nice and ionice are available
@@ -292,10 +302,10 @@ for filesystem in $filesystems; do
 
        # Prepare storage area
        mkdir -m 755 -p $storagedir/$computer/$sfilesystem/full 2>/dev/null
-       mkdir -m 755 -p $storagedir/$computer/$sfilesystem/daglig 2>/dev/null
+       mkdir -m 755 -p $storagedir/$computer/$sfilesystem/daily 2>/dev/null
 
        # Default backuplevel
-       backuplevel=daglig
+       backuplevel=daily
 
        if [ ! -s $storagedir/$computer/$sfilesystem/.date ]; then
                # Take the first full backup of this filesystem on this computer
@@ -339,7 +349,7 @@ for filesystem in $filesystems; do
        # Delete incremental backups older than the oldest full backup
        oldf=`ls -t1 $storagedir/$computer/$sfilesystem/full/*tgz* | tail -1`
        find \
-               $storagedir/$computer/$sfilesystem/daglig \
+               $storagedir/$computer/$sfilesystem/daily \
                -type f \
                \! -newer $oldf \
                -printf "`date`: $computer: Deleting old incremental backup: %p\n" \