You can delete a ZFS filesystem (or other dataset) with zfs destroy
. That fails if the dataset has children, including snapshots. zfs destroy -r
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
)
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.
Answer
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.
No comments:
Post a Comment