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'
56 ### see if we can login ###
58 if [ "$testconnect" == "yes" ]; then
59 debug "ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'"
61 result=`ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'`
62 if [ "$result" != "1" ]; then
63 fatal "Can't connect to $desthost as $destuser."
65 debug "Connected to $desthost as $destuser successfully"
70 ### COMMAND-LINE MANGLING ###
72 scpoptions="$sshoptions"
73 [ "$bandwidthlimit" == 0 ] || scpoptions="$scpoptions -l $bandwidthlimit"
75 execstr="$options --no-print-statistics --scp-command 'scp $scpoptions' --ssh-command 'ssh $sshoptions' "
77 # deal with symmetric or asymmetric (public/private key pair) encryption
78 if [ -n "$encryptkey" ]; then
79 execstr="${execstr}--encrypt-key $encryptkey "
80 debug "Data will be encrypted with the GnuPG key $encryptkey."
82 [ -n "$password" ] || fatal "The password option must be set when using symmetric encryption."
83 debug "Data will be encrypted using symmetric encryption."
86 # deal with data signing
87 if [ "$sign" == yes ]; then
88 # duplicity is not able to sign data when using symmetric encryption
89 [ -n "$encryptkey" ] || fatal "The encryptkey option must be set when signing."
90 # if needed, initialize signkey to a value that is not empty (checked above)
91 [ -n "$signkey" ] || signkey="$encryptkey"
92 # check password validity
93 [ -n "$password" ] || fatal "The password option must be set when signing."
94 execstr="${execstr}--sign-key $signkey "
95 debug "Data will be signed will the GnuPG key $signkey."
97 debug "Data won't be signed."
100 if [ "$keep" != "yes" ]; then
101 if [ "`echo $keep | tr -d 0-9`" == "" ]; then
104 execstr="${execstr}--remove-older-than $keep "
107 if [ "$incremental" == "no" ]; then
108 execstr="${execstr}--full "
111 execstr_serverpart="scp://$destuser@$desthost/$destdir"
112 execstr_clientpart="/"
119 for i in $exclude; do
120 str="${i//__star__/*}"
121 i=`readlink -f ${i#}`
122 execstr="${execstr}--exclude '$str' "
126 for i in $include; do
127 str="${i//__star__/*}"
128 i=`readlink -f ${i#}`
129 execstr="${execstr}--include '$str' "
133 if [ $usevserver = yes ]; then
134 for vserver in $vsnames; do
135 for vi in $vsinclude; do
136 i=`readlink -f $VROOTDIR/$vserver$vi`
137 str="${i//__star__/*}"
138 execstr="${execstr}--include '$VROOTDIR/$vserver$str' "
147 # exclude everything else, start with root
148 #execstr="${execstr}--exclude '**' / "
150 # include client-part and server-part
151 #execstr="$execstr $execstr_serverpart"
153 execstr=${execstr//\\*/\\\\\\*}
155 debug "duplicity $execstr --exclude '**' / $execstr_serverpart"
157 export PASSPHRASE=$password
158 output=`nice -n $nicelevel \
160 "duplicity $execstr --exclude '**' / $execstr_serverpart 2>&1"`
162 if [ $code -eq 0 ]; then
164 info "Duplicity finished successfully."
167 fatal "Duplicity failed."