diff --git a/backup.sh b/backup.sh index 11ec7c4e2ef5aeb61a2b36b73003d2dd8707b84d..121aef6c0eb85d92b14d7cb55adb314e1f7160a0 100755 --- a/backup.sh +++ b/backup.sh @@ -176,7 +176,7 @@ EOFbackupinfo if [ $bStart -eq 1 ]; then - _j_runHooks "hooks/10-before-backup/always" + _j_runHooks "10-before-backup" sleep 3 @@ -190,16 +190,9 @@ EOFbackupinfo echo "INFO: $(date) - Making local backups ... ${DIR_SELF}/localdump.sh ALL" | tee -a "$JOB_LOGFILE" - _j_runHooks "hooks/12-before-db-service/always" "${DIR_SELF}"/localdump.sh ALL | tee -a "$JOB_LOGFILE" rcBackup=$? - if [ $rcBackup -eq 0 ]; then - _j_runHooks "hooks/18-after-db-service/on-ok" - else - _j_runHooks "hooks/18-after-db-service/on-error" - fi - _j_runHooks "hooks/18-after-db-service/always" echo "INFO: $(date) - local backups were finished" | tee -a "$JOB_LOGFILE" echo diff --git a/jobhelper.sh b/jobhelper.sh index 1334c9d86adc4b7a04aa75a1f34c1a4462a739f3..f51b71629e146a58c5862beaac9f83da8ee5bda1 100755 --- a/jobhelper.sh +++ b/jobhelper.sh @@ -181,22 +181,38 @@ function _j_getvar(){ # ------------------------------------------------------------ # execute hook skripts in a given directory in alphabetic order -# param string name of hook directory +# param string name of hook directory +# param string optional: integer of existcode or "" for non-on-result hook # ------------------------------------------------------------ function _j_runHooks(){ - local _hookdir=$1 - echo - echo ">>> HOOKS $_hookdir" + local _hookbase="$1" + local _exitcode="$2" + local _hookdir="hooks/$_hookbase" + + if [ -z "$_exitcode" ]; then + _hookdir="$_hookdir/always" + elif [ "$_exitcode" = "0" ]; then + _hookdir="$_hookdir/on-ok" + else + _hookdir="$_hookdir/on-error" + fi + for hookscript in $( ls -1a "$_hookdir" | grep -v "^\.*$" | sort ) do if [ -x "$hookscript" ]; then - echo "start $hookscript ..." + echo ">>> HOOKS $_hookdir start $hookscript ..." $hookscript - else - echo "SKIP: $hookscript (not executable)" + # else + # echo "SKIP: $hookscript (not executable)" fi done + # if an exitcode was given as param then run hooks without exitcode + # (in subdir "always") + if [ -n "$_exitcode" ]; then + _j_runHooks "$_hookbase" + fi + echo } diff --git a/localdump.sh b/localdump.sh index 3bb293ae694dc2026b0abfe00ea9d95c063e4200..36abbfe34e9fe995d54b964ce3633b919482b441 100755 --- a/localdump.sh +++ b/localdump.sh @@ -204,7 +204,7 @@ if [ -d "${BACKUP_TARGETDIR}" ]; then cd "${BACKUP_TARGETDIR}" if [ -z $1 ]; then - find -type f | sed "s#__[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9].*##g" | grep -v ".meta" | sort -ud| sed "s#^\./##g" + find -type f | sed "s#__[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9].*##g" | grep -v "\.meta" | sort -ud| sed "s#^\./##g" else ls -ltr "$*__"* | sed "s#^\./##g" fi @@ -354,7 +354,9 @@ # ----- start service specific script h2 "START SCRIPT FOR ${SERVICENAME} - $BACKUP_SCRIPT" + _j_runHooks "12-before-db-service" . $BACKUP_SCRIPT $mode + _j_runHooks "18-after-db-service" "$rc" # ----- post jobs: cleanup cleanup_backup_target diff --git a/plugins/transfer/restic.sh b/plugins/transfer/restic.sh index 75a92cb2c52209a8db71b3063ccc5724ed9c0acc..032fe28339dc3c7814517543ec40071623fd6b7b 100644 --- a/plugins/transfer/restic.sh +++ b/plugins/transfer/restic.sh @@ -213,6 +213,8 @@ color reset t_rcCheckPrune $_myrc + _j_runHooks "26-after-prune" "$_myrc" + echo } # verify backup data @@ -231,6 +233,7 @@ color reset t_rcCheckVerify $_myrc + _j_runHooks "28-after-verify" "$_myrc" echo } diff --git a/transfer.sh b/transfer.sh index 2355de80c3c8b8b75e0b4749ca10ebbed2df0af3..5ec5c5fb9dffcb56675789b30df33a8d3839cc31 100755 --- a/transfer.sh +++ b/transfer.sh @@ -219,13 +219,14 @@ function setAction(){ fi . `dirname $0`/plugins/transfer/$STORAGE_BIN.sh || exit 1 - test -z "$STORAGE_REGISTER" || . `dirname $0`/plugins/register/$STORAGE_REGISTER.sh || exit 1 # -------------------------------------------------------------------------------- # ----- Check requirements t_checkRequirements || exit 1 + test -z "$STORAGE_REGISTER" || . `dirname $0`/plugins/register/$STORAGE_REGISTER.sh || exit 1 + echo Check locking of a running transfer if [ -f "${lockfile}" ]; then color error @@ -268,6 +269,8 @@ function setAction(){ exit 2 fi + _j_runHooks "20-before-transfer" + # -------------------------------------------------------------------------------- # ----- BACKUP VARS @@ -379,6 +382,9 @@ function setAction(){ if [ $doBackup -eq 0 ]; then echo "SKIP backup" else + + _j_runHooks "22-before-folder-transfer" + sCmd="$( t_backupDirGetCmdBackup )" echo "what: ${BACKUP_DIR}" echo "target: ${sTarget}" | sed 's#:[^:]*@#:**********@#' @@ -391,6 +397,7 @@ function setAction(){ echo t_rcCheckBackup $myrc "${BACKUP_DIR}" + _j_runHooks "24-after-folder-transfer" "$myrc" fi echo @@ -410,6 +417,8 @@ function setAction(){ fi echo done + else + echo "SKIP backup of dirs" fi # --- prune @@ -469,6 +478,8 @@ function setAction(){ echo Backup FAILED :-/ fi color reset + + _j_runHooks "30-post-backup" "$rc" echo typeset -i TIMER_TRANSFER=`date +%s`-$TIMER_TRANSFER_START echo `date` $ACTION DONE in $TIMER_TRANSFER sec