[Rear-users] SF.net SVN: rear:[645] trunk/usr/share/rear

dag- at users.sourceforge.net dag- at users.sourceforge.net
Thu Jun 30 11:34:19 CEST 2011


Revision: 645
          http://rear.svn.sourceforge.net/rear/?rev=645&view=rev
Author:   dag-
Date:     2011-06-30 09:34:19 +0000 (Thu, 30 Jun 2011)

Log Message:
-----------
Implemented a Rear shell, with custom prompt and history.

Modified Paths:
--------------
    trunk/usr/share/rear/lib/linux-functions.sh
    trunk/usr/share/rear/restore/BACULA/default/40_restore_backup.sh
    trunk/usr/share/rear/restore/REQUESTRESTORE/default/20_prompt_user_to_start_restore.sh

Modified: trunk/usr/share/rear/lib/linux-functions.sh
===================================================================
--- trunk/usr/share/rear/lib/linux-functions.sh	2011-06-29 13:51:32 UTC (rev 644)
+++ trunk/usr/share/rear/lib/linux-functions.sh	2011-06-30 09:34:19 UTC (rev 645)
@@ -311,3 +311,41 @@
 function rpmtopdir () {
 	rpmdb -E '%{_topdir}'
 }
+
+# Provide a shell, with custom exit-prompt and history
+rear_shell() {
+    local prompt=$1
+    local history=$2
+
+    if [[ -z "$prompt" ]]; then
+        prompt="Are you sure you want to exit the Rear shell ?"
+    fi
+
+    local histfile="$TMP_DIR/.bash_history"
+    if [[ "$history" ]]; then
+        echo -e "exit\n$history" >$histfile
+    else
+        echo "exit" >$histfile
+    fi
+
+    local bashrc="$TMP_DIR/.bashrc"
+    cat <<EOF >$bashrc
+export PS1="rear> "
+ask_exit() {
+    read -p "$prompt " REPLY
+    if [[ "\$REPLY" =~ ^[Yy1] ]]; then
+        \exit
+    fi
+}
+rear() {
+    echo "ERROR: You cannot run rear from within the rear shell !" >&2
+}
+alias exit=ask_exit
+alias halt=ask_exit
+alias poweroff=ask_exit
+alias reboot=ask_exit
+alias shutdown=ask_exit
+EOF
+
+    HISTFILE="$histfile" bash --noprofile --rcfile $bashrc
+}

Modified: trunk/usr/share/rear/restore/BACULA/default/40_restore_backup.sh
===================================================================
--- trunk/usr/share/rear/restore/BACULA/default/40_restore_backup.sh	2011-06-29 13:51:32 UTC (rev 644)
+++ trunk/usr/share/rear/restore/BACULA/default/40_restore_backup.sh	2011-06-30 09:34:19 UTC (rev 645)
@@ -8,80 +8,79 @@
 # assume that the user knows how to run a restore from bacula and that they
 # know what files to restore and to where.
 
-if [ "$BEXTRACT_DEVICE" -o "$BEXTRACT_VOLUME" ]; then
+if [[ "$BEXTRACT_DEVICE" || "$BEXTRACT_VOLUME" ]]; then
 
-   if [ -b "$BEXTRACT_DEVICE" -a -d /backup ]; then
+    if [[ -s "$TMP_DIR/restore-exclude-list.txt" ]]; then
+        exclude_list=" -e $TMP_DIR/restore-exclude-list.txt "
+    fi
 
-      ### Bacula support using bextract and disk archive
-      echo "The system is now ready for a restore via Bacula. bextract will
+    if [[ -b "$BEXTRACT_DEVICE" && -d "/backup" ]]; then
+
+        ### Bacula support using bextract and disk archive
+        LogPrint "The system is now ready for a restore via Bacula. bextract will
 be started for you to restore the required files. It's assumed that you know
 what is necessary to restore - typically it will be a full backup.
 Be aware, the new root is mounted under /mnt/local.
 Do not exit bextract until all files are restored.
 "
-      read -p "Press ENTER to start bextract" 2>&1
+        read -p "Press ENTER to start bextract" 2>&1
 
-      bextract -V$BEXTRACT_VOLUME /backup /mnt/local
+        bextract$exclude_list -V$BEXTRACT_VOLUME /backup /mnt/local
 
-      echo "
-If you've exited bextract; it's because the restore has been completed.
-The next stage is to reinstall the grub bootloader which will fail if the
-correct files have not been restored.
+        LogPrint "
+Please verify that the backup has been restored correctly to '/mnt/local'
+in the provided shell. When finished, type exit in the shell to continue
+recovery.
 "
-      read -p "Press ENTER to continue" 2>&1
+        rear_shell "Did the backup successfully restore to '/mnt/local' ? Ready to continue ?" \
+            "bextract$exclude_list -V$BEXTRACT_VOLUME /backup /mnt/local"
 
-   else
+    else
 
-      ### Bacula support using bextract and tape archive
-      LogPrint "$REQUESTRESTORE_TEXT"
+        ### Bacula support using bextract and tape archive
+        LogPrint "$REQUESTRESTORE_TEXT"
 
-      LogPrint "The bextract command looks like:
+        LogPrint "The bextract command looks like:
 
-   bextract -V$BEXTRACT_VOLUME $BEXTRACT_DEVICE /mnt/local
+   bextract$exclude_list -V$BEXTRACT_VOLUME $BEXTRACT_DEVICE /mnt/local
 
 Where \"$BEXTRACT_VOLUME\" is the required Volume name of the tape,
 alternatively, use '*' if you don't know the volume,
 and \"$BEXTRACT_DEVICE\" is the Bacula device name of the tape drive."
 
-      LogPrint "After you reboot, you can restore your Bacula mysql database manually.
-
-   echo \"create database bacula;\" | mysql
-   echo \"\. /var/lib/bacula/bacula.sql\" | mysql bacula
-   /usr/lib64/bacula/grant_mysql_privileges
-   chmod 6770 /var/lib/mysql/bacula
-   chgrp bacula /var/lib/mysql/bacula
-   service bacula restart
-
+        LogPrint "Please restore your backup in the provided shell, use the shell history to
+access the above command and, when finished, type exit in the shell to continue recovery.
 "
-      read -p "IMPORTANT: return here and press ENTER when the restore is done:" 2>&1
+        rear_shell "Did you restore the backup to /mnt/local ? Ready to continue ?" \
+            "bextract$exclude_list -V$BEXTRACT_VOLUME $BEXTRACT_DEVICE /mnt/local"
 
-   fi
+    fi
 
 else
 
-   ### Bacula support using bconsole
+    ### Bacula support using bconsole
 
-   # Prompt the user that the system recreation has been done and that 
-   # bconsole is about to be started.
-   echo "The system is now ready for a restore via Bacula. bconsole will 
+    # Prompt the user that the system recreation has been done and that
+    # bconsole is about to be started.
+    echo "The system is now ready for a restore via Bacula. bconsole will
 be started for you to restore the required files. It's assumed that you know
-what is necessary to restore - typically it will be a full backup. 
-Be aware, the new root is mounted under /mnt/local.
+what is necessary to restore - typically it will be a full backup.
+Be aware, the new root is mounted under '/mnt/local'.
 Do not exit bconsole until all files are restored
 
 Press ENTER to start bconsole"
-   read
+    read
 
-   bconsole
+    bconsole
 
-   echo "
-If you've exited bconsole, it's because the restore has been completed.
-The next stage is to reinstall the grub bootloader which will fail if the 
-correct files have not been restored
-
-Press ENTER to continue
+    LogPrint "
+Please verify that the backup has been restored correctly to '/mnt/local'
+in the provided shell. When finished, type exit in the shell to continue
+recovery.
 "
-   read
+    cat <<EOF | rear_shell "Did the backup successfully restore to '/mnt/local' ? Ready to continue ?"
+bextract$exclude_list -V$BEXTRACT_VOLUME /backup /mnt/local
+EOF
 
 fi
 

Modified: trunk/usr/share/rear/restore/REQUESTRESTORE/default/20_prompt_user_to_start_restore.sh
===================================================================
--- trunk/usr/share/rear/restore/REQUESTRESTORE/default/20_prompt_user_to_start_restore.sh	2011-06-29 13:51:32 UTC (rev 644)
+++ trunk/usr/share/rear/restore/REQUESTRESTORE/default/20_prompt_user_to_start_restore.sh	2011-06-30 09:34:19 UTC (rev 645)
@@ -5,4 +5,20 @@
 
 LogPrint "$REQUESTRESTORE_TEXT"
 
-read -p "Press ENTER when the restore is done:" 2>&1
+if [[ "$REQUESTRESTORE_COMMAND" ]]; then
+    LogPrint "Use the following command to restore the backup to your system in '/mnt/local':
+
+    $REQUESTRESTORE_COMMAND
+"
+
+    LogPrint "Please restore your backup in the provided shell, use the shell history to
+access the above command and, when finished, type exit in the shell to continue
+recovery.
+"
+else
+    LogPrint "Please restore your backup in the provided shell and, when finished, type exit
+in the shell to continue recovery."
+fi
+
+    rear_shell "Did you restore the backup to /mnt/local ? Are you ready to continue recovery ?" \
+        "$REQUESTRESTORE_COMMAND"


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rear-users mailing list