1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
3 # duplicity script for backupninja
8 getconf testconnect yes
24 getconf incremental yes
27 getconf bandwidthlimit 0
33 [ "$destdir" != "" ] || fatal "Destination directory not set"
34 [ "$include" != "" ] || fatal "No source includes specified"
36 ### vservers stuff ###
38 # If vservers are configured, check that the ones listed in $vsnames do exist.
40 if [ $vservers_are_available = yes ]; then
41 if [ "$vsnames" = all ]; then
42 vsnames="$found_vservers"
44 if ! vservers_exist "$vsnames" ; then
45 fatal "At least one of the vservers listed in vsnames ($vsnames) does not exist."
48 if [ -n "$vsinclude" ]; then
49 info "Using vservers '$vsnames'"
53 [ -z "$vsinclude" ] || warning 'vservers support disabled in backupninja.conf, vsincludes configuration lines will be ignored'
54 [ -z "$vsnames" ] || warning 'vservers support disabled in backupninja.conf, vsnames configuration line will be ignored'
57 ### see if we can login ###
59 if [ "$testconnect" == "yes" ]; then
60 debug "ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'"
62 result=`ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'`
63 if [ "$result" != "1" ]; then
64 fatal "Can't connect to $desthost as $destuser."
66 debug "Connected to $desthost as $destuser successfully"
71 ### COMMAND-LINE MANGLING ###
73 scpoptions="$sshoptions"
74 [ "$bandwidthlimit" == 0 ] || scpoptions="$scpoptions -l $bandwidthlimit"
76 execstr="$options --no-print-statistics --scp-command 'scp $scpoptions' --ssh-command 'ssh $sshoptions' "
78 # deal with symmetric or asymmetric (public/private key pair) encryption
79 if [ -n "$encryptkey" ]; then
80 execstr="${execstr}--encrypt-key $encryptkey "
81 debug "Data will be encrypted with the GnuPG key $encryptkey."
83 [ -n "$password" ] || fatal "The password option must be set when using symmetric encryption."
84 debug "Data will be encrypted using symmetric encryption."
87 # deal with data signing
88 if [ "$sign" == yes ]; then
89 # duplicity is not able to sign data when using symmetric encryption
90 [ -n "$encryptkey" ] || fatal "The encryptkey option must be set when signing."
91 # if needed, initialize signkey to a value that is not empty (checked above)
92 [ -n "$signkey" ] || signkey="$encryptkey"
93 # check password validity
94 [ -n "$password" ] || fatal "The password option must be set when signing."
95 execstr="${execstr}--sign-key $signkey "
96 debug "Data will be signed will the GnuPG key $signkey."
98 debug "Data won't be signed."
101 if [ "$keep" != "yes" ]; then
102 if [ "`echo $keep | tr -d 0-9`" == "" ]; then
105 execstr="${execstr}--remove-older-than $keep "
108 if [ "$incremental" == "no" ]; then
109 execstr="${execstr}--full "
112 execstr_serverpart="scp://$destuser@$desthost/$destdir"
113 execstr_clientpart="/"
120 for i in $exclude; do
121 str="${i//__star__/*}"
122 execstr="${execstr}--exclude '$str' "
126 for i in $include; do
127 str="${i//__star__/*}"
128 execstr="${execstr}--include '$str' "
132 if [ $usevserver = yes ]; then
133 for vserver in $vsnames; do
134 for vi in $vsinclude; do
135 str="${vi//__star__/*}"
136 execstr="${execstr}--include '$VROOTDIR/$vserver$str' "
145 # exclude everything else, start with root
146 #execstr="${execstr}--exclude '**' / "
148 # include client-part and server-part
149 #execstr="$execstr $execstr_serverpart"
151 execstr=${execstr//\\*/\\\\\\*}
153 debug "duplicity $execstr --exclude '**' / $execstr_serverpart"
155 export PASSPHRASE=$password
156 output=`nice -n $nicelevel \
158 "duplicity $execstr --exclude '**' / $execstr_serverpart 2>&1"`
160 if [ $code -eq 0 ]; then
162 info "Duplicity finished successfully."
165 fatal "Duplicity failed."