Hello,

The `zfs destroy` man page rightly warns about using `-r`:

> Extreme care should be taken when applying either the -r or the
> -R options, as they can destroy large portions of a pool and
> cause unexpected behavior for mounted file systems in use.

I've submitted a PR[0] to openzfs adding a new `-t` option, which
reduces the capabilites of a given `zfs destroy` call. The goal is
to make `-r` safer to use, by letting the caller specify the type of
what they're trying to destroy.

The `-t` option accepts a comma-separated list of the following
values: filesystem, volume, snapshot, snap, bookmark, and all.

It has the following behaviors:

* attempting to delete a single thing which does not match a provided
   type fails.
* Passing `-t snapshot` will guarantee that only snapshots are
   destroyed.
* a recursive destroy with `-t volume` or `-t filesystem` will not
   delete any filesystems or volumes which have snapshots or bookmarks.
* a recursive destroy with `-t volume,snapshot` or
   `-t filesystem,snapshot` will delete any filesystems or volumes
   which have snapshots.
* Passing `-t volume,bookmark` has the same behavior, but with
   bookmarks.
* Passing `-t volume,snapshot,bookmark` will delete all volumes and
   their bookmarks and snapshots.

What do y'all think?

Thanks,
Graham Christensen

0: https://github.com/openzfs/zfs/pull/9882
------------------------------------------
openzfs: openzfs-developer
Permalink: 
https://openzfs.topicbox.com/groups/developer/T06af513a824c4d4b-M975c88db892546597d874b2b
Delivery options: https://openzfs.topicbox.com/groups/developer/subscription

Reply via email to