1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
3 HELPERS="$HELPERS rdiff:incremental_remote_filesystem_backup"
5 declare -a rdiff_includes
6 declare -a rdiff_excludes
10 do_rdiff_host_includes() {
12 # choose the files to backup
16 formBegin "$rdiff_title - host system: includes"
17 for ((i=0; i < ${#rdiff_includes[@]} ; i++))
19 formItem include ${rdiff_includes[$i]}
27 rdiff_includes="$REPLY"
33 # choose the vservers to backup (into $selected_vservers)
34 choose_one_or_more_vservers "$rdiff_title"
35 [ $? = 0 ] || return 1
38 # choose the files to backup
41 while [ -z "$REPLY" ]; do
42 formBegin "$rdiff_title - vsincludes (backup these directories from every vserver)"
43 [ -z "$rdiff_vsincludes" ] && rdiff_vsincludes="$rdiff_default_includes"
45 for i in $rdiff_vsincludes; do
53 [ $? = 0 ] || return 1
54 rdiff_vsincludes="$REPLY"
62 formBegin "$rdiff_title: excludes"
63 for ((i=0; i < ${#rdiff_excludes[@]} ; i++))
65 formItem exclude ${rdiff_excludes[$i]}
74 rdiff_excludes="$REPLY"
79 choose_host_or_vservers_or_both "$rdiff_title"
80 [ $? = 0 ] || return 1
81 case $host_or_vservers in
83 do_rdiff_host_includes
84 [ $? = 0 ] || return 1
88 [ $? = 0 ] || return 1
91 do_rdiff_host_includes
92 [ $? = 0 ] || return 1
94 [ $? = 0 ] || return 1
101 [ $? = 0 ] || return 1
113 while [ -z "$REPLY" -o -z "$rdiff_directory" -o -z "$rdiff_host" -o -z "$rdiff_user" ]
115 formBegin "$rdiff_title - destination: last three items are required"
116 formItem "keep" "$rdiff_keep"
117 formItem "dest_directory" "$rdiff_directory"
118 formItem "dest_host" "$rdiff_host"
119 formItem "dest_user" "$rdiff_user"
124 replyconverted=`echo $REPLY | tr '\n' :`
126 thereply=($replyconverted)
129 rdiff_keep=${thereply[0]}
130 rdiff_directory=${thereply[1]}
131 rdiff_host=${thereply[2]}
132 rdiff_user=${thereply[3]}
143 if [ "$_dest_done" = "" ]; then
144 msgBox "$rdiff_title: error" "You must first configure the destination."
146 elif [ "$rdiff_user" = "" ]; then
147 msgBox "$rdiff_title: error" "You must first configure the destination user."
149 elif [ "$rdiff_host" = "" ]; then
150 msgBox "$rdiff_title: error" "You must first configure the destination host."
153 booleanBox "$rdiff_title" "This step will create a ssh key for the local root user with no passphrase (if one does not already exist), and attempt to copy root's public ssh key to authorized_keys file of $rdiff_user@$rdiff_host. This will allow the local root to make unattended backups to $rdiff_user@$rdiff_host.\n\n\nAre you sure you want to continue?"
157 if [ ! -f /root/.ssh/id_dsa.pub -a ! -f /root/.ssh/id_rsa.pub ]; then
158 echo "Creating local root's ssh key"
159 ssh-keygen -t dsa -f /root/.ssh/id_dsa -N ""
160 echo "Done. hit return to continue"
164 ssh -o PreferredAuthentications=publickey $rdiff_host -l $rdiff_user "exit" 2> /dev/null
165 if [ $? -ne 0 ]; then
166 echo "Copying root's public ssh key to authorized_keys of $rdiff_user@$rdiff_host. When prompted, specify the password for user $rdiff_user@$rdiff_host."
167 ssh-copy-id -i /root/.ssh/id_[rd]sa.pub $rdiff_user@$rdiff_host
168 if [ $? -ne 0 ]; then
169 echo "FAILED: Couldn't copy root's public ssh key to authorized_keys of $rdiff_user@$rdiff_host."
170 ssh $rdiff_user@$rdiff_host 'test -w .ssh || test -w .'
172 echo "Hit return to continue."
175 0 ) msgBox "$rdiff_title: error" "Directories are writable: Probably just a typo the first time." ;;
176 1 ) msgBox "$rdiff_title: error" "Connected successfully to $rdiff_user@$rdiff_host, but unable to write. Check ownership and modes of ~$rdiff_user on $rdiff_host." ;;
177 255 ) msgBox "$rdiff_title: error" "Failed to connect to $rdiff_user@$rdiff_host. Check hostname, username, and password. Also, make sure sshd is running on the destination host." ;;
178 * ) msgBox "$rdiff_title: error" "Unexpected error." ;;
182 echo "Done. hit return to continue"
186 echo "root@localhost is already in authorized_keys of $rdiff_user@$rdiff_host."
187 echo "Hit return to continue."
190 # test to see if the remote rdiff backup directory exists and is writable
191 echo "Testing to see if remote rdiff backup directory exists and is writable"
192 ssh $rdiff_user@$rdiff_host "test -d ${rdiff_directory}"
195 ssh $rdiff_user@$rdiff_host "test -w $rdiff_directory"
198 msgBox "destination directory is not writable!" "The remote destination directory is not writable by the user you specified. Please fix the permissions on the directory and then try again."
204 booleanBox "Remote directory does not exist" "The destination backup directory does not exist, do you want me to create it for you?"
207 ssh $rdiff_user@$rdiff_host "mkdir -p ${rdiff_directory}"
209 echo "Hit return to continue."
213 msgBox "$rdiff_title: success" "Creation of the remote destination directory was a success!"
217 msgBox "$rdiff_title: error" "Connected successfully to $rdiff_user@$rdiff_host, but was unable to create the destination directory, check the directory permissions."
221 msgBox "$rdiff_title: error" "Failed to connect to $rdiff_user@$rdiff_host. Check hostname, username, and password. Also, make sure sshd is running on the destination host."
225 msgBox "$rdiff_title: error" "Unexpected error."
233 if [ $remote_status -ne 1 ]
240 echo "Testing to make sure destination has rdiff-backup installed and is compatible."
241 remote_result=`/usr/bin/rdiff-backup --test-server $rdiff_user@$rdiff_host::/ 2>&1 >&-`
244 echo $remote_result | grep -q "command not found"
247 if [ "$rdiff_user" = "root" ]
249 booleanBox "install rdiff-backup?" "It seems like the remote machine does not have rdiff-backup installed, I can attempt to install rdiff-backup on the remote machine.\n\n\nDo you want me to attempt this now?"
252 ssh $rdiff_user@$rdiff_host 'apt-get install rdiff-backup'
254 echo "Hit return to continue."
258 msgBox "$rdiff_title: success" "Installation of rdiff-backup was a success!"
262 msgBox "$rdiff_title: error" "Connected successfully to $rdiff_user@$rdiff_host, but was unable to install the package for some reason."
265 msgBox "$rdiff_title: error" "Failed to connect to $rdiff_user@$rdiff_host. Check hostname, username, and password. Also, make sure sshd is running on the destination host."
268 msgBox "$rdiff_title: error" "Unexpected error."
274 booleanBox "install rdiff-backup" "Please install rdiff-backup on the remote machine, this cannot be done automatically, as the remote user in your configuration is not root. \n\nIf you have installed rdiff-backup on the remote machine and you are getting this error, then there is a version incompatibility between that version and the local version.\n\nPlease resolve this problem and then try connecting again.\n\n\n\nTry connecting again?"
283 msgBox "incompatible versions of rdiff-backup" "It looks like rdiff-backup is installed on the remote machine, but it may be an incompatible version with the one installed locally, or something else is amiss.\n\nPlease resolve this problem and then try connecting again.\n\n\nTry connecting again?"
292 echo "SUCCESS: Everything looks good!"
293 echo "Hit return to continue."
302 get_next_filename $configdirectory/90.rdiff
303 cat > $next_filename <<EOF
305 # when = everyday at 02
312 if [ "$host_or_vservers" == host -o "$host_or_vservers" == both ]
316 for ((i=0; i < ${#rdiff_includes[@]} ; i++))
318 echo "include = ${rdiff_includes[$i]}" >> $next_filename
324 if [ "$host_or_vservers" == vservers -o "$host_or_vservers" == both ]
326 cat >> $next_filename <<EOF
328 # If vservers = yes in /etc/backupninja.conf then the following variables can
330 # vsnames = all | <vserver1> <vserver2> ... (default = all)
334 # Any path specified in vsinclude is added to the include list for each vserver
335 # listed in vsnames (or all if vsnames = all).
337 # For example, vsinclude = /home will backup the /home partition in every
338 # vserver listed in vsnames. If you have vsnames = "foo bar baz", this
339 # vsinclude will add to the include list /vservers/foo/home,
340 # /vservers/bar/home and /vservers/baz/home.
341 # Vserver paths are derived from $VROOTDIR.
346 echo -e "vsnames = \"$selected_vservers\"\n" >> $next_filename
347 for i in $rdiff_vsincludes; do
348 echo "vsinclude = $i" >> $next_filename
355 for ((i=0; i < ${#rdiff_excludes[@]} ; i++))
357 echo exclude = ${rdiff_excludes[$i]} >> $next_filename
360 cat >> $next_filename <<EOF
362 ######################################################
363 ## destination section
364 ## (where the files are copied to)
368 directory = $rdiff_directory
373 chmod 600 $next_filename
379 srcitem="choose files to include & exclude $_src_done"
380 destitem="configure backup destination $_dest_done"
381 conitem="set up ssh keys and test remote connection $_con_done"
382 advitem="edit advanced settings $_adv_done"
383 menuBox "$rdiff_title" "choose a step:" \
387 finish "finish and create config file"
392 "src") do_rdiff_src;;
393 "dest") do_rdiff_dest;;
394 "conn") do_rdiff_ssh_con;;
395 "adv") do_rdiff_adv;;
397 if [[ "$_con_done$_dest_done$_src_done" != "(DONE)(DONE)(DONE)" ]]; then
398 msgBox "$rdiff_title" "You cannot create the configuration file until the other steps are completed."
410 require_packages rdiff-backup
413 rdiff_title="rdiff-backup action wizard"
419 rdiff_directory=/backup/`hostname`
423 # Global variables whose '*' shall not be expanded
425 rdiff_includes=(/var/spool/cron/crontabs /var/backups /etc /root /home /usr/local/*bin /var/lib/dpkg/status*)
426 rdiff_excludes=(/home/*/.gnupg)