ZFS Automatic execution of zfs-snapshot

Hello,

Is it possible to execute something like this:

# zfs destroy -r pool/users@7daysago
# zfs rename -r pool/users@6daysago @7daysago
# zfs rename -r pool/users@5daysago @6daysago
# zfs rename -r pool/users@4daysago @5daysago
# zfs rename -r pool/users@3daysago @4daysago
# zfs rename -r pool/users@2daysago @3daysago
# zfs rename -r pool/users@yesterday @2daysago
# zfs rename -r pool/users@today @yesterday
# zfs snapshot -r pool/users@today

in a automatic way with cron for instance?
Many thanks in advance
Have a nice day

Rob
 
There are many ZFS backup and snapshot utilities in ports. Have a look at them, one might have the functionality you are searching for.

Rich (BB code):
pkg search  -c zfs | egrep -i 'snapshot|backup'

zfs-snapshot-mgmt-20090201_4   Automatic ZFS snapshot management tool
freebsd-snapshot-20091208.1_4  Convenience frontend tools for the management of UFS2/ZFS snapshots
zogftw-0.0.2022.06.25_1        Creates redundant backups on encrypted ZFS pools
p5-App-ZFSCurses-1.212         Curses UI to query/modify a ZFS dataset/snapshot properties
zsd-0.0.2014.12.07_1           Destroys ZFS snapshots
zap-0.8.3_1                    Maintain and replicate ZFS snapshots
zfstools-0.3.6_2               OpenSolaris-compatible auto snapshotting for ZFS
py39-zfs-autobackup-3.2.2      Periodicly backup zfs filesystems to other locations
zfsnap2-2.0.0.b3_4             Portable performant script to make rolling ZFS snapshots easy
zfs-periodic-1.0.20130213      Simple way of maintaining zfs snapshots using the periodic system
zfs-snapshot-clean-0.2.0       Tool to sieve ZFS snapshots as per given spec a la 'pdumpfs-clean'
zfs-snap-diff-1.1.3_16         View ZFS snapshot differences via a web browser
zsm-0.4.0                      ZFS Snapshot Manager
zfs-replicate-0.7_2            ZFS Snapshot Replication Script
py39-pyznap-1.6.0              ZFS snapshot tool written in Python
znapzend-0.21.2_1              ZFS-centric backup tool
zetaback-1.0.7                 Zetaback ZFS backup and recovery management system
zetaback-devel-2020.01.31_1    Zetaback ZFS backup and recovery management system
 
I prefer naming my snapshots with the date included, like "zroot/home/backup@20240324". To support this, I've wrote a script that maintains backups for the past 31 days and removes older ones.

The relevant part for deleting older snapshots is the following command:

zfs list -H -t snapshot -o name -S creation zroot/home/backup | tail -n +32 | xargs -n 1 zfs destroy
 
I’ve been using sysutils/zfstools (usage) for over a decade on numerous systems and have been very happy with it. Add the cron jobs you like, and set com.sun:auto-snapshot=true on the filesystems/zvols you want snapshotted.

The cron jobs specify how frequently the snapshots are taken, and the arguments (label) (retention count) define how many will be retained. Snapshots are named @zfs-auto-snap_frequent-2024-03-12-10h12, for example.

Simple and effective.
 
I am using:

Code:
zfs destroy `zfs list -t snapshot -o name | grep [what to delete]@20 | head -1`

in cron, just before taking a new snapshot. "20" is date (century) of my automated snapshots. Since the oldest snapshot appears first on the list, it is deleted. No external tools needed.
 
Back
Top