~ubuntu-branches/ubuntu/oneiric/backupninja/oneiric

« back to all changes in this revision

Viewing changes to handlers/dup.in

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-01-16 15:44:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080116154413-re504b7dbl5y5dtw
Tags: 0.9.5-3
* Add improved duplicity support (>= 0.4.4) command line syntax:
  . run remove-older-than when $keep is not set to yes (Closes: #458816),
  . and run "duplicity cleanup" before any other duplicity command
  . full/incremental backup switch also migrated to the new syntax.
* Remove versioned Suggest on duplicity
* Add patch from Matthew Palmer to rdiff handler to incorporate sshoptions
  into options via remote-schema not already specified (Closes: #424639)
* Fixed Vcs-Svn field (Closes: #455814)

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
getconf destuser
32
32
destdir=${destdir%/}
33
33
 
34
 
[ "$destdir" != "" ] || fatal "Destination directory not set"
35
 
[ "$include" != "" ] || fatal "No source includes specified"
36
 
 
37
 
### vservers stuff ###
38
 
 
 
34
### SANITY CHECKS ##############################################################
 
35
 
 
36
[ -n "$destdir" ]  || fatal "Destination directory not set"
 
37
[ -n "$include" ]  || fatal "No source includes specified"
 
38
[ -n "$password" ] || fatal "The password option must be set."
 
39
 
 
40
### VServers
39
41
# If vservers are configured, check that the ones listed in $vsnames do exist.
40
42
local usevserver=no
41
43
if [ $vservers_are_available = yes ]; then
54
56
   [ -z "$vsinclude" ] || warning 'vservers support disabled in backupninja.conf, vsincludes configuration lines will be ignored'
55
57
fi
56
58
 
57
 
 
58
 
### see if we can login ###
59
 
 
 
59
### See if we can login on $desthost
60
60
if [ "$testconnect" == "yes" ]; then
61
 
    debug "ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'"
62
 
    if [ ! $test ]; then
63
 
        result=`ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'`
64
 
        if [ "$result" != "1" ]; then
65
 
            fatal "Can't connect to $desthost as $destuser."
66
 
        else
67
 
            debug "Connected to $desthost as $destuser successfully"
68
 
        fi
69
 
    fi
 
61
   debug "ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'"
 
62
   if [ ! $test ]; then
 
63
      result=`ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'`
 
64
      if [ "$result" != "1" ]; then
 
65
         fatal "Can't connect to $desthost as $destuser."
 
66
      else
 
67
         debug "Connected to $desthost as $destuser successfully"
 
68
      fi
 
69
   fi
70
70
fi
71
71
 
72
 
### COMMAND-LINE MANGLING ###
73
 
 
 
72
### COMMAND-LINE MANGLING ######################################################
 
73
 
 
74
### initialize $execstr*
 
75
execstr_command=
 
76
execstr_options="$options --no-print-statistics"
 
77
execstr_source=
 
78
execstr_serverpart="scp://$destuser@$desthost/$destdir"
 
79
 
 
80
### duplicity version
74
81
duplicity_version="`duplicity --version | @AWK@ '{print $2}'`"
75
82
duplicity_major="`echo $duplicity_version | @AWK@ -F '.' '{print $1}'`"
76
83
duplicity_minor="`echo $duplicity_version | @AWK@ -F '.' '{print $2}'`"
77
84
duplicity_sub="`echo $duplicity_version | @AWK@ -F '.' '{print $3}'`"
78
85
 
79
 
# 1. duplicity >= 0.4.2 needs --sftp-command (NB: sftp does not support the -l option)
80
 
# 2. duplicity >= 0.4.3 replaces --ssh-command with --ssh-options, which:
81
 
#      - is passed to scp and sftp commands by duplicity
82
 
#      - has a special syntax we can not feed the command line with
83
 
#    so we don't use it: since this version does not use the ssh command anymore,
84
 
#    we keep compatibility with our previous config files by passing $sshoptions to
85
 
#    --scp-command and --sftp-command ourselves
 
86
### ssh/scp/sftp options
 
87
# 1. duplicity >= 0.4.2 needs --sftp-command
 
88
#    (NB: sftp does not support the -l option)
 
89
# 2. duplicity 0.4.3 to 0.4.9 replace --ssh-command with --ssh-options, which is
 
90
#    passed to scp and sftp commands by duplicity. We don't use it: since this
 
91
#    version does not use the ssh command anymore, we keep compatibility with
 
92
#    our previous config files by passing $sshoptions to --scp-command and
 
93
#    --sftp-command ourselves
86
94
 
87
95
scpoptions="$sshoptions"
88
96
[ "$bandwidthlimit" == 0 ] || scpoptions="$scpoptions -l $bandwidthlimit"
89
97
 
90
 
execstr="$options --no-print-statistics "
91
 
 
92
98
# < 0.4.2 : only uses ssh and scp
93
99
if [ "$duplicity_major" -le 0 -a "$duplicity_minor" -le 4 -a "$duplicity_sub" -lt 2 ]; then
94
 
   execstr="$execstr --scp-command 'scp $scpoptions' --ssh-command 'ssh $sshoptions' "
 
100
   execstr_options="${execstr_options} --scp-command 'scp $scpoptions' --ssh-command 'ssh $sshoptions'"
95
101
# >= 0.4.2 : also uses sftp, --sftp-command option is now supported
96
102
else
97
103
   sftpoptions="$sshoptions"
98
104
   # == 0.4.2 : uses ssh, scp and sftp
99
105
   if [ "$duplicity_major" -eq 0 -a "$duplicity_minor" -eq 4 -a "$duplicity_sub" -eq 2 ]; then
100
 
      execstr="$execstr --scp-command 'scp $scpoptions' --sftp-command 'sftp $sftpoptions' --ssh-command 'ssh $sshoptions' "
 
106
      execstr_options="${execstr_options} --scp-command 'scp $scpoptions' --sftp-command 'sftp $sftpoptions' --ssh-command 'ssh $sshoptions'"
101
107
   # >= 0.4.3 : uses only scp and sftp, --ssh-command option is not supported anymore
102
108
   else
103
 
      execstr="$execstr --scp-command 'scp $scpoptions' --sftp-command 'sftp $sftpoptions' "
 
109
      execstr_options="${execstr_options} --scp-command 'scp $scpoptions' --sftp-command 'sftp $sftpoptions'"
104
110
   fi
105
111
fi
106
112
 
107
 
# deal with symmetric or asymmetric (public/private key pair) encryption
 
113
### Symmetric or asymmetric (public/private key pair) encryption
108
114
if [ -n "$encryptkey" ]; then
109
 
    execstr="${execstr}--encrypt-key $encryptkey "
110
 
    debug "Data will be encrypted with the GnuPG key $encryptkey."
 
115
   execstr_options="${execstr_options} --encrypt-key $encryptkey"
 
116
   debug "Data will be encrypted with the GnuPG key $encryptkey."
111
117
else
112
 
    debug "Data will be encrypted using symmetric encryption."
 
118
   debug "Data will be encrypted using symmetric encryption."
113
119
fi
114
120
 
115
 
# deal with data signing
 
121
### Data signing (or not)
116
122
if [ "$sign" == yes ]; then
117
 
    # duplicity is not able to sign data when using symmetric encryption
118
 
    [ -n "$encryptkey" ] || fatal "The encryptkey option must be set when signing."
119
 
    # if needed, initialize signkey to a value that is not empty (checked above)
120
 
    [ -n "$signkey" ] || signkey="$encryptkey"
121
 
    execstr="${execstr}--sign-key $signkey "
122
 
    debug "Data will be signed will the GnuPG key $signkey."
 
123
   # duplicity is not able to sign data when using symmetric encryption
 
124
   [ -n "$encryptkey" ] || fatal "The encryptkey option must be set when signing."
 
125
   # if needed, initialize signkey to a value that is not empty (checked above)
 
126
   [ -n "$signkey" ] || signkey="$encryptkey"
 
127
   execstr_options="${execstr_options} --sign-key $signkey"
 
128
   debug "Data will be signed will the GnuPG key $signkey."
123
129
else
124
 
    debug "Data won't be signed."
125
 
fi
126
 
 
127
 
# deal with GnuPG passphrase
128
 
[ -n "$password" ] || fatal "The password option must be set."
129
 
 
130
 
if [ "$keep" != "yes" ]; then
131
 
    if [ "`echo $keep | tr -d 0-9`" == "" ]; then
132
 
        keep="${keep}D"
133
 
    fi
134
 
    execstr="${execstr}--remove-older-than $keep "
135
 
fi
136
 
 
 
130
   debug "Data won't be signed."
 
131
fi
 
132
 
 
133
### Incremental or full backup mode
 
134
# If incremental==yes, use the default duplicity behaviour: perform an
 
135
# incremental backup if old signatures can be found, else switch to
 
136
# full backup.
 
137
# If incremental==no, force a full backup anyway.
137
138
if [ "$incremental" == "no" ]; then
138
 
    execstr="${execstr}--full "
139
 
fi
140
 
 
141
 
execstr_serverpart="scp://$destuser@$desthost/$destdir"
142
 
execstr_clientpart="/"
143
 
 
144
 
### SOURCE ###
 
139
   # before 0.4.4, full was an option and not a command
 
140
   if [ "$duplicity_major" -le 0 -a "$duplicity_minor" -le 4 -a "$duplicity_sub" -lt 4 ]; then   
 
141
      execstr_options="${execstr_options} --full"
 
142
   else
 
143
      execstr_command="full"
 
144
   fi
 
145
fi
 
146
 
 
147
### Temporary directory
 
148
precmd=
 
149
if [ -n "$tmpdir" ]; then
 
150
   if [ ! -d "$tmpdir" ]; then
 
151
      info "Temporary directory ($tmpdir) does not exist, creating it."
 
152
      mkdir -p "$tmpdir"
 
153
      [ $? -eq 0 ] || fatal "Could not create temporary directory ($tmpdir)."
 
154
   fi
 
155
   info "Using $tmpdir as TMPDIR"
 
156
   precmd="${precmd}TMPDIR=$tmpdir "
 
157
fi
 
158
 
 
159
### Cleanup old backup sets (or not)
 
160
if [ "$keep" != "yes" ]; then
 
161
   if [ "`echo $keep | tr -d 0-9`" == "" ]; then
 
162
      keep="${keep}D"
 
163
   fi
 
164
   # before 0.4.4, remove-older-than was an option and not a command
 
165
   if [ "$duplicity_major" -le 0 -a "$duplicity_minor" -le 4 -a "$duplicity_sub" -lt 4 ]; then
 
166
      execstr_options="${execstr_options} --remove-older-than $keep"
 
167
   fi
 
168
fi
 
169
 
 
170
### Source
145
171
 
146
172
set -o noglob
147
173
 
148
174
# excludes
149
175
for i in $exclude; do
150
176
   str="${i//__star__/*}"
151
 
   execstr="${execstr}--exclude '$str' "
 
177
   execstr_source="${execstr_source} --exclude '$str'"
152
178
done
153
 
        
154
 
# includes 
 
179
 
 
180
# includes
155
181
for i in $include; do
156
182
   [ "$i" != "/" ] || fatal "Sorry, you cannot use 'include = /'"
157
183
   str="${i//__star__/*}"
158
 
   execstr="${execstr}--include '$str' "
 
184
   execstr_source="${execstr_source} --include '$str'"
159
185
done
160
186
 
161
187
# vsincludes
164
190
      for vi in $vsinclude; do
165
191
         str="${vi//__star__/*}"
166
192
         str="$VROOTDIR/$vserver$str"
167
 
         execstr="${execstr}--include '$str' "
 
193
         execstr_source="${execstr_source} --include '$str'"
168
194
      done
169
195
   done
170
196
fi
171
197
 
172
198
set +o noglob
173
199
 
174
 
### deal with tmpdir ###
175
 
precmd=
176
 
if [ -n "$tmpdir" ]; then
177
 
   if [ ! -d "$tmpdir" ]; then
178
 
      info "Temporary directory ($tmpdir) does not exist, creating it."
179
 
      mkdir -p "$tmpdir"
180
 
      [ $? -eq 0 ] || fatal "Could not create temporary directory ($tmpdir)."
181
 
   fi
182
 
   info "Using $tmpdir as TMPDIR"
183
 
   precmd="${precmd}TMPDIR=$tmpdir "
184
 
fi
185
 
 
186
 
### EXECUTE ###
187
 
 
188
 
execstr=${execstr//\\*/\\\\\\*}
189
 
 
190
 
debug "$precmd duplicity $execstr --exclude '**' / $execstr_serverpart"
 
200
### EXECUTE ####################################################################
 
201
 
 
202
execstr_source=${execstr_source//\\*/\\\\\\*}
 
203
 
 
204
### Cleanup commands (duplicity >= 0.4.4)
 
205
 
 
206
# cleanup
 
207
if [ "$duplicity_major" -ge 0 -a "$duplicity_minor" -ge 4 -a "$duplicity_sub" -ge 4 ]; then
 
208
   debug "$precmd duplicity cleanup $execstr_options $execstr_serverpart"
 
209
   if [ ! $test ]; then
 
210
      export PASSPHRASE=$password
 
211
      output=`nice -n $nicelevel \
 
212
         su -c \
 
213
         "$precmd duplicity cleanup $execstr_options $execstr_serverpart 2>&1"`
 
214
      exit_code=$?
 
215
      if [ $exit_code -eq 0 ]; then
 
216
         debug $output
 
217
         info "Duplicity cleanup finished successfully."
 
218
      else
 
219
         debug $output
 
220
         warning "Duplicity cleanup failed."
 
221
      fi
 
222
   fi
 
223
fi
 
224
 
 
225
# remove-older-than
 
226
if [ "$keep" != "yes" ]; then
 
227
   if [ "$duplicity_major" -ge 0 -a "$duplicity_minor" -ge 4 -a "$duplicity_sub" -ge 4 ]; then
 
228
      debug "$precmd duplicity remove-older-than $keep $execstr_options $execstr_serverpart"
 
229
      if [ ! $test ]; then
 
230
         export PASSPHRASE=$password
 
231
         output=`nice -n $nicelevel \
 
232
                   su -c \
 
233
                      "$precmd duplicity remove-older-than $keep $execstr_options $execstr_serverpart 2>&1"`
 
234
         exit_code=$?
 
235
         if [ $exit_code -eq 0 ]; then
 
236
            debug $output
 
237
            info "Duplicity remove-older-than finished successfully."
 
238
         else
 
239
            debug $output
 
240
            warning "Duplicity remove-older-than failed."
 
241
         fi
 
242
      fi
 
243
   fi
 
244
fi
 
245
 
 
246
### Backup command
 
247
debug "$precmd duplicity $execstr_command $execstr_options $execstr_source --exclude '**' / $execstr_serverpart"
191
248
if [ ! $test ]; then
192
 
        export PASSPHRASE=$password
193
 
        output=`nice -n $nicelevel \
194
 
                  su -c \
195
 
                    "$precmd duplicity $execstr --exclude '**' / $execstr_serverpart 2>&1"`
196
 
        code=$?
197
 
        if [ $code -eq 0 ]; then
198
 
                debug $output
199
 
                info "Duplicity finished successfully."
200
 
        else
201
 
                debug $output
202
 
                fatal "Duplicity failed."
203
 
        fi
204
 
fi      
 
249
   export PASSPHRASE=$password
 
250
   output=`nice -n $nicelevel \
 
251
             su -c \
 
252
                "$precmd duplicity $execstr_command $execstr_options $execstr_source --exclude '**' / $execstr_serverpart 2>&1"`
 
253
   exit_code=$?
 
254
   if [ $exit_code -eq 0 ]; then
 
255
      debug $output
 
256
      info "Duplicity finished successfully."
 
257
   else
 
258
      debug $output
 
259
      fatal "Duplicity failed."
 
260
   fi
 
261
fi
205
262
 
206
263
return 0