Skip to content
Snippets Groups Projects
Commit dc40e176 authored by Axel Hahn's avatar Axel Hahn
Browse files

add execution of hooks

parent 7410832c
No related branches found
No related tags found
1 merge request!80Add hooks
......@@ -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
......
......@@ -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
}
......
......@@ -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
......
......@@ -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
}
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment