1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
3 # duplicity script for backupninja
8 getconf testconnect yes
25 getconf incremental yes
28 getconf bandwidthlimit 0
34 [ "$destdir" != "" ] || fatal "Destination directory not set"
35 [ "$include" != "" ] || fatal "No source includes specified"
37 ### vservers stuff ###
39 # If vservers are configured, check that the ones listed in $vsnames do exist.
41 if [ $vservers_are_available = yes ]; then
42 if [ "$vsnames" = all ]; then
43 vsnames="$found_vservers"
45 if ! vservers_exist "$vsnames" ; then
46 fatal "At least one of the vservers listed in vsnames ($vsnames) does not exist."
49 if [ -n "$vsinclude" ]; then
50 info "Using vservers '$vsnames'"
54 [ -z "$vsinclude" ] || warning 'vservers support disabled in backupninja.conf, vsincludes configuration lines will be ignored'
58 ### see if we can login ###
60 if [ "$testconnect" == "yes" ]; then
61 debug "ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'"
63 result=`ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'`
64 if [ "$result" != "1" ]; then
65 fatal "Can't connect to $desthost as $destuser."
67 debug "Connected to $desthost as $destuser successfully"
72 ### COMMAND-LINE MANGLING ###
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}'`"
79 # 1. duplicity >= 0.4.2 needs --sftp-command (NB: sftp does not support the -l option)
80 # 2. duplicity >= 0.4.3 replaces --ssh-command with --ssh-options, which:
81 # - is passed to scp and sftp commands by duplicity
82 # - has a special syntax we can not directly feed the command line with
83 # (e.g. "IdentityFile=/root/.ssh/id_dsa_backupninja Port=2222", without the -o)
84 # so we don't use it: since this version does not use the ssh command anymore,
85 # we keep compatibility with our previous config files by passing $sshoptions to
86 # --scp-command and --sftp-command ourselves
88 scpoptions="$sshoptions"
89 [ "$bandwidthlimit" == 0 ] || scpoptions="$scpoptions -l $bandwidthlimit"
91 execstr="$options --no-print-statistics "
93 # < 0.4.2 : only uses ssh and scp
94 if [ "$duplicity_major" -le 0 -a "$duplicity_minor" -le 4 -a "$duplicity_sub" -lt 2 ]; then
95 execstr="$execstr --scp-command 'scp $scpoptions' --ssh-command 'ssh $sshoptions' "
96 # >= 0.4.2 : also uses sftp, --sftp-command option is now supported
98 sftpoptions="$sshoptions"
99 # == 0.4.2 : uses ssh, scp and sftp
100 if [ "$duplicity_major" -eq 0 -a "$duplicity_minor" -eq 4 -a "$duplicity_sub" -eq 2 ]; then
101 execstr="$execstr --scp-command 'scp $scpoptions' --sftp-command 'sftp $sftpoptions' --ssh-command 'ssh $sshoptions' "
102 # >= 0.4.3 : uses only scp and sftp, --ssh-command option is not supported anymore
104 execstr="$execstr --scp-command 'scp $scpoptions' --sftp-command 'sftp $sftpoptions' "
108 # deal with symmetric or asymmetric (public/private key pair) encryption
109 if [ -n "$encryptkey" ]; then
110 execstr="${execstr}--encrypt-key $encryptkey "
111 debug "Data will be encrypted with the GnuPG key $encryptkey."
113 debug "Data will be encrypted using symmetric encryption."
116 # deal with data signing
117 if [ "$sign" == yes ]; then
118 # duplicity is not able to sign data when using symmetric encryption
119 [ -n "$encryptkey" ] || fatal "The encryptkey option must be set when signing."
120 # if needed, initialize signkey to a value that is not empty (checked above)
121 [ -n "$signkey" ] || signkey="$encryptkey"
122 execstr="${execstr}--sign-key $signkey "
123 debug "Data will be signed will the GnuPG key $signkey."
125 debug "Data won't be signed."
128 # deal with GnuPG passphrase
129 [ -n "$password" ] || fatal "The password option must be set."
131 if [ "$keep" != "yes" ]; then
132 if [ "`echo $keep | tr -d 0-9`" == "" ]; then
135 execstr="${execstr}--remove-older-than $keep "
138 if [ "$incremental" == "no" ]; then
139 execstr="${execstr}--full "
142 execstr_serverpart="scp://$destuser@$desthost/$destdir"
143 execstr_clientpart="/"
150 for i in $exclude; do
151 str="${i//__star__/*}"
152 execstr="${execstr}--exclude '$str' "
156 for i in $include; do
157 [ "$i" != "/" ] || fatal "Sorry, you cannot use 'include = /'"
158 str="${i//__star__/*}"
159 execstr="${execstr}--include '$str' "
163 if [ $usevserver = yes ]; then
164 for vserver in $vsnames; do
165 for vi in $vsinclude; do
166 str="${vi//__star__/*}"
167 str="$VROOTDIR/$vserver$str"
168 execstr="${execstr}--include '$str' "
175 ### deal with tmpdir ###
177 if [ -n "$tmpdir" ]; then
178 if [ ! -d "$tmpdir" ]; then
179 info "Temporary directory ($tmpdir) does not exist, creating it."
181 [ $? -eq 0 ] || fatal "Could not create temporary directory ($tmpdir)."
183 info "Using $tmpdir as TMPDIR"
184 precmd="${precmd}TMPDIR=$tmpdir "
189 execstr=${execstr//\\*/\\\\\\*}
191 debug "$precmd duplicity $execstr --exclude '**' / $execstr_serverpart"
193 export PASSPHRASE=$password
194 output=`nice -n $nicelevel \
196 "$precmd duplicity $execstr --exclude '**' / $execstr_serverpart 2>&1"`
198 if [ $code -eq 0 ]; then
200 info "Duplicity finished successfully."
203 fatal "Duplicity failed."