54
56
[ -z "$vsinclude" ] || warning 'vservers support disabled in backupninja.conf, vsincludes configuration lines will be ignored'
58
### see if we can login ###
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'"
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."
67
debug "Connected to $desthost as $destuser successfully"
61
debug "ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'"
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."
67
debug "Connected to $desthost as $destuser successfully"
72
### COMMAND-LINE MANGLING ###
72
### COMMAND-LINE MANGLING ######################################################
74
### initialize $execstr*
76
execstr_options="$options --no-print-statistics"
78
execstr_serverpart="scp://$destuser@$desthost/$destdir"
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}'`"
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
87
95
scpoptions="$sshoptions"
88
96
[ "$bandwidthlimit" == 0 ] || scpoptions="$scpoptions -l $bandwidthlimit"
90
execstr="$options --no-print-statistics "
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
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
103
execstr="$execstr --scp-command 'scp $scpoptions' --sftp-command 'sftp $sftpoptions' "
109
execstr_options="${execstr_options} --scp-command 'scp $scpoptions' --sftp-command 'sftp $sftpoptions'"
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."
112
debug "Data will be encrypted using symmetric encryption."
118
debug "Data will be encrypted using symmetric encryption."
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."
124
debug "Data won't be signed."
127
# deal with GnuPG passphrase
128
[ -n "$password" ] || fatal "The password option must be set."
130
if [ "$keep" != "yes" ]; then
131
if [ "`echo $keep | tr -d 0-9`" == "" ]; then
134
execstr="${execstr}--remove-older-than $keep "
130
debug "Data won't be signed."
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
137
# If incremental==no, force a full backup anyway.
137
138
if [ "$incremental" == "no" ]; then
138
execstr="${execstr}--full "
141
execstr_serverpart="scp://$destuser@$desthost/$destdir"
142
execstr_clientpart="/"
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"
143
execstr_command="full"
147
### Temporary directory
149
if [ -n "$tmpdir" ]; then
150
if [ ! -d "$tmpdir" ]; then
151
info "Temporary directory ($tmpdir) does not exist, creating it."
153
[ $? -eq 0 ] || fatal "Could not create temporary directory ($tmpdir)."
155
info "Using $tmpdir as TMPDIR"
156
precmd="${precmd}TMPDIR=$tmpdir "
159
### Cleanup old backup sets (or not)
160
if [ "$keep" != "yes" ]; then
161
if [ "`echo $keep | tr -d 0-9`" == "" ]; then
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"
149
175
for i in $exclude; do
150
176
str="${i//__star__/*}"
151
execstr="${execstr}--exclude '$str' "
177
execstr_source="${execstr_source} --exclude '$str'"
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'"
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'"
174
### deal with tmpdir ###
176
if [ -n "$tmpdir" ]; then
177
if [ ! -d "$tmpdir" ]; then
178
info "Temporary directory ($tmpdir) does not exist, creating it."
180
[ $? -eq 0 ] || fatal "Could not create temporary directory ($tmpdir)."
182
info "Using $tmpdir as TMPDIR"
183
precmd="${precmd}TMPDIR=$tmpdir "
188
execstr=${execstr//\\*/\\\\\\*}
190
debug "$precmd duplicity $execstr --exclude '**' / $execstr_serverpart"
200
### EXECUTE ####################################################################
202
execstr_source=${execstr_source//\\*/\\\\\\*}
204
### Cleanup commands (duplicity >= 0.4.4)
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"
210
export PASSPHRASE=$password
211
output=`nice -n $nicelevel \
213
"$precmd duplicity cleanup $execstr_options $execstr_serverpart 2>&1"`
215
if [ $exit_code -eq 0 ]; then
217
info "Duplicity cleanup finished successfully."
220
warning "Duplicity cleanup failed."
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"
230
export PASSPHRASE=$password
231
output=`nice -n $nicelevel \
233
"$precmd duplicity remove-older-than $keep $execstr_options $execstr_serverpart 2>&1"`
235
if [ $exit_code -eq 0 ]; then
237
info "Duplicity remove-older-than finished successfully."
240
warning "Duplicity remove-older-than failed."
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 \
195
"$precmd duplicity $execstr --exclude '**' / $execstr_serverpart 2>&1"`
197
if [ $code -eq 0 ]; then
199
info "Duplicity finished successfully."
202
fatal "Duplicity failed."
249
export PASSPHRASE=$password
250
output=`nice -n $nicelevel \
252
"$precmd duplicity $execstr_command $execstr_options $execstr_source --exclude '**' / $execstr_serverpart 2>&1"`
254
if [ $exit_code -eq 0 ]; then
256
info "Duplicity finished successfully."
259
fatal "Duplicity failed."