Forgot to note in the changelog
[matthijs/upstream/backupninja-vserver.git] / handlers / dup
1 #
2 # duplicity script for backupninja
3 # requires duplicity
4 #
5
6 getconf password
7 getconf options
8 getconf keep 60
9 getconf include
10 getconf exclude
11 getconf desthost
12 getconf destdir
13 getconf destuser
14 destdir=${destdir%/}
15
16 [ "$destdir" != "" ] || fatal "Destination directory not set"
17 [ "$include" != "" ] || fatal "No source includes specified"
18 [ "$password" != "" ] || fatal "No password specified"
19
20 # see if we can login
21 debug "ssh -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'"
22 if [ ! $test ]; then
23         result=`ssh -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1' 2>&1`
24         if [ "$result" != "1" ]; then
25                 fatal "Can't connect to $desthost as $destuser."
26         fi
27 fi
28
29 if [ "`echo $keep | tr -d 0-9`" == "" ]; then
30         keep="${keep}D"
31 fi
32
33 execstr_serverpart="scp://$destuser@$desthost/$destdir"
34 execstr_clientpart="/"
35 execstr="$options --no-print-statistics --remove-older-than $keep "
36
37 # excludes
38 for i in $exclude; do
39         str="${i//__star__/*}"
40         execstr="${execstr}--exclude $str "
41 done
42         
43 # includes 
44 for i in $include; do
45         str="${i//__star__/*}"
46         execstr="${execstr}--include $str "
47 done
48
49 # exclude everything else, start with root
50 #execstr="${execstr}--exclude '**' / "
51                 
52 # include client-part and server-part
53 #execstr="$execstr $execstr_serverpart"
54
55 execstr=${execstr//\\*/\\\\\\*}
56
57 debug "duplicity $execstr --exclude '**' / $execstr_serverpart"
58 if [ ! $test ]; then
59         PASSPHRASE=$password
60         export PASSPHRASE
61         output=`duplicity $execstr --exclude '**' / $execstr_serverpart 2>&1`
62         code=$?
63         if [ "$code" == "0" ]; then
64                 debug $output
65                 info "Duplicity finished successfully."
66         else
67                 warning $output
68                 warning "Duplicity failed."
69         fi
70 fi      
71
72 return 0