Resetting zfs snapshots

Dave Cottlehuber dch at
Thu Feb 22 23:00:36 UTC 2018

On Thu, 22 Feb 2018, at 22:29, James B. Byrne via freebsd-questions wrote:
> I am in the process of setting up a new FreeBSD server which involves
> transferring a large amount of data onto.  The system was installed
> with root zfs and snapshots were initialised immediately.
> Several iterations of test data transfer and deletes has now resulted
> in snapshots exceeding 64 Gb.  I wish to effectively restart/rebase
> snapshots following the final transfer and eliminate all previous
> ones.
> What is the safest way to do this?

-read the manpage for `zfs destroy` carefully ;-) and make a backup.

start off using:

zfs destroy -vn zroot/path/to/dataset at first-snapshot%last-snapshot

the -n ensures it only displays what it *would* do, but actually makes
no changes.

the @first%last is an inclusive range so the destruction would include:

- first
- last
- everything in between

You may want -r which does this same range destruction for all
child datasets.

If your goal is to *recursively* nuke all snapshots prior to "now" then you can:

# make a snapshot right now that will be destroyed in the inclusive range
zfs snapshot -r zroot at before
# this snapshot will live on in infamy long after its comrades are gone
zfs snapshot -r zroot at now
# use the inclusive range to trash all preceding snapshots
zfs destroy -vrn zroot@%before
# at this point a backup is a really good idea
zfs send -LevR zroot at now > somewhere/with/space

I highly recommend Jude + Lucas'  zfs books, well worth every penny.

Also, if you're not using boot environments, start now. they are the best
thing since zfs. You have a good opportunity to test these out before your
system is live.

[1]: sysutils/beadm-devel


More information about the freebsd-questions mailing list