dup: new tmpdir config option, useful when duplicity fills up /tmp
[matthijs/upstream/backupninja.git] / handlers / dup.in
index edb43ac4b90ddcf8b732f92ae9e7811692e1f48d..417b625d94df012e059589379440d14070231fcf 100644 (file)
@@ -7,6 +7,7 @@
 getconf options
 getconf testconnect yes
 getconf nicelevel 0
+getconf tmpdir
 
 setsection gpg
 getconf password
@@ -70,22 +71,37 @@ fi
 
 ### COMMAND-LINE MANGLING ###
 
-# duplicity >= 0.4.2 needs --sftp-command (NB: sftp does not support the -l option)
 duplicity_version="`duplicity --version | @AWK@ '{print $2}'`"
 duplicity_major="`echo $duplicity_version | @AWK@ -F '.' '{print $1}'`"
 duplicity_minor="`echo $duplicity_version | @AWK@ -F '.' '{print $2}'`"
 duplicity_sub="`echo $duplicity_version | @AWK@ -F '.' '{print $3}'`"
-if [ "$duplicity_major" -ge 0 -a "$duplicity_minor" -ge 4 -a "$duplicity_sub" -ge 2 ]; then
-   sftpoptions="$sshoptions"
-fi
+
+# 1. duplicity >= 0.4.2 needs --sftp-command (NB: sftp does not support the -l option)
+# 2. duplicity >= 0.4.3 replaces --ssh-command with --ssh-options, which:
+#      - is passed to scp and sftp commands by duplicity
+#      - has a special syntax we can not feed the command line with
+#    so we don't use it: since this version does not use the ssh command anymore,
+#    we keep compatibility with our previous config files by passing $sshoptions to
+#    --scp-command and --sftp-command ourselves
 
 scpoptions="$sshoptions"
 [ "$bandwidthlimit" == 0 ] || scpoptions="$scpoptions -l $bandwidthlimit"
 
-if [ -z "$sftpoptions" ]; then
-   execstr="$options --no-print-statistics --scp-command 'scp $scpoptions' --ssh-command 'ssh $sshoptions' "
+execstr="$options --no-print-statistics "
+
+# < 0.4.2 : only uses ssh and scp
+if [ "$duplicity_major" -le 0 -a "$duplicity_minor" -le 4 -a "$duplicity_sub" -lt 2 ]; then
+   execstr="$execstr --scp-command 'scp $scpoptions' --ssh-command 'ssh $sshoptions' "
+# >= 0.4.2 : also uses sftp, --sftp-command option is now supported
 else
-   execstr="$options --no-print-statistics --scp-command 'scp $scpoptions' --sftp-command 'sftp $sftpoptions' --ssh-command 'ssh $sshoptions' "
+   sftpoptions="$sshoptions"
+   # == 0.4.2 : uses ssh, scp and sftp
+   if [ "$duplicity_major" -eq 0 -a "$duplicity_minor" -eq 4 -a "$duplicity_sub" -eq 2 ]; then
+      execstr="$execstr --scp-command 'scp $scpoptions' --sftp-command 'sftp $sftpoptions' --ssh-command 'ssh $sshoptions' "
+   # >= 0.4.3 : uses only scp and sftp, --ssh-command option is not supported anymore
+   else
+      execstr="$execstr --scp-command 'scp $scpoptions' --sftp-command 'sftp $sftpoptions' "
+   fi
 fi
 
 # deal with symmetric or asymmetric (public/private key pair) encryption
@@ -155,16 +171,28 @@ fi
 
 set +o noglob
 
+### deal with tmpdir ###
+precmd=
+if [ -n "$tmpdir" ]; then
+   if [ ! -d "$tmpdir" ]; then
+      info "Temporary directory ($tmpdir) does not exist, creating it."
+      mkdir -p "$tmpdir"
+      [ $? -eq 0 ] || fatal "Could not create temporary directory ($tmpdir)."
+   fi
+   info "Using $tmpdir as TMPDIR"
+   precmd="${precmd}TMPDIR=$tmpdir "
+fi
+
 ### EXECUTE ###
 
 execstr=${execstr//\\*/\\\\\\*}
 
-debug "duplicity $execstr --exclude '**' / $execstr_serverpart"
+debug "$precmd duplicity $execstr --exclude '**' / $execstr_serverpart"
 if [ ! $test ]; then
         export PASSPHRASE=$password
        output=`nice -n $nicelevel \
                   su -c \
-                    "duplicity $execstr --exclude '**' / $execstr_serverpart 2>&1"`
+                    "$precmd duplicity $execstr --exclude '**' / $execstr_serverpart 2>&1"`
        code=$?
        if [ $code -eq 0 ]; then
                debug $output