From 52f0e243c286bfede308da60366413b2cdb9019e Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 24 Jun 2020 21:48:25 +0200 Subject: [PATCH] Add support for pre- and post-backup commands. --- hosts/backup_script.sh.sample | 23 ++++++++++++++++++ hosts/scripts/main_part.include | 42 +++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/hosts/backup_script.sh.sample b/hosts/backup_script.sh.sample index 58efcaa..c1dba0a 100644 --- a/hosts/backup_script.sh.sample +++ b/hosts/backup_script.sh.sample @@ -70,6 +70,29 @@ ssh_keyfile=$HOME/.ssh/id_dsa ## - ssh_user=back +## - Commands executed on srcHost befor saving +## - +## - pre_backup_commands=("#" ["#"] ..) +## - +## - Example: +## - pre_backup_commands=( +## - "www-data#/usr/local/php/bin/php /var/www/cloud-02.oopen.de/htdocs/occ maintenance:mode --on" +## - ... +## - ) +pre_backup_commands=() + + +## - Commands executed on srcHost after saving +## - +## - post_backup_commands=("#" ["#"] ..) +## - +## - Example: +## - post_backup_commands=( +## - "www-data#/usr/local/php/bin/php /var/www/cloud-02.oopen.de/htdocs/occ maintenance:mode --off" +## - ... +## - ) +post_backup_commands=() + ## - what to store ? ## - diff --git a/hosts/scripts/main_part.include b/hosts/scripts/main_part.include index f0796c6..e16b208 100644 --- a/hosts/scripts/main_part.include +++ b/hosts/scripts/main_part.include @@ -276,6 +276,27 @@ if [ "$found" = "true" -o "$pgsql_backup" = "true" -o "$mysql_backup" = "true" export svn_source_base_path svn_gzip $script_dir/svn_backup.sh fi + + if [[ -n "$pre_backup_commands" ]]; then + + echolog "\nGoing to execute pre backup commands.." + + for _val in "${pre_backup_commands[@]}" ; do + + err_Log=${LOCK_DIR}/svn.err.log + > $err_Log + + IFS='#' read -a _val_arr <<< "${_val}" + + echolog "\t${_val_arr[0]}: ${_val_arr[1]}" + $ssh ${ssh_user}@${srcHost} "$sudo -u ${_val_arr[0]} ${_val_arr[1]}" > /dev/null 2> $err_Log + if [[ "$?" -ne 0 ]]; then + $(cat "$err_Log") + fi + + done + fi + if $mysql_backup ;then if [[ ${#mysql_credential_args_arr[@]} -gt 0 ]] ; then @@ -328,6 +349,27 @@ if [ "$found" = "true" -o "$pgsql_backup" = "true" -o "$mysql_backup" = "true" backup_dir=$dir $script_dir/net_mounted_dir_backup.sh done fi + + if [[ -n "$post_backup_commands" ]]; then + + echolog "\nGoing to execute post backup commands.." + + for _val in "${post_backup_commands[@]}" ; do + + err_Log=${LOCK_DIR}/svn.err.log + > $err_Log + + IFS='#' read -a _val_arr <<< "${_val}" + + echolog "\t${_val_arr[0]}: ${_val_arr[1]}" + $ssh ${ssh_user}@${srcHost} "$sudo -u ${_val_arr[0]} ${_val_arr[1]}" > /dev/null 2> $err_Log + if [[ "$?" -ne 0 ]]; then + $(cat "$err_Log") + fi + + done + fi + fi # if $NO_NEW_BACKUP end_h=`$date +%H`