diff --git a/docs/30_Scripts.md b/docs/30_Scripts.md index 1468370ccaf640873febe86d8e0572a8ee9b6203..28a8f4aeeb41331386087d964b41e42e522630f8 100644 --- a/docs/30_Scripts.md +++ b/docs/30_Scripts.md @@ -139,6 +139,7 @@ The inc_config.sh mus contain 3 variables for pruning prune_basedir=/netshare/restic-backup prune_params="--group-by paths,tags --prune --keep-within 180d --max-unused unlimited --max-repack-size 100M --cleanup-cache" prune_skipdays="7" + prune_cachedir=${prune_basedir}/.cache_for_pruning ``` ## rest_pruner.cfg diff --git a/inc_config.sh.dist b/inc_config.sh.dist index 18621c01014cc5ee11cbe65cabb256c57be0df51..9912b902c96960705efa4f61ca27bb350721e5e9 100644 --- a/inc_config.sh.dist +++ b/inc_config.sh.dist @@ -28,7 +28,9 @@ sLogfile="$sLogdir/connections.log" # for prune on restic rest server - prune_params="--group-by paths,tags --prune --keep-within 180d --max-unused unlimited --max-repack-size 100M --cleanup-cache" + prune_basedir=/netshare/restic-backup + prune_params="--group-by paths,tags --prune --keep-within 180d --max-unused unlimited --max-repack-size 100M --cleanup-cache --verbose=0" prune_skipdays="7" + prune_cachedir=${prune_basedir}/.cache_for_pruning # ---------------------------------------------------------------------- diff --git a/rest_pruner.sh b/rest_pruner.sh index 3762e9316d7b34966f85f25d510983e586d5592b..8fbf8d7ab650985565ce5439419116660a8ecf21 100755 --- a/rest_pruner.sh +++ b/rest_pruner.sh @@ -6,16 +6,18 @@ # ---------------------------------------------------------------------- # 2024-02-01 v0.1 <axel.hahn@unibe.ch> first lines # 2024-02-02 v0.2 <axel.hahn@unibe.ch> add: timer, skip file, skin N days, limit process time, stats +# 2024-02-03 v0.3 <axel.hahn@unibe.ch> enable cache dir; unlock before pruning # ====================================================================== cd "$( dirname $0 )" || exit -_version=0.2 +_version=0.3 logdir=_last_prune prune_basedir= prune_params= prune_skipdays=7 +prune_cachedir= # stop pruning more repositories when running longer N seconds prune_timeout=7200 @@ -40,6 +42,7 @@ typeset -i rcAll=0 . "inc_config.sh" || exit 1 cfgfile=rest_pruner.cfg || exit 1 +test -z "$prune_cachedir" && prune_cachedir="${prune_basedir}/.cache_for_pruning" # ---------------------------------------------------------------------- @@ -153,13 +156,24 @@ function _prune(){ fi if [ "$bDoRun" -eq "1" ]; then - local _user; _user=$( stat -c "%U" "$_dir" ) - echo ">>>>> $( _getTimer ) >>>>> $_dir" + echo ">>>>> $( _getTimer ) sec >>>>> $_dir" + + local _user; + _user=$( stat -c "%U" "$_dir" ) + + local _cachedir; + export _cachedir=$prune_cachedir/${mybase} + echo "Creating cache $_cachedir ..." + test -d "$_cachedir" || mkdir -p "$_cachedir" + chown ${_user}:${_user} "$_cachedir" + echo "Starting prune as user $_user ..." su - $_user - /bin/bash -c " echo START $( date ) $_dir export RESTIC_PASSWORD=$mypw - restic forget -r $_dir $prune_params 2>&1 + set -vx + restic unlock -r $_dir --cache-dir=$_cachedir 2>&1 + restic forget -r $_dir --cache-dir=$_cachedir $prune_params 2>&1 " | tee "${logfile}.running" rc=${PIPESTATUS[0]} rcAll+=$rc @@ -170,7 +184,10 @@ function _prune(){ else iCountPruneError+=1 mv "${logfile}.running" "${logfile}.error" + echo "!!! ERROR !!! pruning failed." fi + echo "Removing cache $_cachedir ..." + rm -rf "$_cachedir" fi else test "$bOptAll" -eq "1" && echo "SKIP: $_dir - no password for this repo"