Ensure to keep a number of snapshots after matching a prefix or suffix

This commit is contained in:
JensHeinrich 2023-04-26 18:10:25 +02:00
parent fe7ca9e6ee
commit f22f85ed9a
1 changed files with 11 additions and 10 deletions

View File

@ -284,16 +284,6 @@ lines=()
while read -r line; do
read -r creation used snapshot <<< "$line"
fsname=${snapshot%@*}
if [[ $keep -gt 0 ]]; then
if (( ${kept_arr["$fsname"]:-0} < keep )); then
((kept_arr[$fsname]++))
debug "skipping $snapshot: kept ${kept_arr["$fsname"]}/$keep"
continue
fi
fi
# ensure optional prefix matches
snapname=${snapshot#*@}
if [[ -n $prefix ]]; then
@ -331,6 +321,17 @@ while read -r line; do
fi
fi
# ensure at least keep snapshots are kept for each fsname
fsname=${snapshot%@*}
if [[ $keep -gt 0 ]]; then
if (( ${kept_arr["$fsname"]:-0} < keep )); then
((kept_arr[$fsname]++))
debug "skipping $snapshot: kept ${kept_arr["$fsname"]}/$keep"
continue
fi
fi
# ensure snapshot is older than the cutoff time
delta=$((now - creation))
ht=$(human-time "$delta")