summaryrefslogtreecommitdiffstats
path: root/zfs_snapshot_cleanup.sh
diff options
context:
space:
mode:
Diffstat (limited to 'zfs_snapshot_cleanup.sh')
-rwxr-xr-xzfs_snapshot_cleanup.sh14
1 files changed, 14 insertions, 0 deletions
diff --git a/zfs_snapshot_cleanup.sh b/zfs_snapshot_cleanup.sh
new file mode 100755
index 0000000..ba743ac
--- /dev/null
+++ b/zfs_snapshot_cleanup.sh
@@ -0,0 +1,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