2 # duplicity script for backupninja
7 getconf testconnect yes
23 getconf incremental yes
26 getconf bandwidthlimit 0
32 [ "$destdir" != "" ] || fatal "Destination directory not set"
33 [ "$include" != "" ] || fatal "No source includes specified"
35 ### vservers stuff ###
37 # See if vservers are configured.
38 # If so, check that the ones listed in $vsnames do exist.
39 if [ "$vservers" == "yes" ]; then
40 [ -d "$VROOTDIR" ] || fatal "vservers enabled, but $VROOTDIR does not exist!"
41 if [ "$vsnames" == "all" ]; then
43 for vserver in `ls $VROOTDIR | grep -E -v "lost+found|ARCHIVES"`; do
44 vsnames="$vserver $vsnames"
47 for vserver in "$vsnames"; do
48 [ -d "$VROOTDIR/$vserver" ] || fatal "vserver '$vserver' does not exist."
51 if [ -n "$vsnames" ]; then
52 if [ -n "$vsinclude" ]; then
53 info "Using vservers '$vsnames'"
57 [ -z "$vsinclude" ] || warning 'vsnames is empty, vsinclude configuration lines will be ignored'
61 ### see if we can login ###
63 if [ "$testconnect" == "yes" ]; then
64 debug "ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'"
66 result=`ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'`
67 if [ "$result" != "1" ]; then
68 fatal "Can't connect to $desthost as $destuser."
70 debug "Connected to $desthost as $destuser successfully"
75 ### COMMAND-LINE MANGLING ###
77 scpoptions="$sshoptions"
78 [ "$bandwidthlimit" == 0 ] || scpoptions="$scpoptions -l $bandwidthlimit"
80 execstr="$options --no-print-statistics --scp-command 'scp $scpoptions' --ssh-command 'ssh $sshoptions' "
82 # deal with symmetric or asymmetric (public/private key pair) encryption
83 if [ -n "$encryptkey" ]; then
84 execstr="${execstr}--encrypt-key $encryptkey "
85 debug "Data will be encrypted with the GnuPG key $encryptkey."
87 [ -n "$password" ] || fatal "The password option must be set when using symmetric encryption."
88 debug "Data will be encrypted using symmetric encryption."
91 # deal with data signing
92 if [ "$sign" == yes ]; then
93 # duplicity is not able to sign data when using symmetric encryption
94 [ -n "$encryptkey" ] || fatal "The encryptkey option must be set when signing."
95 # if needed, initialize signkey to a value that is not empty (checked above)
96 [ -n "$signkey" ] || signkey="$encryptkey"
97 # check password validity
98 [ -n "$password" ] || fatal "The password option must be set when signing."
99 execstr="${execstr}--sign-key $signkey "
100 debug "Data will be signed will the GnuPG key $signkey."
102 debug "Data won't be signed."
105 if [ "$keep" != "yes" ]; then
106 if [ "`echo $keep | tr -d 0-9`" == "" ]; then
109 execstr="${execstr}--remove-older-than $keep "
112 if [ "$incremental" == "no" ]; then
113 execstr="${execstr}--full "
116 execstr_serverpart="scp://$destuser@$desthost/$destdir"
117 execstr_clientpart="/"
122 for i in $exclude; do
123 str="${i//__star__/*}"
124 execstr="${execstr}--exclude '$str' "
128 for i in $include; do
129 str="${i//__star__/*}"
130 execstr="${execstr}--include '$str' "
134 if [ $usevserver ]; then
135 for vserver in $vsnames; do
136 for vi in $vsinclude; do
137 str="${vi//__star__/*}"
138 execstr="${execstr}--include '$VROOTDIR/$vserver$str' "
145 # exclude everything else, start with root
146 #execstr="${execstr}--exclude '**' / "
148 # include client-part and server-part
149 #execstr="$execstr $execstr_serverpart"
151 execstr=${execstr//\\*/\\\\\\*}
153 debug "duplicity $execstr --exclude '**' / $execstr_serverpart"
155 export PASSPHRASE=$password
156 output=`nice -n $nicelevel \
158 "duplicity $execstr --exclude '**' / $execstr_serverpart 2>&1"`
160 if [ $code -eq 0 ]; then
162 info "Duplicity finished successfully."
165 fatal "Duplicity failed."