2

You can delete a ZFS filesystem (or other dataset) with zfs destroy <dataset>. That fails if the dataset has children, including snapshots. zfs destroy -r <dataset> will remove the filesystem and its children, but will also destroy any non-snapshot children of the filesystem. Is there a succinct way to say "Delete this filesystem and its snapshots, but only if it has no non-snapshot children"?

Basically, I have a number of nested filesystems and I'm using snapshots extensively, both for replication and for cheap backups. I would like a way to easily remove child filesystems and their snapshots (e.g. zfs destroy tank/container/leaf) while providing a modicum of protection against accidentally nuking the entire filesystem collection (e.g. zfs destroy tank/container<enter>leaf)

In case it matters, I'm using ZFS on Linux with Scientific Linux 7.


Solution:

Based on longneck's comment, I can do this with two lines:

zfs destroy tank/example/leaf@%
zfs destroy tank/example/leaf

I've tested it and it does exactly what I want.

3

I haven't tested it, but I have seen in other posts that you can remove all snapshots like this:

zfs destroy -rv dataset_or_vol_name@%

You could then follow-up with your destroy command to remove the database.

1

This isn't a one liner, but you could use the output from

zfs list -t all -r -H <dataset>

And have a script go through it and verify things carefully and destroy the the appropriate filesystems.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.