1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
2 HELPERS="$HELPERS rdiff:incremental_remote_filesystem_backup"
4 declare -a rdiff_includes
5 declare -a rdiff_excludes
9 do_rdiff_host_includes() {
11 # choose the files to backup
15 formBegin "$rdiff_title - host system: includes"
16 for ((i=0; i < ${#rdiff_includes[@]} ; i++))
18 formItem include ${rdiff_includes[$i]}
26 rdiff_includes="$REPLY"
32 # choose the vservers to backup (into $selected_vservers)
33 choose_one_or_more_vservers "$rdiff_title"
34 [ $? = 0 ] || return 1
37 # choose the files to backup
40 while [ -z "$REPLY" ]; do
41 formBegin "$rdiff_title - vsincludes (backup these directories from every vserver)"
42 [ -z "$rdiff_vsincludes" ] && rdiff_vsincludes="$rdiff_default_includes"
44 for i in $rdiff_vsincludes; do
52 [ $? = 0 ] || return 1
53 rdiff_vsincludes="$REPLY"
61 formBegin "$rdiff_title: excludes"
62 for ((i=0; i < ${#rdiff_excludes[@]} ; i++))
64 formItem exclude ${rdiff_excludes[$i]}
73 rdiff_excludes="$REPLY"
78 choose_host_or_vservers_or_both "$rdiff_title"
79 [ $? = 0 ] || return 1
80 case $host_or_vservers in
82 do_rdiff_host_includes
83 [ $? = 0 ] || return 1
87 [ $? = 0 ] || return 1
90 do_rdiff_host_includes
91 [ $? = 0 ] || return 1
93 [ $? = 0 ] || return 1
100 [ $? = 0 ] || return 1
112 while [ -z "$REPLY" -o -z "$rdiff_directory" -o -z "$rdiff_host" -o -z "$rdiff_user" ]
114 formBegin "$rdiff_title - destination: last three items are required"
115 formItem "keep" "$rdiff_keep"
116 formItem "dest_directory" "$rdiff_directory"
117 formItem "dest_host" "$rdiff_host"
118 formItem "dest_user" "$rdiff_user"
123 replyconverted=`echo $REPLY | tr '\n' :`
125 thereply=($replyconverted)
128 rdiff_keep=${thereply[0]}
129 rdiff_directory=${thereply[1]}
130 rdiff_host=${thereply[2]}
131 rdiff_user=${thereply[3]}
142 if [ "$_dest_done" = "" ]; then
143 msgBox "$rdiff_title: error" "You must first configure the destination."
145 elif [ "$rdiff_user" = "" ]; then
146 msgBox "$rdiff_title: error" "You must first configure the destination user."
148 elif [ "$rdiff_host" = "" ]; then
149 msgBox "$rdiff_title: error" "You must first configure the destination host."
152 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?"
156 if [ ! -f /root/.ssh/id_dsa.pub -a ! -f /root/.ssh/id_rsa.pub ]; then
157 echo "Creating local root's ssh key"
158 ssh-keygen -t dsa -f /root/.ssh/id_dsa -N ""
159 echo "Done. hit return to continue"
163 ssh -o PreferredAuthentications=publickey $rdiff_host -l $rdiff_user "exit" 2> /dev/null
164 if [ $? -ne 0 ]; then
165 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."
166 ssh-copy-id -i /root/.ssh/id_[rd]sa.pub $rdiff_user@$rdiff_host
167 if [ $? -ne 0 ]; then
168 echo "FAILED: Couldn't copy root's public ssh key to authorized_keys of $rdiff_user@$rdiff_host."
169 ssh $rdiff_user@$rdiff_host 'test -w .ssh || test -w .'
171 echo "Hit return to continue."
174 0 ) msgBox "$rdiff_title: error" "Directories are writable: Probably just a typo the first time." ;;
175 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." ;;
176 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." ;;
177 * ) msgBox "$rdiff_title: error" "Unexpected error." ;;
181 echo "Done. hit return to continue"
185 echo "root@localhost is already in authorized_keys of $rdiff_user@$rdiff_host."
186 echo "Hit return to continue."
189 # test to see if the remote rdiff backup directory exists and is writable
190 echo "Testing to see if remote rdiff backup directory exists and is writable"
191 ssh $rdiff_user@$rdiff_host "test -d ${rdiff_directory}"
194 ssh $rdiff_user@$rdiff_host "test -w $rdiff_directory"
197 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."
203 booleanBox "Remote directory does not exist" "The destination backup directory does not exist, do you want me to create it for you?"
206 ssh $rdiff_user@$rdiff_host "mkdir -p ${rdiff_directory}"
208 echo "Hit return to continue."
212 msgBox "$rdiff_title: success" "Creation of the remote destination directory was a success!"
216 msgBox "$rdiff_title: error" "Connected successfully to $rdiff_user@$rdiff_host, but was unable to create the destination directory, check the directory permissions."
220 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."
224 msgBox "$rdiff_title: error" "Unexpected error."
232 if [ $remote_status -ne 1 ]
239 echo "Testing to make sure destination has rdiff-backup installed and is compatible."
240 remote_result=`/usr/bin/rdiff-backup --test-server $rdiff_user@$rdiff_host::/ 2>&1 >&-`
243 echo $remote_result | grep -q "command not found"
246 if [ "$rdiff_user" = "root" ]
248 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?"
251 ssh $rdiff_user@$rdiff_host 'apt-get install rdiff-backup'
253 echo "Hit return to continue."
257 msgBox "$rdiff_title: success" "Installation of rdiff-backup was a success!"
261 msgBox "$rdiff_title: error" "Connected successfully to $rdiff_user@$rdiff_host, but was unable to install the package for some reason."
264 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."
267 msgBox "$rdiff_title: error" "Unexpected error."
273 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?"
282 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?"
291 echo "SUCCESS: Everything looks good!"
292 echo "Hit return to continue."
301 get_next_filename $configdirectory/90.rdiff
302 cat > $next_filename <<EOF
304 # when = everyday at 02
311 if [ "$host_or_vservers" == host -o "$host_or_vservers" == both ]
315 for ((i=0; i < ${#rdiff_includes[@]} ; i++))
317 echo "include = ${rdiff_includes[$i]}" >> $next_filename
323 if [ "$host_or_vservers" == vservers -o "$host_or_vservers" == both ]
325 cat >> $next_filename <<EOF
327 # If vservers = yes in /etc/backupninja.conf then the following variables can
329 # vsnames = all | <vserver1> <vserver2> ... (default = all)
333 # Any path specified in vsinclude is added to the include list for each vserver
334 # listed in vsnames (or all if vsnames = all).
336 # For example, vsinclude = /home will backup the /home partition in every
337 # vserver listed in vsnames. If you have vsnames = "foo bar baz", this
338 # vsinclude will add to the include list /vservers/foo/home,
339 # /vservers/bar/home and /vservers/baz/home.
340 # Vserver paths are derived from $VROOTDIR.
345 echo -e "vsnames = \"$selected_vservers\"\n" >> $next_filename
346 for i in $rdiff_vsincludes; do
347 echo "vsinclude = $i" >> $next_filename
354 for ((i=0; i < ${#rdiff_excludes[@]} ; i++))
356 echo exclude = ${rdiff_excludes[$i]} >> $next_filename
359 cat >> $next_filename <<EOF
361 ######################################################
362 ## destination section
363 ## (where the files are copied to)
367 directory = $rdiff_directory
372 chmod 600 $next_filename
378 srcitem="choose files to include & exclude $_src_done"
379 destitem="configure backup destination $_dest_done"
380 conitem="set up ssh keys and test remote connection $_con_done"
381 advitem="edit advanced settings $_adv_done"
382 menuBox "$rdiff_title" "choose a step:" \
386 finish "finish and create config file"
391 "src") do_rdiff_src;;
392 "dest") do_rdiff_dest;;
393 "conn") do_rdiff_ssh_con;;
394 "adv") do_rdiff_adv;;
396 if [[ "$_con_done$_dest_done$_src_done" != "(DONE)(DONE)(DONE)" ]]; then
397 msgBox "$rdiff_title" "You cannot create the configuration file until the other steps are completed."
409 require_packages rdiff-backup
412 rdiff_title="rdiff-backup action wizard"
418 rdiff_directory=/backup/`hostname`
422 # Global variables whose '*' shall not be expanded
424 rdiff_includes=(/var/spool/cron/crontabs /var/backups /etc /root /home /usr/local/*bin /var/lib/dpkg/status*)
425 rdiff_excludes=(/home/*/.gnupg)