removed extra 0 from cron
[matthijs/upstream/backupninja-vserver.git] / handlers / dup
1 #
2 # duplicity script for backupninja
3 # requires duplicity
4 #
5
6 getconf options
7 getconf testconnect yes
8 getconf nicelevel 0
9
10 setsection gpg
11 getconf password
12 getconf sign no
13 getconf encryptkey
14
15 setsection source
16 getconf include
17 getconf exclude
18
19 setsection dest
20 getconf keep 60
21 getconf sshoptions
22 getconf bandwidthlimit 0
23 getconf desthost
24 getconf destdir
25 getconf destuser
26 destdir=${destdir%/}
27
28 [ "$destdir" != "" ] || fatal "Destination directory not set"
29 [ "$include" != "" ] || fatal "No source includes specified"
30 [ "$password" != "" ] || fatal "No password specified"
31
32 # see if we can login
33 if [ "$testconnect" == "yes" ]; then
34     debug "ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'"
35     if [ ! $test ]; then
36         result=`ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1' 2>&1`
37         if [ "$result" != "1" ]; then
38             fatal "Can't connect to $desthost as $destuser."
39         else
40             debug "Connected to $desthost as $destuser successfully"
41         fi
42     fi
43 fi
44
45 ### COMMAND-LINE MANGLING ###
46
47 scpoptions="$sshoptions"
48 [ "$bandwidthlimit" == 0 ] || scpoptions="$scpoptions -l $bandwidthlimit"
49
50 execstr="$options --no-print-statistics --scp-command 'scp $scpoptions' --ssh-command 'ssh $sshoptions' "
51
52 if [ "$encryptkey" == "" ]; then
53     [ "$sign" != "yes" ] || fatal "encryptkey option must be set when signing."
54 else
55     execstr="${execstr}--encrypt-key $encryptkey "
56     [ "$sign" != "yes" ] || execstr="${execstr}--sign-key $encryptkey "
57 fi
58
59 if [ "$keep" != "yes" ]; then
60     if [ "`echo $keep | tr -d 0-9`" == "" ]; then
61         keep="${keep}D"
62     fi
63     execstr="${execstr}--remove-older-than $keep "
64 fi
65
66 execstr_serverpart="scp://$destuser@$desthost/$destdir"
67 execstr_clientpart="/"
68
69 ### SOURCE ###
70
71 # excludes
72 for i in $exclude; do
73         str="${i//__star__/*}"
74         execstr="${execstr}--exclude $str "
75 done
76         
77 # includes 
78 for i in $include; do
79         str="${i//__star__/*}"
80         execstr="${execstr}--include $str "
81 done
82
83 ### EXECUTE ###
84
85 # exclude everything else, start with root
86 #execstr="${execstr}--exclude '**' / "
87                 
88 # include client-part and server-part
89 #execstr="$execstr $execstr_serverpart"
90
91 execstr=${execstr//\\*/\\\\\\*}
92
93 debug "duplicity $execstr --exclude '**' / $execstr_serverpart"
94 if [ ! $test ]; then
95         output=`nice -n $nicelevel \
96                   su -c \
97                     "export PASSPHRASE=$password \
98                      && duplicity $execstr --exclude '**' / $execstr_serverpart 2>&1"`
99         code=$?
100         if [ "$code" == "0" ]; then
101                 debug $output
102                 info "Duplicity finished successfully."
103         else
104                 warning $output
105                 warning "Duplicity failed."
106         fi
107 fi      
108
109 return 0