ansitest/ZFS/zfs-killsnaps.sh

29 lines
616 B
Bash
Raw Normal View History

2021-04-12 14:40:45 -05:00
#!/bin/bash
# REF: https://sysadminman.net/blog/2008/remove-all-zfs-snapshots-50
2021-04-12 17:36:04 -05:00
# destroy arg snapshots on pool (to free space) and track what got killed
# NOTE does NOT do Recursive and can grep on whatever criteria matches!
# NOTE no logfile rotation
# 2014 Dave Bechtel
2021-04-12 14:40:45 -05:00
#crit=daily
crit=weekly
#crit=$zp
[ "$1" = "" ] || crit="$1"
logfile=/root/zfs-killsnaps.log
function dokill () {
crit=$1
2021-04-12 17:36:04 -05:00
for snapshot in $(zfs list -H -t snapshot |grep $crit | cut -f 1)
2021-04-12 14:40:45 -05:00
do
2021-04-12 17:36:04 -05:00
echo "$(date) - Killing $snapshot" |tee -a $logfile
2021-04-12 14:40:45 -05:00
time zfs destroy $snapshot
done
}
dokill $crit
2021-04-12 17:36:04 -05:00
#dokill hourly
2021-04-12 14:40:45 -05:00
#dokill weekly