First and foremost, create a checkpoint for your pool.
zpool checkpoint <poolname>
Then you’ll want to list out the snapshots in TXG
order. (Which is the default, anyways)
Even though you can do this recursively, it’s safer to just do it at a per-dataset, step-by-step process.
Yes, it’s more “manual” and will take more time and require more redundant steps. But when it comes to data, it’s better to go slowly rather than go crazy with recursive, bulk actions.
zfs list -t snap -o name,used,refer,createtxg -s createtxg <poolname>/<path>/<to>/<dataset> | less
The command might appear to “hang” the first time you run it, since it needs to fetch and populate this list.
The oldest will be at the top of the list, and the newest will be at the bottom. This also assumes you’re only looking at the snapshots of a single dataset.
Use PgDown, PgUp, ▼, and ▲ to scroll and assess the list. Press Q to exit the scrollable less
view.
After you’ve decided on the “range” of snapshots you wish to prune, you can do a “dry-run” to simulate deleting the sequential batch. (I’m using fake snapshot names and dates for this example.)
For my example, I choose to delete everything from @auto-2022-01-01
to @auto-2024-06-30
zfs destroy -nv <poolname>/<path>/<to>/<dataset>@auto-2022-01-01%auto-2024-06-30
The %
symbol instructs the zfs destroy
command to delete all snapshots from auto-2022-01-01
to auto-2024-06-30
.
If you feel comfortable, remove the -n
flag, which will delete the snapshots this time, without a “dry-run”.
zfs destroy -v <poolname>/<path>/<to>/<dataset>@auto-2022-01-01%auto-2024-06-30
You can repeat this again for the other datasets that need pruning of their snapshots.
Shortly after, if everything looks good and you’re happy with the results, you can safely remove the checkpoint.
zpool checkpoint -d <poolname>