Support changing the number of datasets to keep in rolling_datasets

Signed-off-by: magic_rb <richard@brezak.sk>
This commit is contained in:
magic_rb 2023-10-07 22:42:14 +02:00
parent 85db381a7e
commit 52a6d7d312
No known key found for this signature in database
GPG key ID: 08D5287CC5DDCA0E

View file

@ -8,6 +8,7 @@ if [[ "$#" != 3 ]] ; then
fi
dataset="$1"
to_keep="$2"
generation="$(zfs get :generation "$dataset" -H -o value)"
generation="$(("$generation" + 1))"
@ -18,8 +19,8 @@ zfs rollback "$dataset@blank" && echo "rollback complete"
while IFS="\n" read gen
do
printf "$gen < $(("$generation" - 10)) => "
if [ "$gen" -lt "$(("$generation" - 10))" ]; then
printf "$gen < $(("$generation" - "$to_keep")) => "
if [ "$gen" -lt "$(("$generation" - "$to_keep"))" ]; then
zfs destroy -r "$dataset/$gen"
echo "destroyed"
else