1 # -*- mode: sh; sh-basic-offset: 8; 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'
62 ### see if we can login ###
64 if [ "$testconnect" == "yes" ]; then
65 debug "ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'"
67 result=`ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'`
68 if [ "$result" != "1" ]; then
69 fatal "Can't connect to $desthost as $destuser."
71 debug "Connected to $desthost as $destuser successfully"
76 ### COMMAND-LINE MANGLING ###
78 scpoptions="$sshoptions"
79 [ "$bandwidthlimit" == 0 ] || scpoptions="$scpoptions -l $bandwidthlimit"
81 execstr="$options --no-print-statistics --scp-command 'scp $scpoptions' --ssh-command 'ssh $sshoptions' "
83 # deal with symmetric or asymmetric (public/private key pair) encryption
84 if [ -n "$encryptkey" ]; then
85 execstr="${execstr}--encrypt-key $encryptkey "
86 debug "Data will be encrypted with the GnuPG key $encryptkey."
88 [ -n "$password" ] || fatal "The password option must be set when using symmetric encryption."
89 debug "Data will be encrypted using symmetric encryption."
92 # deal with data signing
93 if [ "$sign" == yes ]; then
94 # duplicity is not able to sign data when using symmetric encryption
95 [ -n "$encryptkey" ] || fatal "The encryptkey option must be set when signing."
96 # if needed, initialize signkey to a value that is not empty (checked above)
97 [ -n "$signkey" ] || signkey="$encryptkey"
98 # check password validity
99 [ -n "$password" ] || fatal "The password option must be set when signing."
100 execstr="${execstr}--sign-key $signkey "
101 debug "Data will be signed will the GnuPG key $signkey."
103 debug "Data won't be signed."
106 if [ "$keep" != "yes" ]; then
107 if [ "`echo $keep | tr -d 0-9`" == "" ]; then
110 execstr="${execstr}--remove-older-than $keep "
113 if [ "$incremental" == "no" ]; then
114 execstr="${execstr}--full "
117 execstr_serverpart="scp://$destuser@$desthost/$destdir"
118 execstr_clientpart="/"
123 for i in $exclude; do
124 str="${i//__star__/*}"
125 execstr="${execstr}--exclude '$str' "
129 for i in $include; do
130 str="${i//__star__/*}"
131 execstr="${execstr}--include '$str' "
135 if [ $usevserver ]; then
136 for vserver in $vsnames; do
137 for vi in $vsinclude; do
138 str="${vi//__star__/*}"
139 execstr="${execstr}--include '$VROOTDIR/$vserver$str' "
146 # exclude everything else, start with root
147 #execstr="${execstr}--exclude '**' / "
149 # include client-part and server-part
150 #execstr="$execstr $execstr_serverpart"
152 execstr=${execstr//\\*/\\\\\\*}
154 debug "duplicity $execstr --exclude '**' / $execstr_serverpart"
156 export PASSPHRASE=$password
157 output=`nice -n $nicelevel \
159 "duplicity $execstr --exclude '**' / $execstr_serverpart 2>&1"`
161 if [ $code -eq 0 ]; then
163 info "Duplicity finished successfully."
166 fatal "Duplicity failed."