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 # See if vservers are configured.
39 # If so, check that the ones listed in $vsnames do exist.
40 if [ "$vservers" == "yes" ]; then
41 [ -d "$VROOTDIR" ] || fatal "vservers enabled, but $VROOTDIR does not exist!"
42 if [ "$vsnames" == "all" ]; then
44 for vserver in `ls $VROOTDIR | grep -E -v "lost+found|ARCHIVES"`; do
45 vsnames="$vserver $vsnames"
48 for vserver in "$vsnames"; do
49 [ -d "$VROOTDIR/$vserver" ] || fatal "vserver '$vserver' does not exist."
52 if [ -n "$vsnames" ]; then
53 if [ -n "$vsinclude" ]; then
54 info "Using vservers '$vsnames'"
58 [ -z "$vsinclude" ] || warning 'vsnames is empty, vsinclude configuration lines will be ignored'
61 [ -z "$vsinclude" ] || warning 'vservers support disabled in backupninja.conf, vsincludes configuration lines will be ignored'
62 [ -z "$vsnames" ] || warning 'vservers support disabled in backupninja.conf, vsnames configuration line will be ignored'
65 ### see if we can login ###
67 if [ "$testconnect" == "yes" ]; then
68 debug "ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'"
70 result=`ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'`
71 if [ "$result" != "1" ]; then
72 fatal "Can't connect to $desthost as $destuser."
74 debug "Connected to $desthost as $destuser successfully"
79 ### COMMAND-LINE MANGLING ###
81 scpoptions="$sshoptions"
82 [ "$bandwidthlimit" == 0 ] || scpoptions="$scpoptions -l $bandwidthlimit"
84 execstr="$options --no-print-statistics --scp-command 'scp $scpoptions' --ssh-command 'ssh $sshoptions' "
86 # deal with symmetric or asymmetric (public/private key pair) encryption
87 if [ -n "$encryptkey" ]; then
88 execstr="${execstr}--encrypt-key $encryptkey "
89 debug "Data will be encrypted with the GnuPG key $encryptkey."
91 [ -n "$password" ] || fatal "The password option must be set when using symmetric encryption."
92 debug "Data will be encrypted using symmetric encryption."
95 # deal with data signing
96 if [ "$sign" == yes ]; then
97 # duplicity is not able to sign data when using symmetric encryption
98 [ -n "$encryptkey" ] || fatal "The encryptkey option must be set when signing."
99 # if needed, initialize signkey to a value that is not empty (checked above)
100 [ -n "$signkey" ] || signkey="$encryptkey"
101 # check password validity
102 [ -n "$password" ] || fatal "The password option must be set when signing."
103 execstr="${execstr}--sign-key $signkey "
104 debug "Data will be signed will the GnuPG key $signkey."
106 debug "Data won't be signed."
109 if [ "$keep" != "yes" ]; then
110 if [ "`echo $keep | tr -d 0-9`" == "" ]; then
113 execstr="${execstr}--remove-older-than $keep "
116 if [ "$incremental" == "no" ]; then
117 execstr="${execstr}--full "
120 execstr_serverpart="scp://$destuser@$desthost/$destdir"
121 execstr_clientpart="/"
126 for i in "$exclude"; do
127 str="${i//__star__/*}"
128 execstr="${execstr}--exclude '$str' "
132 for i in "$include"; do
133 str="${i//__star__/*}"
134 execstr="${execstr}--include '$str' "
138 if [ $usevserver ]; then
139 for vserver in $vsnames; do
140 for vi in "$vsinclude"; do
141 str="${vi//__star__/*}"
142 execstr="${execstr}--include '$VROOTDIR/$vserver$str' "
149 # exclude everything else, start with root
150 #execstr="${execstr}--exclude '**' / "
152 # include client-part and server-part
153 #execstr="$execstr $execstr_serverpart"
155 execstr=${execstr//\\*/\\\\\\*}
157 debug "duplicity $execstr --exclude '**' / $execstr_serverpart"
159 export PASSPHRASE=$password
160 output=`nice -n $nicelevel \
162 "duplicity $execstr --exclude '**' / $execstr_serverpart 2>&1"`
164 if [ $code -eq 0 ]; then
166 info "Duplicity finished successfully."
169 fatal "Duplicity failed."