# -*- mode: shell-script -*- source @out@/share/functions/get_old_datasets export "PATH=$PATH:@runtimePath@" if [[ "$#" != 3 ]] ; 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")"