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.
I haven't tested it, but I have seen in other posts that you can remove all snapshots like this:
You could then follow-up with your
destroy
command to remove the database.This isn't a one liner, but you could use the output from
And have a script go through it and verify things carefully and destroy the the appropriate filesystems.