Bulk ZFS snapshot delete (in dataset / pool-wide)

Hi,
I have about ~40k snapshots in one of my pools and TrueNAS is advising me to bring it below 10k in a notification. I would like to do a bulk delete of all snapshots in the pool. However, the snapshots web interface only allows me to delete 100 at a time. That is going to take along time to get up above 40k.

How can I do bulk delete of al snapshots in (a) a pool and (b) a dataset?

Thank you.

Andy

zfs list -h -t snap | awk '/<insert suitable regex here>/ { printf "zfs destroy %s\n", $1 }' | sh

Man, <insert suitable regex here> is the IT equivalent of the Claymore “FRONT TOWARD ENEMY” instruction.

It’s an apparently simple admonition, but disastrous if you get it wrong :laughing:

You can do it without | sh first to check.

1 Like

Thanks for the reply.

So what should be in the ‘insert suitable regex here’? Name of the data set?

E.g. poo\/path\/to\/dataset - this will hit all snapshots of the dataset and potential child datasets.

But check first - this will if you have e.g. datasets named “dataset” and “datasetfoo” and “datasetbar” … hit all three of them.

As I wrote to check what will be deleted just omit the | sh at the end.

So if the root data set I went to delete snapshots for is zdata/photos, what would the regex be? Sorry not that familiar with awl.

*want, *awk

You can use the % symbol to delete an entire sequence of snapshots.


To delete all snapshots of a dataset within a range of two specified snapshots:

zfs destroy -nv tank/mydata@snap20230101%snap20240615

This will delete all snapshots of the dataset tank/mydata, including intermediary ones (regardless of name), between @snap20230101 and @snap20240615,


You can also delete recursively, which will also destroy any such snapshots within range in the children datasets:

zfs destroy -nvr tank/mydata@snap20230101%snap20240615

If you don’t specify anything after the % symbol, then it will interpret that you want to delete all snapshots up to the very latest one.

zfs destroy -nv tank/mydata@snap20230101%

I kept -n in the flags for good reason. This will only do a dry run and not actually destroy anything.

3 Likes

As posted in the other thread you opened:

zdata\/photos

Once you’ve resolved your excess snapshot issue, you may want to look into this approach to periodic snapshots

BTW, if the snapshots were taken with a snapshot task, adjusting the expiry will fix after the next time the task fires. Even if they weren’t, if a task can be created that would’ve, then if can be used to prune the snapshots.

2 Likes