From 875b0af73ff25c6f85097b05820ae9f0c0894486 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 9 Dec 2018 22:24:09 +0100 Subject: [PATCH] Support changing compressors (e.g. to get zstd or xz). --- backup.sh | 26 ++++++++++++++++++-------- conf/backup.config.example | 11 +++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/backup.sh b/backup.sh index dfe8d45..e64312f 100755 --- a/backup.sh +++ b/backup.sh @@ -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 @@ -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 diff --git a/conf/backup.config.example b/conf/backup.config.example index 254092d..0324ae7 100644 --- a/conf/backup.config.example +++ b/conf/backup.config.example @@ -38,6 +38,17 @@ # Otherwise, assume root privileges. nonpriv = + # If set, use the given program to compress and decompress the backup + # (compressor must exist on the host to be backed up, and decompressor + # must exist on the backup host). compressor can be unset; if so, + # either pigz or gzip (autodetected) will be used. You can give flags + # (e.g. -9) if you wish. + # + # Not used for nonpriv (change output-encrypted-backup instead). + # The file will be called .tgz no matter what the compressor is. + compressor = + decompressor = gzip -d + # Config for a given host [pannekake.samfundet.no] maxnumfull = 2 -- 2.39.2