Repository navigation
PrePost
DatuX edited this page Nov 13, 2026
·
4 revisions
You can run commands before and after the snapshot. For example: freeze a database, so that the data on the disk is consistent.
Usually it is not necessary.
ZFS snapshots are atomic per pool. Writes during the snapshot do not cause corruption. After a restore, the application sees the same state as after a crash. Most modern databases and applications can recover from this.
If you use more than one pool, the snapshots are only atomic per pool.
Use zfs-autobackup without a target to make only the snapshot. Put the commands around it in a script:
# freeze
some-freeze-command
# make the snapshot
zfs-autobackup backup1
# unfreeze
some-unfreeze-command
# make the backup
zfs-autobackup backup1 --no-snapshot --ssh-target backupserver backups/db1Disadvantages:
- You must do the error handling yourself.
- If the source is remote, you must write the SSH commands and the escaping yourself.
zfs-autobackup runs the commands for you:
zfs-autobackup \
--pre-snapshot-cmd 'some-freeze-command'\
--post-snapshot-cmd 'some-unfreeze-command'\
--ssh-target backupserver backups/db1How it works:
- zfs-autobackup always runs the commands on the source. It uses SSH if necessary.
- If a pre-command fails, zfs-autobackup runs the post-commands and stops with an error code.
- zfs-autobackup always runs all post-commands, also when a pre-command or the snapshot fails. Thus, it always unfreezes.
zfs-autobackup:
- Introduction (README.md)
- Getting started
- Full manual
- Mounting backup datasets
- Performance tips (recommended)
- Common problems and errors
- Thinning out obsolete snapshots
- Common snapshots, holds and bookmarks
- Handling ZFS encryption
- Transfer buffering, compression and rate limiting.
- Custom Pre- and post-snapshot commands
- Monitoring
Examples: