2 # duplicity script for backupninja
7 getconf testconnect yes
22 getconf incremental yes
25 getconf bandwidthlimit 0
31 [ "$destdir" != "" ] || fatal "Destination directory not set"
32 [ "$include" != "" ] || fatal "No source includes specified"
33 [ "$password" != "" ] || fatal "No password 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 if [ "$encryptkey" == "" ]; then
83 [ "$sign" != "yes" ] || fatal "encryptkey option must be set when signing."
85 execstr="${execstr}--encrypt-key $encryptkey "
86 [ "$sign" != "yes" ] || execstr="${execstr}--sign-key $encryptkey "
89 if [ "$keep" != "yes" ]; then
90 if [ "`echo $keep | tr -d 0-9`" == "" ]; then
93 execstr="${execstr}--remove-older-than $keep "
96 if [ "$incremental" == "no" ]; then
97 execstr="${execstr}--full "
100 execstr_serverpart="scp://$destuser@$desthost/$destdir"
101 execstr_clientpart="/"
106 for i in $exclude; do
107 str="${i//__star__/*}"
108 execstr="${execstr}--exclude '$str' "
112 for i in $include; do
113 str="${i//__star__/*}"
114 execstr="${execstr}--include '$str' "
118 if [ $usevserver ]; then
119 for vserver in $vsnames; do
120 for vi in $vsinclude; do
121 str="${vi//__star__/*}"
122 execstr="${execstr}--include '$VROOTDIR/$vserver$str' "
129 # exclude everything else, start with root
130 #execstr="${execstr}--exclude '**' / "
132 # include client-part and server-part
133 #execstr="$execstr $execstr_serverpart"
135 execstr=${execstr//\\*/\\\\\\*}
137 debug "duplicity $execstr --exclude '**' / $execstr_serverpart"
139 export PASSPHRASE=$password
140 output=`nice -n $nicelevel \
142 "duplicity $execstr --exclude '**' / $execstr_serverpart 2>&1"`
144 if [ $code -eq 0 ]; then
146 info "Duplicity finished successfully."
149 fatal "Duplicity failed."