Skip to content
Snippets Groups Projects
Commit 3285a47a authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch '5814-migrate-repo-to-v2' into 'master'

5814 migrate repo to v2 - rename hooks

See merge request !88
parents 484384e1 d9f6f8f3
No related branches found
No related tags found
1 merge request!885814 migrate repo to v2 - rename hooks
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
# 2021-07-13 ..... remove leading ./ in localdump.sh restore # 2021-07-13 ..... remove leading ./ in localdump.sh restore
# 2022-02-18 ..... WIP: use class like functions # 2022-02-18 ..... WIP: use class like functions
# 2022-03-17 ..... WIP: add lines with prefix __DB__ # 2022-03-17 ..... WIP: add lines with prefix __DB__
# 2022-11-04 ah rename hooks
# ====================================================================== # ======================================================================
# --- variables: # --- variables:
...@@ -354,9 +355,9 @@ ...@@ -354,9 +355,9 @@
# ----- start service specific script # ----- start service specific script
h2 "START SCRIPT FOR ${SERVICENAME} - $BACKUP_SCRIPT" h2 "START SCRIPT FOR ${SERVICENAME} - $BACKUP_SCRIPT"
_j_runHooks "12-before-db-service" _j_runHooks "200-before-db-service"
. $BACKUP_SCRIPT $mode . $BACKUP_SCRIPT $mode
_j_runHooks "18-after-db-service" "$rc" _j_runHooks "230-after-db-service" "$rc"
# ----- post jobs: cleanup # ----- post jobs: cleanup
cleanup_backup_target cleanup_backup_target
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
# 2022-05-10 ah v0.5 fix handling with nocache flag (use globally as default param - not in backup only) # 2022-05-10 ah v0.5 fix handling with nocache flag (use globally as default param - not in backup only)
# 2022-05-16 ah v0.6 added restic prune # 2022-05-16 ah v0.6 added restic prune
# 2022-10-21 ah v0.7 simplify restic exec commands in _restic; remove --prune in check # 2022-10-21 ah v0.7 simplify restic exec commands in _restic; remove --prune in check
# 2022-11-04 ah v1.0 one command for forget and prune; rename hooks
# ================================================================================ # ================================================================================
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
...@@ -177,13 +178,14 @@ ...@@ -177,13 +178,14 @@
# return exitcode of restic prune # return exitcode of restic prune
function t_backupDoPrune(){ function t_backupDoPrune(){
# -------------------- # --------------------
echo "--- FORGET (in all pathes of repository)" echo "--- FORGET AND PRUNE (in all pathes of repository)"
local _tag=$( _j_getvar ${STORAGEFILE} "${CFGPREFIX}tag") local _tag=$( _j_getvar ${STORAGEFILE} "${CFGPREFIX}tag")
local _mycmd="forget \ local _mycmd="forget \
${ARGS_DEFAULT} \ ${ARGS_DEFAULT} \
--tag $_tag \ --tag $_tag \
--group-by paths,tags \ --group-by paths,tags \
--prune \
--cleanup-cache" --cleanup-cache"
local _keep local _keep
...@@ -201,13 +203,8 @@ ...@@ -201,13 +203,8 @@
t_rcCheckCleanup $_myrc t_rcCheckCleanup $_myrc
echo echo
# --------------------
echo "--- PRUNE (whole repository)"
_restic prune
_myrc=$?
t_rcCheckPrune $_myrc _j_runHooks "330-after-prune" "$_myrc"
_j_runHooks "26-after-prune" "$_myrc"
echo echo
return $_myrc return $_myrc
...@@ -225,7 +222,7 @@ ...@@ -225,7 +222,7 @@
_myrc=$? _myrc=$?
t_rcCheckVerify $_myrc t_rcCheckVerify $_myrc
_j_runHooks "28-after-verify" "$_myrc" _j_runHooks "340-after-verify" "$_myrc"
echo echo
return $_myrc return $_myrc
} }
...@@ -405,16 +402,6 @@ ...@@ -405,16 +402,6 @@
} }
# verify backup data # verify backup data
# param integer exitcode of command # param integer exitcode of command
function t_rcCheckPrune(){
echo -n "__PRUNE__ "
case $1 in
0) color ok; echo "OK" ;;
*) color error; echo "FAILED - returncode was $1" ;;
esac
color reset
}
# verify backup data
# param integer exitcode of command
function t_rcCheckVerify(){ function t_rcCheckVerify(){
echo -n "__VERIFY__ " echo -n "__VERIFY__ "
case $1 in case $1 in
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
# 2018-08-27 ah,ds v1.2 fix restore target with a given selection; handle '*' placeholder # 2018-08-27 ah,ds v1.2 fix restore target with a given selection; handle '*' placeholder
# 2019-06-05 ah,ds v1.3 add custom cache dir # 2019-06-05 ah,ds v1.3 add custom cache dir
# 2021-05-19 ah,ds, v2.0 plugin driven # 2021-05-19 ah,ds, v2.0 plugin driven
# 2022-10-21 ah v2.1 init vars # 2022-10-21 ah v2.1 init vars; shell fixes
# ================================================================================ # ================================================================================
...@@ -32,11 +32,11 @@ ...@@ -32,11 +32,11 @@
# . `dirname $0`/inc_config.sh # . `dirname $0`/inc_config.sh
. `dirname $0`/jobhelper.sh . $(dirname $0)/jobhelper.sh
. `dirname $0`/inc_bash.sh . $(dirname $0)/inc_bash.sh
# --- load a transfer plugin # --- load a transfer plugin
STORAGE_BIN=`_j_getvar ${STORAGEFILE} "bin"` STORAGE_BIN=$(_j_getvar ${STORAGEFILE} "bin")
if [ -z "$STORAGE_BIN" ]; then if [ -z "$STORAGE_BIN" ]; then
if ! id -u | grep '^0$' if ! id -u | grep '^0$'
...@@ -50,20 +50,20 @@ ...@@ -50,20 +50,20 @@
CFGPREFIX=${STORAGE_BIN}_ CFGPREFIX=${STORAGE_BIN}_
. `dirname $0`/plugins/transfer/$STORAGE_BIN.sh || exit 1 . $(dirname $0)/plugins/transfer/$STORAGE_BIN.sh || exit 1
# --- get backend url of backup data # --- get backend url of backup data
STORAGE_BASEDIR=`_j_getvar ${STORAGEFILE} "storage"` STORAGE_BASEDIR=$(_j_getvar ${STORAGEFILE} "storage")
if [ -z $STORAGE_BASEDIR ]; then if [ -z $STORAGE_BASEDIR ]; then
echo ERROR: missing config for backup target. echo "ERROR: missing config for backup target."
echo There must be an entry storage in ${STORAGEFILE} echo "There must be an entry storage in ${STORAGEFILE}"
exit 1 exit 1
fi fi
# target directory of directory specific repository # target directory of directory specific repository
STORAGE_TARGETPATH= STORAGE_TARGETPATH=
PASSPHRASE=`_j_getvar ${STORAGEFILE} "passphrase"` PASSPHRASE=$(_j_getvar "${STORAGEFILE}" "passphrase")
# timestamp or snapshot id # timestamp or snapshot id
RESTORE_ITEM= RESTORE_ITEM=
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
RESTORE_FILTER= RESTORE_FILTER=
# full path of restore data # full path of restore data
RESTORE_BASEDIR=`_j_getvar ${STORAGEFILE} "restore-path"` RESTORE_BASEDIR=$(_j_getvar "${STORAGEFILE}" "restore-path")
RESTORE_TARGETPATH= RESTORE_TARGETPATH=
# set vars for transfer plugin # set vars for transfer plugin
...@@ -80,15 +80,16 @@ ...@@ -80,15 +80,16 @@
# ----- Create default command line parameters # ----- Create default command line parameters
export ARGS_DEFAULT
ARGS_DEFAULT="$( t_getParamDefault $1 $2 )" ARGS_DEFAULT="$( t_getParamDefault $1 $2 )"
sFileSshPrivkey=`_j_getvar ${STORAGEFILE} "ssh-privatekey"` sFileSshPrivkey=$(_j_getvar "${STORAGEFILE}" "ssh-privatekey")
if [ ! -z $sFileSshPrivkey ]; then if [ -n "$sFileSshPrivkey" ]; then
ARGS_DEFAULT="${ARGS_DEFAULT} $( t_getParamSshKey $sFileSshPrivkey )" ARGS_DEFAULT="${ARGS_DEFAULT} $( t_getParamSshKey $sFileSshPrivkey )"
fi fi
# task#3046 - add custom cache dir # task#3046 - add custom cache dir
sCacheDir=`_j_getvar ${STORAGEFILE} "cachedir"` sCacheDir=$(_j_getvar "${STORAGEFILE}" "cachedir")
ARGS_DEFAULT="${ARGS_DEFAULT} $( t_getParamCacheDir $sCacheDir )" ARGS_DEFAULT="${ARGS_DEFAULT} $( t_getParamCacheDir $sCacheDir )"
...@@ -115,7 +116,7 @@ function enterBackupDir(){ ...@@ -115,7 +116,7 @@ function enterBackupDir(){
echo "Enter the full path; marked entries with (*) do not exist on this machine" echo "Enter the full path; marked entries with (*) do not exist on this machine"
echo echo
local sDirs="`j_getDirs2Backup`" local sDirs="$(j_getDirs2Backup)"
for mydir in $sDirs for mydir in $sDirs
do do
if [ ! -d "$mydir" ]; then if [ ! -d "$mydir" ]; then
...@@ -130,7 +131,7 @@ function enterBackupDir(){ ...@@ -130,7 +131,7 @@ function enterBackupDir(){
color input color input
echo -n "[$BACKUP_DIR] >" echo -n "[$BACKUP_DIR] >"
color reset color reset
read myinput read -r myinput
setBackupDir "${myinput}" setBackupDir "${myinput}"
...@@ -143,7 +144,7 @@ function enterBackupDir(){ ...@@ -143,7 +144,7 @@ function enterBackupDir(){
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
function setBackupDir(){ function setBackupDir(){
if [ ! -z $1 ]; then if [ ! -z $1 ]; then
sDirs2Backup="`j_getDirs2Backup`" sDirs2Backup="$(j_getDirs2Backup)"
bFound=0 bFound=0
for mydir in ${sDirs2Backup} for mydir in ${sDirs2Backup}
do do
...@@ -176,7 +177,7 @@ function setBackupDir(){ ...@@ -176,7 +177,7 @@ function setBackupDir(){
# set backup url and local restore path (based on given backup directory) # set backup url and local restore path (based on given backup directory)
function setVars(){ function setVars(){
local sSafeName=`j_getSafename "$BACKUP_DIR"` local sSafeName=$(j_getSafename "$BACKUP_DIR")
RESTORE_TARGETPATH="${RESTORE_BASEDIR}/${sSafeName}" RESTORE_TARGETPATH="${RESTORE_BASEDIR}/${sSafeName}"
STORAGE_TARGETPATH="$( t_backupDirGetTarget $BACKUP_DIR )" STORAGE_TARGETPATH="$( t_backupDirGetTarget $BACKUP_DIR )"
} }
...@@ -193,7 +194,7 @@ function doRestore(){ ...@@ -193,7 +194,7 @@ function doRestore(){
fi fi
mkdir -p "${RESTORE_TARGETPATH}" mkdir -p "${RESTORE_TARGETPATH}"
echo $restorecmd echo "$restorecmd"
color cmd color cmd
$restorecmd $restorecmd
fetchrc fetchrc
...@@ -205,9 +206,9 @@ function doRestore(){ ...@@ -205,9 +206,9 @@ function doRestore(){
echo echo
echo Restore is finished. echo Restore is finished.
echo Have look to the output above. echo Have look to the output above.
echo "The restore path has `find ${RESTORE_TARGETPATH} | wc -l` items (`du -hs ${RESTORE_TARGETPATH} | awk '{ print $1 }'`)" echo "The restore path has $(find ${RESTORE_TARGETPATH} | wc -l) items ($(du -hs ${RESTORE_TARGETPATH} | awk '{ print $1 }'))"
echo echo
echo find ${RESTORE_TARGETPATH} echo "find ${RESTORE_TARGETPATH}"
exit exit
} }
...@@ -222,14 +223,10 @@ function doRestore(){ ...@@ -222,14 +223,10 @@ function doRestore(){
t_checkRequirements t_checkRequirements
setBackupDir $1 setBackupDir $1
if [ -z $BACKUP_DIR ]; then if [ -z "$BACKUP_DIR" ]; then
enterBackupDir enterBackupDir
fi fi
# init vars of the backup tool
t_getParamDefault >/dev/null
# ----- menu and loop # ----- menu and loop
while true while true
...@@ -257,7 +254,7 @@ function doRestore(){ ...@@ -257,7 +254,7 @@ function doRestore(){
echo " restore to : $RESTORE_TARGETPATH" echo " restore to : $RESTORE_TARGETPATH"
echo -n " " echo -n " "
if [ -n "$RESTORE_TARGETPATH" ]; then if [ -n "$RESTORE_TARGETPATH" ]; then
ls -d $RESTORE_TARGETPATH >/dev/null 2>&1 ls -d "$RESTORE_TARGETPATH" >/dev/null 2>&1
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
color error color error
echo "WARNING: directory already exists! Backup will fail." echo "WARNING: directory already exists! Backup will fail."
...@@ -274,7 +271,7 @@ function doRestore(){ ...@@ -274,7 +271,7 @@ function doRestore(){
echo echo
showPrompt "Select (not case sensitive) --> " showPrompt "Select (not case sensitive) --> "
read action read -r action
echo echo
case $action in case $action in
...@@ -296,7 +293,7 @@ function doRestore(){ ...@@ -296,7 +293,7 @@ function doRestore(){
h2 "Search a file" h2 "Search a file"
filefilter=".*" filefilter=".*"
showPrompt "Regex for filefilter; ${filefilter} for all >" showPrompt "Regex for filefilter; ${filefilter} for all >"
read filefilter read -r filefilter
test -z "${filefilter}" || t_restoreDoSearchFile "${filefilter}" test -z "${filefilter}" || t_restoreDoSearchFile "${filefilter}"
;; ;;
# v|V) # v|V)
...@@ -306,7 +303,7 @@ function doRestore(){ ...@@ -306,7 +303,7 @@ function doRestore(){
h2 "Shell" h2 "Shell"
echo "HINT: type exit in the subshell to return to the menu." echo "HINT: type exit in the subshell to return to the menu."
echo echo
export PS1="RESTIC [`basename $0` \u@\h \w]\$ " export PS1="RESTIC [$(basename $0) \u@\h \w]\$ "
bash --noprofile bash --noprofile
;; ;;
f|F) f|F)
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
# 2022-10-07 ah v2.5 unescape regex with space to prevent "grep: warning: stray \ before white space" # 2022-10-07 ah v2.5 unescape regex with space to prevent "grep: warning: stray \ before white space"
# 2022-10-20 ah v2.6 move hook 20-before-transfer (after init of the backup tool) # 2022-10-20 ah v2.6 move hook 20-before-transfer (after init of the backup tool)
# 2022-10-21 ah v2.7 shell fixes; # 2022-10-21 ah v2.7 shell fixes;
# 2022-11-04 ah v2.8 rename hooks
# ================================================================================ # ================================================================================
...@@ -313,7 +314,7 @@ function setAction(){ ...@@ -313,7 +314,7 @@ function setAction(){
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
# ----- PRE transfer # ----- PRE transfer
_j_runHooks "20-before-transfer" _j_runHooks "300-before-transfer"
h2 "$( date ) Wait for a free slot" h2 "$( date ) Wait for a free slot"
...@@ -390,7 +391,7 @@ function setAction(){ ...@@ -390,7 +391,7 @@ function setAction(){
echo "SKIP backup" echo "SKIP backup"
else else
_j_runHooks "22-before-folder-transfer" _j_runHooks "310-before-folder-transfer"
sCmd="$( t_backupDirGetCmdBackup )" sCmd="$( t_backupDirGetCmdBackup )"
echo "what: ${BACKUP_DIR}" echo "what: ${BACKUP_DIR}"
...@@ -404,7 +405,7 @@ function setAction(){ ...@@ -404,7 +405,7 @@ function setAction(){
echo echo
t_rcCheckBackup $myrc "${BACKUP_DIR}" t_rcCheckBackup $myrc "${BACKUP_DIR}"
_j_runHooks "24-after-folder-transfer" "$myrc" _j_runHooks "320-after-folder-transfer" "$myrc"
fi fi
echo echo
...@@ -496,7 +497,7 @@ function setAction(){ ...@@ -496,7 +497,7 @@ function setAction(){
fi fi
color reset color reset
_j_runHooks "30-post-backup" "$rc" _j_runHooks "400-post-backup" "$rc"
echo echo
typeset -i TIMER_TRANSFER typeset -i TIMER_TRANSFER
TIMER_TRANSFER=$(date +%s)-$TIMER_TRANSFER_START TIMER_TRANSFER=$(date +%s)-$TIMER_TRANSFER_START
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment