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"
34 [ "$password" != "" ] || fatal "No password 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 # if encryptkey is set, add --encrypt-key to the command-line
84 [ -z "$encryptkey" ] || execstr="${execstr}--encrypt-key $encryptkey "
85 # if signkey is not set, set it to encryptkey
86 [ -n "$signkey" ] || signkey="$encryptkey"
87 # if needed, add --sign-key to command-line
88 if [ "$sign" == "yes" ]; then
89 if [ -n "$signkey" ]; then
90 execstr="${execstr}--sign-key $signkey "
92 fatal "Either encryptkey or signkey option must be set when signing."
96 if [ "$keep" != "yes" ]; then
97 if [ "`echo $keep | tr -d 0-9`" == "" ]; then
100 execstr="${execstr}--remove-older-than $keep "
103 if [ "$incremental" == "no" ]; then
104 execstr="${execstr}--full "
107 execstr_serverpart="scp://$destuser@$desthost/$destdir"
108 execstr_clientpart="/"
113 for i in $exclude; do
114 str="${i//__star__/*}"
115 execstr="${execstr}--exclude '$str' "
119 for i in $include; do
120 str="${i//__star__/*}"
121 execstr="${execstr}--include '$str' "
125 if [ $usevserver ]; then
126 for vserver in $vsnames; do
127 for vi in $vsinclude; do
128 str="${vi//__star__/*}"
129 execstr="${execstr}--include '$VROOTDIR/$vserver$str' "
136 # exclude everything else, start with root
137 #execstr="${execstr}--exclude '**' / "
139 # include client-part and server-part
140 #execstr="$execstr $execstr_serverpart"
142 execstr=${execstr//\\*/\\\\\\*}
144 debug "duplicity $execstr --exclude '**' / $execstr_serverpart"
146 export PASSPHRASE=$password
147 output=`nice -n $nicelevel \
149 "duplicity $execstr --exclude '**' / $execstr_serverpart 2>&1"`
151 if [ $code -eq 0 ]; then
153 info "Duplicity finished successfully."
156 fatal "Duplicity failed."