summaryrefslogtreecommitdiffstats
path: root/zfs_snapshot_cleanup.sh
blob: ba743ac002a219879e5391a25a6f96551219c673 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash

if (($#<3)); then
	echo "usage: ${0##*/} <filesystem|volume> <snapshot prefix> <number of snapshots to keep>"
	exit 1
fi

filesystem=$1
snapshotname=$2
keep=$3

keep=$((keep+1))

zfs list -H -t snapshot -o name -S creation -d1 "$filesystem" | grep "^$filesystem@$snapshotname" | tail -n +$keep | xargs -r -n 1 zfs destroy -r