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

simplify restic exec commands in _restic

parent 41454ff9
No related branches found
No related tags found
1 merge request!875814 migrate repo to v2
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# 2022-03-07 ah v0.4 add verify in post task # 2022-03-07 ah v0.4 add verify in post task
# 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
# ================================================================================ # ================================================================================
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
...@@ -119,6 +120,19 @@ ...@@ -119,6 +120,19 @@
fi fi
} }
# execute a restic command
# param string options and subcommand
function _restic(){
local _mycmd="restic $* ${ARGS_DEFAULT}"
echo "$_mycmd"
sleep 3
color cmd
eval "$_mycmd"
local _myrc=$?
color reset
return $_myrc
}
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
# BACKUP ACTIONS :: TRANSFER # BACKUP ACTIONS :: TRANSFER
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
...@@ -127,30 +141,22 @@ ...@@ -127,30 +141,22 @@
# function t_backupDoPreTasks(){ # function t_backupDoPreTasks(){
function t_backupDoPreTasks(){ function t_backupDoPreTasks(){
if eval restic snapshots ${ARGS_DEFAULT} >/dev/null 2>&1 # if eval restic snapshots ${ARGS_DEFAULT} >/dev/null 2>&1
if _restic list keys >/dev/null 2>&1
then then
echo "__REPO__ OK, Backup repository already exists." echo "__REPO__ OK, Backup repository already exists."
echo "--- UNLOCK ... just in case :-)" echo "--- UNLOCK ... just in case :-)"
eval restic unlock ${ARGS_DEFAULT} _restic unlock
color reset
echo echo
else else
echo "Backup repository needs to be created." echo "Backup repository needs to be created."
local _mycmd="restic init ${ARGS_DEFAULT}" _restic init
echo $_mycmd
color cmd
eval $_mycmd
local _myrc=$? local _myrc=$?
color reset
# detect return code ... and abort on any error. # detect return code ... and abort on any error.
t_rcCheckInit $_myrc t_rcCheckInit $_myrc
fi fi
echo restic unlock ${ARGS_DEFAULT}
color cmd
eval restic unlock ${ARGS_DEFAULT}
color reset
echo echo
} }
...@@ -161,26 +167,23 @@ ...@@ -161,26 +167,23 @@
# -------------------- # --------------------
echo "--- UNLOCK ... just in case :-)" echo "--- UNLOCK ... just in case :-)"
echo restic unlock ${ARGS_DEFAULT} _restic unlock
color cmd
eval restic unlock ${ARGS_DEFAULT}
color reset
echo echo
} }
# prune old data # prune old data
# uses global vars from ../../transfer.sh # uses global vars from ../../transfer.sh
# return exitcode of restic prune
function t_backupDoPrune(){ function t_backupDoPrune(){
# -------------------- # --------------------
echo "--- FORGET (in all pathes of repository)" echo "--- FORGET (in all pathes of repository)"
local _tag=$( _j_getvar ${STORAGEFILE} "${CFGPREFIX}tag") local _tag=$( _j_getvar ${STORAGEFILE} "${CFGPREFIX}tag")
local _mycmd="restic 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
...@@ -192,49 +195,39 @@ ...@@ -192,49 +195,39 @@
fi fi
done done
echo $_mycmd _restic "$_mycmd"
sleep 3 _myrc=$?
color cmd
eval $_mycmd
local _myrc=$?
color reset
t_rcCheckCleanup $_myrc t_rcCheckCleanup $_myrc
echo echo
# -------------------- # --------------------
echo "--- PRUNE (whole repository)" echo "--- PRUNE (whole repository)"
_mycmd="restic prune ${ARGS_DEFAULT}" _restic prune
echo $_mycmd _myrc=$?
sleep 3
color cmd
eval $_mycmd
local _myrc=$?
color reset
t_rcCheckPrune $_myrc t_rcCheckPrune $_myrc
_j_runHooks "26-after-prune" "$_myrc" _j_runHooks "26-after-prune" "$_myrc"
echo echo
return $_myrc
} }
# verify backup data # verify backup data
# uses global vars from ../../transfer.sh # uses global vars from ../../transfer.sh
# return exitcode of restic check
function t_backupDoVerify(){ function t_backupDoVerify(){
# -------------------- # --------------------
echo "--- VERIFY (whole repository)" echo "--- VERIFY (whole repository)"
# param --read-data takes a long time. Maybe use an extra job with it. # param --read-data takes a long time. Maybe use an extra job with it.
# _mycmd="time restic check ${ARGS_DEFAULT} --with-cache --read-data" # _mycmd="time restic check ${ARGS_DEFAULT} --with-cache --read-data"
_mycmd="restic check ${ARGS_DEFAULT} --with-cache"
echo $_mycmd
sleep 3
color cmd
eval $_mycmd
local _myrc=$?
color reset
_restic check --with-cache
_myrc=$?
t_rcCheckVerify $_myrc t_rcCheckVerify $_myrc
_j_runHooks "28-after-verify" "$_myrc" _j_runHooks "28-after-verify" "$_myrc"
echo echo
return $_myrc
} }
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
...@@ -280,9 +273,7 @@ ...@@ -280,9 +273,7 @@
if [ "${_snapshotLast}" = "${_snapshotNow}" ]; then if [ "${_snapshotLast}" = "${_snapshotNow}" ]; then
echo "This was the initial (full) Backup" echo "This was the initial (full) Backup"
else else
color cmd _restic diff "${_snapshotLast}" "${_snapshotNow}"
eval restic diff ${ARGS_DEFAULT} "${_snapshotLast}" "${_snapshotNow}"
color reset
fi fi
echo echo
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment