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'
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 # duplicity >= 0.4.2 needs --sftp-command (NB: sftp does not support the -l option)
74 duplicity_version="`duplicity --version | awk '{print $2}'`"
75 duplicity_major="`echo $duplicity_version | awk -F '.' '{print $1}'`"
76 duplicity_minor="`echo $duplicity_version | awk -F '.' '{print $2}'`"
77 duplicity_sub="`echo $duplicity_version | awk -F '.' '{print $3}'`"
78 if [ "$duplicity_major" -ge 0 -a "$duplicity_minor" -ge 4 -a "$duplicity_sub" -ge 2 ]; then
79 sftpoptions="$sshoptions"
82 scpoptions="$sshoptions"
83 [ "$bandwidthlimit" == 0 ] || scpoptions="$scpoptions -l $bandwidthlimit"
85 if [ -z "$sftpoptions" ]; then
86 execstr="$options --no-print-statistics --scp-command 'scp $scpoptions' --ssh-command 'ssh $sshoptions' "
88 execstr="$options --no-print-statistics --scp-command 'scp $scpoptions' --sftp-command 'sftp $sftpoptions' --ssh-command 'ssh $sshoptions' "
91 # deal with symmetric or asymmetric (public/private key pair) encryption
92 if [ -n "$encryptkey" ]; then
93 execstr="${execstr}--encrypt-key $encryptkey "
94 debug "Data will be encrypted with the GnuPG key $encryptkey."
96 debug "Data will be encrypted using symmetric encryption."
99 # deal with data signing
100 if [ "$sign" == yes ]; then
101 # duplicity is not able to sign data when using symmetric encryption
102 [ -n "$encryptkey" ] || fatal "The encryptkey option must be set when signing."
103 # if needed, initialize signkey to a value that is not empty (checked above)
104 [ -n "$signkey" ] || signkey="$encryptkey"
105 execstr="${execstr}--sign-key $signkey "
106 debug "Data will be signed will the GnuPG key $signkey."
108 debug "Data won't be signed."
111 # deal with GnuPG passphrase
112 [ -n "$password" ] || fatal "The password option must be set."
114 if [ "$keep" != "yes" ]; then
115 if [ "`echo $keep | tr -d 0-9`" == "" ]; then
118 execstr="${execstr}--remove-older-than $keep "
121 if [ "$incremental" == "no" ]; then
122 execstr="${execstr}--full "
125 execstr_serverpart="scp://$destuser@$desthost/$destdir"
126 execstr_clientpart="/"
132 symlinks_warning="Maybe you have mixed symlinks and '*' in this statement, which is not supported."
135 for i in $exclude; do
136 str="${i//__star__/*}"
137 str=`readlink -f $str`
138 if [ -n "$str" ]; then
139 execstr="${execstr}--exclude '$str' "
141 warning "exclude statement ${i//__star__/*} will be ignored. $symlinks_warning"
146 for i in $include; do
147 [ "$i" != "/" ] || fatal "Sorry, you cannot use 'include = /'"
148 str="${i//__star__/*}"
149 str=`readlink -f $str`
150 if [ -n "$str" ]; then
151 execstr="${execstr}--include '$str' "
153 warning "include statement ${i//__star__/*} will be ignored. $symlinks_warning"
158 if [ $usevserver = yes ]; then
159 for vserver in $vsnames; do
160 for vi in $vsinclude; do
161 str="${vi//__star__/*}"
162 str=`readlink -f $VROOTDIR/$vserver$str`
163 if [ -n "$str" ]; then
164 execstr="${execstr}--include '$str' "
166 warning "vsinclude statement ${vi//__star__/*} will be ignored for VServer $vserver. $symlinks_warning"
176 execstr=${execstr//\\*/\\\\\\*}
178 debug "duplicity $execstr --exclude '**' / $execstr_serverpart"
180 export PASSPHRASE=$password
181 output=`nice -n $nicelevel \
183 "duplicity $execstr --exclude '**' / $execstr_serverpart 2>&1"`
185 if [ $code -eq 0 ]; then
187 info "Duplicity finished successfully."
190 fatal "Duplicity failed."