2 # duplicity script for backupninja
7 getconf testconnect yes
24 getconf bandwidthlimit 0
30 [ "$destdir" != "" ] || fatal "Destination directory not set"
31 [ "$include" != "" ] || fatal "No source includes specified"
32 [ "$password" != "" ] || fatal "No password specified"
34 ### vservers stuff ###
36 # See if vservers are configured.
37 # If so, check that the ones listed in $vsnames do exist.
38 if [ "$vservers" == "yes" ]; then
39 [ -d "$VROOTDIR" ] || fatal "vservers enabled, but $VROOTDIR does not exist!"
40 if [ "$vsnames" == "all" ]; then
42 for vserver in `ls $VROOTDIR | grep -E -v "lost+found|ARCHIVES"`; do
43 vsnames="$vserver $vsnames"
46 for vserver in "$vsnames"; do
47 [ -d "$VROOTDIR/$vserver" ] || fatal "vserver '$vserver' does not exist."
50 if [ -n "$vsnames" ]; then
51 if [ -n "$vsinclude" ]; then
52 info "Using vservers '$vsnames'"
56 [ -z "$vsinclude" ] || warning 'vsnames is empty, vsinclude configuration lines will be ignored'
60 ### see if we can login ###
62 if [ "$testconnect" == "yes" ]; then
63 debug "ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'"
65 result=`ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1' 2>&1`
66 if [ "$result" != "1" ]; then
67 fatal "Can't connect to $desthost as $destuser."
69 debug "Connected to $desthost as $destuser successfully"
74 ### COMMAND-LINE MANGLING ###
76 scpoptions="$sshoptions"
77 [ "$bandwidthlimit" == 0 ] || scpoptions="$scpoptions -l $bandwidthlimit"
79 execstr="$options --no-print-statistics --scp-command 'scp $scpoptions' --ssh-command 'ssh $sshoptions' "
81 if [ "$encryptkey" == "" ]; then
82 [ "$sign" != "yes" ] || fatal "encryptkey option must be set when signing."
84 execstr="${execstr}--encrypt-key $encryptkey "
85 [ "$sign" != "yes" ] || execstr="${execstr}--sign-key $encryptkey "
88 if [ "$keep" != "yes" ]; then
89 if [ "`echo $keep | tr -d 0-9`" == "" ]; then
92 execstr="${execstr}--remove-older-than $keep "
95 execstr_serverpart="scp://$destuser@$desthost/$destdir"
96 execstr_clientpart="/"
101 for i in $exclude; do
102 str="${i//__star__/*}"
103 execstr="${execstr}--exclude $str "
107 for i in $include; do
108 str="${i//__star__/*}"
109 execstr="${execstr}--include $str "
113 if [ $usevserver ]; then
114 for vserver in $vsnames; do
115 for vi in $vsinclude; do
116 str="${vi//__star__/*}"
117 execstr="${execstr}--include '$VROOTDIR/$vserver$str' "
124 # exclude everything else, start with root
125 #execstr="${execstr}--exclude '**' / "
127 # include client-part and server-part
128 #execstr="$execstr $execstr_serverpart"
130 execstr=${execstr//\\*/\\\\\\*}
132 debug "duplicity $execstr --exclude '**' / $execstr_serverpart"
134 output=`nice -n $nicelevel \
136 "export PASSPHRASE=$password \
137 && duplicity $execstr --exclude '**' / $execstr_serverpart 2>&1"`
139 if [ "$code" == "0" ]; then
141 info "Duplicity finished successfully."
144 warning "Duplicity failed."