zsd: ZFS snapshot destroyer


zsd [--gather-snapshots-sorted-by-name] [--fork-and-forget] [--verbose][--verbose] --keep number-of-snapshots --destroy number-of-snapshots dataset

zsd [--gather-snapshots-sorted-by-name] [--fork-and-forget] [--verbose][--verbose] --keep number-of-snapshots dataset

zsd [--gather-snapshots-sorted-by-name] [--fork-and-forget] [--verbose][--verbose] --destroy number-of-snapshots dataset

zsd --help


zsd (ZFS snapshot destroyer) is a zfs(8) wrapper to destroy snapshots on a given dataset using a more convenient interface.

The number of snapshots to destroy can be specified directly, or indirectly by specifying the number of snapshots that should be kept.

It goes nicely with zogftw's zogftw_snapshot_successfully_sent_hook() to grow a certain number of snapshots on new datasets while keeping the number of snapshots on old datasets constant.


--keep number-of-snapshots If this option is used without --destroy, every snapshot above the specified number is destroyed. If it is used together with --destroy, it specifies a number of snapshots that should be kept.

--destroy number-of-snapshots Destroy snapshots until reaching either the specified number or the number of snapshots to keep specified with --keep. If --keep isn't used, a limit of 1 is assumed to keep incrementals working.

--gather-snapshots-sorted-by-name Let zfs(8) list the available snapshots sorted by name which is a lot faster as less metadata has to be read. This should only be used if the order in which snapshots are destroyed doesn't matter or if sorting the snapshots by name keeps the chronological order.

--fork-and-forget Fork a process for each snapshots that should be destroyed and don't check if the operation is successful. This is generally faster than destroying the snapshots one-by-one, especially if the zpool feature async_destroy isn't used. The downside is that it requires more memory and that errors are ignored.

Note that on FreeBSD destroying too many snapshots at the same time can apparently cause the system to become unresponsive under some conditions and rebooting the system a couple of times may take longer than destroying the snapshots one-by-one. It's unclear if this is still an issue, so please let me know if you run into it, especially if you are able to reproduce it.

--verbose Be more verbose. When specified once, the destroyed snapshots are shown. When specified twice, the kept snapshots are shown as well.

All options can be shortened as long as there are no ambiguities.


The following examples are independent and assume a dataset tank/blafasel with 100 snapshots.

zsd --destroy 10 tank/blafasel Destroys 10 snapshots.

zsd --destroy 100 tank/blafasel Destroys 99 snapshots as not using --keep implies that at least one snapshot should be kept.

zsd --destroy 100 --keep 0 tank/blafasel Destroys all the 100 snapshots as no snapshot has to be kept.

zsd --destroy 100 --keep 40 tank/blafasel Destroys 60 snapshots as 40 snapshots have to be kept.

zsd --destroy 10 --keep 40 tank/blafasel Destroys 10 snapshots, keeping 90 as 40 is only the lower limit.

zsd --destroy 100 --keep 200 tank/blafasel Destroys no snapshot as the number of snapshots to keep is above the number of snapshots available on the dataset.

zsd --keep 10 tank/blafasel Destroys 90 snapshots as not using --destroy implies that all the snapshots above the limit should be destroyed.


zfs(8) zogftw(8)


Do you frequently have to destroy ZFS snapshots? Download zsd now! (OpenPGP signature)

Given that zsd is part of the FreeBSD ports collection, FreeBSD users can install it with: cd /usr/ports/sysutils/zsd && sudo make install clean

zsd is written in Perl and licensed under the ISC license.