|
|
d32ec1 |
commit 552dd6bfb20fdb3dc712b5243656d147392c27c3
|
|
|
d32ec1 |
Author: Johannes Meixner <jsmeix@suse.com>
|
|
|
d32ec1 |
Date: Thu Jun 2 15:25:52 2022 +0200
|
|
|
d32ec1 |
|
|
|
d32ec1 |
Merge pull request #2811 from rear/jsmeix-RECOVERY_COMMANDS
|
|
|
d32ec1 |
|
|
|
d32ec1 |
Add PRE_RECOVERY_COMMANDS and POST_RECOVERY_COMMANDS
|
|
|
d32ec1 |
as alternative to PRE_RECOVERY_SCRIPT and POST_RECOVERY_SCRIPT
|
|
|
d32ec1 |
see the description in default.conf how to use them and how they work.
|
|
|
d32ec1 |
See https://github.com/rear/rear/pull/2811 and see also
|
|
|
d32ec1 |
https://github.com/rear/rear/pull/2735 therein in particular
|
|
|
d32ec1 |
https://github.com/rear/rear/pull/2735#issuecomment-1134686196
|
|
|
d32ec1 |
Additionally use LogPrint to show the user the executed commands,
|
|
|
d32ec1 |
see https://github.com/rear/rear/pull/2789
|
|
|
d32ec1 |
|
|
|
d32ec1 |
diff --git a/usr/share/rear/conf/default.conf b/usr/share/rear/conf/default.conf
|
|
|
d32ec1 |
index cb14da8b..b14525da 100644
|
|
|
d32ec1 |
--- a/usr/share/rear/conf/default.conf
|
|
|
d32ec1 |
+++ b/usr/share/rear/conf/default.conf
|
|
|
d32ec1 |
@@ -3117,14 +3117,37 @@ ELILO_BIN=
|
|
|
d32ec1 |
################ ---- custom scripts
|
|
|
d32ec1 |
#
|
|
|
d32ec1 |
# NOTE: The scripts can be defined as an array to better handly spaces in parameters.
|
|
|
d32ec1 |
-# The scripts are called like this: eval "${PRE_RECOVERY_SCRIPT[@]}"
|
|
|
d32ec1 |
+# The scripts are called like this:
|
|
|
d32ec1 |
+# eval "${PRE_RECOVERY_SCRIPT[@]}"
|
|
|
d32ec1 |
+#
|
|
|
d32ec1 |
+# Alternatively, commands can be executed by using the corresponding
|
|
|
d32ec1 |
+# PRE_RECOVERY_COMMANDS and POST_RECOVERY_COMMANDS array variables
|
|
|
d32ec1 |
+# which evaluate like this:
|
|
|
d32ec1 |
+# for command in "${PRE_RECOVERY_COMMANDS[@]}" ; do
|
|
|
d32ec1 |
+# eval "$command"
|
|
|
d32ec1 |
+# done
|
|
|
d32ec1 |
+#
|
|
|
d32ec1 |
+# Using PRE_RECOVERY_COMMANDS and POST_RECOVERY_COMMANDS
|
|
|
d32ec1 |
+# is simpler when multiple commands should be executed.
|
|
|
d32ec1 |
+# For example,
|
|
|
d32ec1 |
+# PRE_RECOVERY_SCRIPT=( 'echo Hello' ';' 'sleep 3' )
|
|
|
d32ec1 |
+# can be rewritten as
|
|
|
d32ec1 |
+# PRE_RECOVERY_COMMANDS=( 'echo Hello' 'sleep 3' )
|
|
|
d32ec1 |
+# or
|
|
|
d32ec1 |
+# PRE_RECOVERY_COMMANDS=( 'echo Hello' )
|
|
|
d32ec1 |
+# PRE_RECOVERY_COMMANDS+=( 'sleep 3' )
|
|
|
d32ec1 |
+
|
|
|
d32ec1 |
+# Those get called at the very beginning of "rear recover".
|
|
|
d32ec1 |
+# The PRE_RECOVERY_COMMANDS are called directly before the PRE_RECOVERY_SCRIPT.
|
|
|
d32ec1 |
+# Nothing was recreated and you have only the plain ReaR rescue/recovery system:
|
|
|
d32ec1 |
+PRE_RECOVERY_COMMANDS=()
|
|
|
d32ec1 |
+PRE_RECOVERY_SCRIPT=
|
|
|
d32ec1 |
|
|
|
d32ec1 |
-# Call this after Relax-and-Recover did everything in the recover workflow.
|
|
|
d32ec1 |
-# Use $TARGET_FS_ROOT (by default '/mnt/local') to refer to the recovered system.
|
|
|
d32ec1 |
+# Those get called at the very end of "rear recover".
|
|
|
d32ec1 |
+# The POST_RECOVERY_COMMANDS are called directly after the POST_RECOVERY_SCRIPT.
|
|
|
d32ec1 |
+# Use $TARGET_FS_ROOT (by default '/mnt/local') to access the recreated target system.
|
|
|
d32ec1 |
POST_RECOVERY_SCRIPT=
|
|
|
d32ec1 |
-
|
|
|
d32ec1 |
-# Call this before Relax-and-Recover starts to do anything in the recover workflow. You have the rescue system but nothing else
|
|
|
d32ec1 |
-PRE_RECOVERY_SCRIPT=
|
|
|
d32ec1 |
+POST_RECOVERY_COMMANDS=()
|
|
|
d32ec1 |
|
|
|
d32ec1 |
# PRE/POST Backup scripts will provide the ability to run certain tasks before and after a ReaR backup.
|
|
|
d32ec1 |
# for example:
|
|
|
d32ec1 |
diff --git a/usr/share/rear/setup/default/010_pre_recovery_script.sh b/usr/share/rear/setup/default/010_pre_recovery_script.sh
|
|
|
d32ec1 |
index 005107cc..8b4e4a36 100644
|
|
|
d32ec1 |
--- a/usr/share/rear/setup/default/010_pre_recovery_script.sh
|
|
|
d32ec1 |
+++ b/usr/share/rear/setup/default/010_pre_recovery_script.sh
|
|
|
d32ec1 |
@@ -1,4 +1,14 @@
|
|
|
d32ec1 |
+
|
|
|
d32ec1 |
+# The PRE_RECOVERY_COMMANDS are called directly before the PRE_RECOVERY_SCRIPT
|
|
|
d32ec1 |
+# so PRE_RECOVERY_COMMANDS can also be used to prepare things for the PRE_RECOVERY_SCRIPT:
|
|
|
d32ec1 |
+
|
|
|
d32ec1 |
+local command
|
|
|
d32ec1 |
+for command in "${PRE_RECOVERY_COMMANDS[@]}" ; do
|
|
|
d32ec1 |
+ LogPrint "Running PRE_RECOVERY_COMMANDS '$command'"
|
|
|
d32ec1 |
+ eval "$command"
|
|
|
d32ec1 |
+done
|
|
|
d32ec1 |
+
|
|
|
d32ec1 |
if test "$PRE_RECOVERY_SCRIPT" ; then
|
|
|
d32ec1 |
- Log "Running PRE_RECOVERY_SCRIPT '${PRE_RECOVERY_SCRIPT[@]}'"
|
|
|
d32ec1 |
- eval "${PRE_RECOVERY_SCRIPT[@]}"
|
|
|
d32ec1 |
+ LogPrint "Running PRE_RECOVERY_SCRIPT '${PRE_RECOVERY_SCRIPT[@]}'"
|
|
|
d32ec1 |
+ eval "${PRE_RECOVERY_SCRIPT[@]}"
|
|
|
d32ec1 |
fi
|
|
|
d32ec1 |
diff --git a/usr/share/rear/wrapup/default/500_post_recovery_script.sh b/usr/share/rear/wrapup/default/500_post_recovery_script.sh
|
|
|
d32ec1 |
index 77751800..866c9368 100644
|
|
|
d32ec1 |
--- a/usr/share/rear/wrapup/default/500_post_recovery_script.sh
|
|
|
d32ec1 |
+++ b/usr/share/rear/wrapup/default/500_post_recovery_script.sh
|
|
|
d32ec1 |
@@ -1,4 +1,14 @@
|
|
|
d32ec1 |
+
|
|
|
d32ec1 |
+# The POST_RECOVERY_COMMANDS are called directly after the POST_RECOVERY_SCRIPT
|
|
|
d32ec1 |
+# so POST_RECOVERY_COMMANDS can also be used to clean up things after the POST_RECOVERY_SCRIPT:
|
|
|
d32ec1 |
+
|
|
|
d32ec1 |
if test "$POST_RECOVERY_SCRIPT" ; then
|
|
|
d32ec1 |
- Log "Running POST_RECOVERY_SCRIPT '${POST_RECOVERY_SCRIPT[@]}'"
|
|
|
d32ec1 |
- eval "${POST_RECOVERY_SCRIPT[@]}"
|
|
|
d32ec1 |
+ LogPrint "Running POST_RECOVERY_SCRIPT '${POST_RECOVERY_SCRIPT[@]}'"
|
|
|
d32ec1 |
+ eval "${POST_RECOVERY_SCRIPT[@]}"
|
|
|
d32ec1 |
fi
|
|
|
d32ec1 |
+
|
|
|
d32ec1 |
+local command
|
|
|
d32ec1 |
+for command in "${POST_RECOVERY_COMMANDS[@]}" ; do
|
|
|
d32ec1 |
+ LogPrint "Running POST_RECOVERY_COMMANDS '$command'"
|
|
|
d32ec1 |
+ eval "$command"
|
|
|
d32ec1 |
+done
|