Skip to content

Commit

Permalink
prefix mtime param with a +, use -name param for passing pattern to find
Browse files Browse the repository at this point in the history
  • Loading branch information
m90 committed Aug 20, 2021
1 parent b558a57 commit b7ba0e0
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,43 +107,48 @@ probe_expired () {
local target=$1
local is_local=$2
if [ -z "$is_local" ]; then
if [ ! -z "$BACKUP_PRUNING_PREFIX" ]; then
target="${target}/${BACKUP_PRUNING_PREFIX}"
fi
mc rm $MC_GLOBAL_OPTIONS --fake --recursive --force \
--older-than "${BACKUP_RETENTION_DAYS}d" \
"$target"
else
find $target* -type f -mtime $BACKUP_RETENTION_DAYS
find $target -name "${BACKUP_PRUNING_PREFIX:-*}" -type f -mtime "+${BACKUP_RETENTION_DAYS}"
fi
}

probe_all () {
local target=$1
local is_local=$2
if [ -z "$is_local" ]; then
if [ ! -z "$BACKUP_PRUNING_PREFIX" ]; then
target="${target}/${BACKUP_PRUNING_PREFIX}"
fi
mc ls $MC_GLOBAL_OPTIONS "$target"
else
find $target* -type f
find $target -name "${BACKUP_PRUNING_PREFIX:-*}" -type f
fi
}

delete () {
local target=$1
local is_local=$2
if [ -z "$is_local" ]; then
if [ ! -z "$BACKUP_PRUNING_PREFIX" ]; then
target="${target}/${BACKUP_PRUNING_PREFIX}"
fi
mc rm $MC_GLOBAL_OPTIONS --recursive --force \
--older-than "${BACKUP_RETENTION_DAYS}d" \
"$target"
else
find $target* -delete -type f -mtime $BACKUP_RETENTION_DAYS
find $target -name "${BACKUP_PRUNING_PREFIX:-*}" -type f -mtime "+${BACKUP_RETENTION_DAYS}" -delete
fi
}

prune () {
local target=$1
local is_local=$2
if [ ! -z "$BACKUP_PRUNING_PREFIX" ]; then
target="$target/${BACKUP_PRUNING_PREFIX}"
fi

rule_applies_to=$(probe_expired "$target" "$is_local" | wc -l)
if [ "$rule_applies_to" == "0" ]; then
echo "No backups found older than the configured retention period of ${BACKUP_RETENTION_DAYS} days."
Expand Down

0 comments on commit b7ba0e0

Please sign in to comment.