zsd [--gather-snapshots-sorted-by-name] [--fork-and-forget] [--verbose][--verbose] --keep number-of-snapshots --destroy number-of-snapshots [--not-really] dataset
zsd [--gather-snapshots-sorted-by-name] [--fork-and-forget] [--verbose][--verbose] --keep number-of-snapshots [--not-really] dataset
zsd [--gather-snapshots-sorted-by-name] [--fork-and-forget] [--verbose][--verbose] --destroy number-of-snapshots [--not-really] dataset
zsd (ZFS snapshot destroyer) is a zfs(8) wrapper to destroy a number of 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. Snapshots are destroyed in the (by default chronological) order they are listed by zfs list.
zsd goes nicely with zogftw's zogftw_snapshot_successfully_sent_hook to grow a certain number of snapshots on new backup datasets while keeping the number of snapshots on old backup datasets constant.
zsd is mainly developed and tested using OpenZFS on FreeBSD, but is expected to work on other platforms as well.
--destroy number-of-snapshots If enough snapshots are available, destroy snapshots until reaching either the specified number or the number of snapshots to keep specified with --keep. If --keep isn't used, one snapshot is kept so receival of incremental snapshots continues to work.
--gather-snapshots-sorted-by-name Let zfs(8) list the available snapshots sorted by name which is a lot faster (on FreeBSD) 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. If the ZFS pool feature async_destroy is unsupported or disabled, this is generally faster than destroying the snapshots one-by-one. The downside is that it requires more memory and that errors are ignored.
Destroying too many snapshots at the same time can cause some FreeBSD versions to become unresponsive under some conditions and rebooting the system a couple of times may take longer than destroying the snapshots one-by-one. You may want to experiment with this option before using it in production environments.
--keep number-of-snapshots When used without --destroy and if enough snapshots are available, snapshots are destroyed until the given number of snapshots is reached. If the option is used together with --destroy, it specifies the number of snapshots that should be kept.
--not-really Show how many snapshots would be destroyed if the option wasn't being used, but don't actually destroy them.
--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 -d 100 -k 0 tank/blafasel Same as the above, but requires less typing.
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 -d 20 -k 20 -n tank/blafasel Shows how many snapshots would be destroyed without -n.
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.
Do you frequently have to destroy ZFS snapshots?
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 free software:
Copyright (c) 2011-2014 Fabian Keil <email@example.com> Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.