Here’s a small bash script to destroy all existing zfs snapshots.
Run at your own risk! 🙂
It’s better to get rid of cut command:
for snapshot in `zfs list -H -o name -t snapshot`
zfs list -H -o name -t snapshot | xargs -n1 zfs destroy
is even better 🙂
I found that when deleting snapshots from multiple shares this works okay:
zfs list -H -o name -t snapshot|grep nameofzfsshare|pfexec xargs -n1 zfs destroy
while trying the same thing we came up with this line
It helps to see what is going to be deleted
zfs list -H -o name -t snapshot | grep | while read SNAPSHOT;do echo $SNAPSHOT; zfs destroy $SNAPSHOT;done
This is an edit because first post was truncated
zfs list -H -o name -t snapshot | grep nameofsnapshot| while read SNAPSHOT;do echo $SNAPSHOT; zfs destroy $SNAPSHOT;done
@Mihai your command is using while the wrong way.
use # while read SNAPSHOT;do echo $SNAPSHOT; zfs destroy $SNAPSHOT;done < <(zfs list -H -o name -t snapshot | grep nameofsnapshot)
A quick one liner to delete all snapshots but keep the latest 3 (for BSD without GNU head command that linux gets):
zfs list -o name -t snapshot |tail +2 |sed ‘$d’|sed ‘$d’|sed ‘$d’|xargs -n1 zfs destroy
If anyone knows a better way to do this with sed I would love to know.
[…] In terminal #2, enter the following (taken from here): […]
Stolen from elsewhere:
To delete all snapshots:
zfs destroy -rv snapshot_name@%
You can test first with -rnv
Jin: nice, but keeping 30 is still a pain 🙂 Wish we had head -n -30.
Seriously? I really need an edit button.
zfs destroy -rv dataset_or_vol_name@%
Thanks before. But, can you help to find how to remove only the old snapshot script for Ubuntu?
And the script will be running on cron every day.