Crates.io | zfs-autosnap |
lib.rs | zfs-autosnap |
version | 0.3.1 |
source | src |
created_at | 2021-10-09 00:41:25.399153 |
updated_at | 2021-10-09 00:41:25.399153 |
description | Automatic ZFS snapshot utility |
homepage | https://github.com/wezm/zfs-autosnap |
repository | https://github.com/wezm/zfs-autosnap.git |
max_upload_size | |
id | 462585 |
size | 29,942 |
zfs-autosnap
periodically snapshots one or more ZFS datasets and removes old
ones according to a retention policy.
In my fork I have:
zfs set at.rollc.at:snapkeep=h24d30w8m6y1 tank
zfs-autosnap snap
hourly via cron.hourly
or systemd timerzfs-autosnap gc
daily via cron.daily
Try zfs-autosnap status
to check what's going on.
See the systemd directory for sample timer files. To use these you need to update the dataset name, then enable and start the timers. E.g.
systemctl enable --now zfs-autosnap-snap.timer
systemctl enable --now zfs-autosnap-gc.timer
Pre-compiled binaries are available for x86_64 Linux and FreeBSD, they have no third-party runtime dependencies:
Example to download and extract a binary:
curl https://releases.wezm.net/zfs-autosnap/0.3.1/zfs-autosnap-0.3.1-x86_64-unknown-linux-musl.tar.gz | tar zxf -
Minimum Supported Rust Version: 1.53.0
zfs-autosnap
is implemented in Rust. See the Rust website for [instructions
on installing the toolchain][rustup].
Build the binary with cargo build --release --locked
. The binary will be in
target/release/zfs-autosnap
.
cargo install zfs-autosnap
I have a PKGBUILD for a pacman package in my personal package collection, which can be used as the basis of your own:
https://github.com/wezm/aur/tree/master/zfs-autosnap
Retention policy is set via the property at.rollc.at:snapkeep
, which must be
present on any datasets (filesystems or volumes) that you'd like to be managed.
The proposed default of h24d30w8m6y1
means to keep 24 hourly, 30 daily, 8
weekly, 6 monthly and 1 yearly snapshots but you can select any value for each
time unit, including omitting it.
The garbage collector looks at every snapshot under the managed datasets, and considers its creation time to decide whether to keep it.
Important: The snapshot name does not matter, only the creation time.
If you'd like to ensure a particular snapshot is not removed, set its
at.rollc.at:snapkeep
property to minus (-
).
If in doubt, consider reading the source: it's only about 500ish lines of code.
zfs-autosnap
will try not to eat your data; the only destructive operation is
contained within a function that will refuse to work on things that are not
snapshots - but there's NO WARRANTY. The previous version (written in Python), was
in production use since ca 2015 and there were zero incidents; this (Rust)
version is basically a source port (prior to wezm's changes).
USE AT YOUR OWN RISK.