mirror of
https://git.sr.ht/~magic_rb/dotfiles
synced 2024-11-29 11:36:16 +01:00
99005cd768
Signed-off-by: magic_rb <magic_rb@redalder.org>
32 lines
779 B
Bash
32 lines
779 B
Bash
# -*- mode: shell-script -*-
|
|
|
|
source @out@/share/functions/get_old_datasets
|
|
|
|
export "PATH=$PATH:@runtimePath@"
|
|
|
|
if [[ "$#" != 2 ]] ; then
|
|
echo "This script requires precisely 2 arguments!"
|
|
exit 1
|
|
fi
|
|
|
|
dataset="$1"
|
|
to_keep="$2"
|
|
|
|
generation="$(zfs get :generation "$dataset" -H -o value)"
|
|
generation="$(("$generation" + 1))"
|
|
|
|
zfs set ":generation=$generation" "$dataset"
|
|
zfs send "$dataset" | zfs recv "$dataset/$generation"
|
|
zfs rollback "$dataset@blank" && echo "rollback complete"
|
|
|
|
while IFS="\n" read gen
|
|
do
|
|
printf -- "$gen < $(("$generation" - "$to_keep")) => "
|
|
if [ "$gen" -lt "$(("$generation" - "$to_keep"))" ]; then
|
|
zfs destroy -r "$dataset/$gen"
|
|
echo "destroyed"
|
|
else
|
|
echo "kept"
|
|
fi
|
|
done <<< "$(get_old_datasets "$dataset")"
|