diff --git a/plugins/transfer/restic.sh b/plugins/transfer/restic.sh index 826ae8c097b3a48508b52ed8b12287ec8d4e0628..ba4d0cce82105efa8f4d0206cc95e11ff14c2156 100644 --- a/plugins/transfer/restic.sh +++ b/plugins/transfer/restic.sh @@ -14,6 +14,7 @@ # 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-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 @@ 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 # -------------------------------------------------------------------------------- @@ -127,30 +141,22 @@ # 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 echo "__REPO__ OK, Backup repository already exists." echo "--- UNLOCK ... just in case :-)" - eval restic unlock ${ARGS_DEFAULT} - color reset + _restic unlock echo else echo "Backup repository needs to be created." - local _mycmd="restic init ${ARGS_DEFAULT}" - echo $_mycmd - color cmd - eval $_mycmd + _restic init local _myrc=$? - color reset # detect return code ... and abort on any error. t_rcCheckInit $_myrc fi - echo restic unlock ${ARGS_DEFAULT} - color cmd - eval restic unlock ${ARGS_DEFAULT} - color reset echo } @@ -161,26 +167,23 @@ # -------------------- echo "--- UNLOCK ... just in case :-)" - echo restic unlock ${ARGS_DEFAULT} - color cmd - eval restic unlock ${ARGS_DEFAULT} - color reset + _restic unlock echo } # prune old data # uses global vars from ../../transfer.sh + # return exitcode of restic prune function t_backupDoPrune(){ # -------------------- echo "--- FORGET (in all pathes of repository)" local _tag=$( _j_getvar ${STORAGEFILE} "${CFGPREFIX}tag") - local _mycmd="restic forget \ + local _mycmd="forget \ ${ARGS_DEFAULT} \ --tag $_tag \ --group-by paths,tags \ - --prune \ --cleanup-cache" local _keep @@ -192,49 +195,39 @@ fi done - echo $_mycmd - sleep 3 - color cmd - eval $_mycmd - local _myrc=$? - color reset + _restic "$_mycmd" + _myrc=$? t_rcCheckCleanup $_myrc echo # -------------------- echo "--- PRUNE (whole repository)" - _mycmd="restic prune ${ARGS_DEFAULT}" - echo $_mycmd - sleep 3 - color cmd - eval $_mycmd - local _myrc=$? - color reset + _restic prune + _myrc=$? t_rcCheckPrune $_myrc _j_runHooks "26-after-prune" "$_myrc" echo + return $_myrc } # verify backup data # uses global vars from ../../transfer.sh + # return exitcode of restic check function t_backupDoVerify(){ # -------------------- echo "--- VERIFY (whole repository)" # 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="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 + _j_runHooks "28-after-verify" "$_myrc" echo + return $_myrc } # -------------------------------------------------------------------------------- @@ -280,9 +273,7 @@ if [ "${_snapshotLast}" = "${_snapshotNow}" ]; then echo "This was the initial (full) Backup" else - color cmd - eval restic diff ${ARGS_DEFAULT} "${_snapshotLast}" "${_snapshotNow}" - color reset + _restic diff "${_snapshotLast}" "${_snapshotNow}" fi echo