rear/SOURCES/rear-bz2111059.patch
2022-09-28 18:19:21 +00:00

106 lines
4.5 KiB
Diff

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