If you’ve been running snapshots for a while and have already backed them up, you might occasional need to delete all zfs snapshots for your pool.
Typically, you’d do this as part of your backup script, assuming that they have been written correctly.
First, to find the used snapshot space, run this command:
zfs list -o space
This will give you a detailed readout of your pools and snapshot space used.
Here’s my script to wipe ZFS snap shots, but I am certainly open to suggestion:
zfs list -H -o name -t snapshot | xargs -n1 zfs destroy
Again, caution is needed as this will remove ALL SNAPS from your pools.
zfs destroy -rv dataset_or_zvol_name@%
To destroy all snapshots for a specific filesystem use: `zfs destroy -nv filesystem@%`
Thank you Andy and Robert, very helpful suggestions. I love snapshots but I just moved a lot of data around and my snapshotting tool (zap) is great at managing snapshots but provides no way to mass clear them. I’ve got my disk space back, thanks again!
Neither of the commands given in the comments will work as described. The destroy -nv will simply list what would be destroyed if the -n flag was not used. destroy -rv will destroy all snapshots AND THE UNDERLYING DATASET.
In general, please do not blindly type in ANY commands you find on the internet into ANY system that you care about.
Hey thanks Peter! I wrote this a while ago and haven’t been doing a great job of pruning the comment section :'(
Leave a comment