dup: support backups to Amazon S3 buckets
[matthijs/upstream/backupninja.git] / handlers / dup.in
index 198eef72dcb46b8abeb00acac443601feaed49cf..ffae48c1bece695bcd2462f4bcc33e4929d34783 100644 (file)
@@ -26,6 +26,8 @@ setsection dest
 getconf incremental yes
 getconf keep 60
 getconf desturl
+getconf awsaccesskeyid
+getconf awssecretaccesskey
 getconf sshoptions
 getconf bandwidthlimit 0
 getconf desthost
@@ -38,6 +40,9 @@ destdir=${destdir%/}
 [ -n "$desturl" -o -n "$destdir" ]  || fatal "The destination directory (destdir) must be set when desturl is not used."
 [ -n "$include" -o -n "$vsinclude" ]  || fatal "No source includes specified"
 [ -n "$password" ] || fatal "The password option must be set."
+if [ "`echo $desturl | @AWK@ -F ':' '{print $1}'`" == "s3+http" ]; then
+   [ -n "$awsaccesskeyid" -a -n "$awssecretaccesskey" ]  || fatal "AWS access keys must be set for S3 backups."
+fi
 
 ### VServers
 # If vservers are configured, check that the ones listed in $vsnames do exist.
@@ -189,26 +194,35 @@ fi
 set -o noglob
 
 # excludes
+SAVEIFS=$IFS
+IFS=$(echo -en "\n\b")
 for i in $exclude; do
    str="${i//__star__/*}"
    execstr_source="${execstr_source} --exclude '$str'"
 done
+IFS=$SAVEIFS
 
 # includes
+SAVEIFS=$IFS
+IFS=$(echo -en "\n\b")
 for i in $include; do
    [ "$i" != "/" ] || fatal "Sorry, you cannot use 'include = /'"
    str="${i//__star__/*}"
    execstr_source="${execstr_source} --include '$str'"
 done
+IFS=$SAVEIFS
 
 # vsincludes
 if [ $usevserver = yes ]; then
    for vserver in $vsnames; do
+      SAVEIFS=$IFS
+      IFS=$(echo -en "\n\b")
       for vi in $vsinclude; do
          str="${vi//__star__/*}"
          str="$VROOTDIR/$vserver$str"
          execstr_source="${execstr_source} --include '$str'"
       done
+      IFS=$SAVEIFS
    done
 fi
 
@@ -218,6 +232,12 @@ set +o noglob
 
 execstr_source=${execstr_source//\\*/\\\\\\*}
 
+### If desturl is an S3 URL export the AWS environment variables
+if [ "`echo $desturl | @AWK@ -F ':' '{print $1}'`" == "s3+http" ]; then
+   export AWS_ACCESS_KEY_ID="$awsaccesskeyid"
+   export AWS_SECRET_ACCESS_KEY="$awssecretaccesskey"
+fi
+
 ### Cleanup commands (duplicity >= 0.4.4)
 
 # cleanup
@@ -271,7 +291,7 @@ if [ ! $test ]; then
    exit_code=$?
    debug $output
    cat $outputfile | (while read output ; do
-                         debug $output
+                         info $output
                       done
    )
    if [ $exit_code -eq 0 ]; then