dup: new tmpdir config option, useful when duplicity fills up /tmp
[matthijs/upstream/backupninja.git] / handlers / dup.in
index 9848cbc024e981acb5b6c0f09ea91e97de0c184d..417b625d94df012e059589379440d14070231fcf 100644 (file)
@@ -7,6 +7,7 @@
 getconf options
 getconf testconnect yes
 getconf nicelevel 0
+getconf tmpdir
 
 setsection gpg
 getconf password
@@ -89,7 +90,7 @@ scpoptions="$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" -le 2 ]; then
+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
@@ -170,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