Here is the process that I use to create local zfs backups.
Manual Backup Procedure
- Create Snapshots
- zfs snapshot -r storage/containers@backup-20240115
- -r: for recursive
- Create a RaidZ1 Pool as our backup target
- zpool create backup-pool raidz1 [DISK1] [DISK2] [DISK3] [DISK4]
- Send the initial snapshot
- zfs send -R --raw storage/containers@backup-20240115 | zfs receive -o readonly=on backup-pool/containers
- -R: for recursive
- --raw: so that encrypted data is not decrypted (not encrypted data will remain not encrypted)
- -o readonly=on: so that the backups are not editable
- Send incremental snapshots
- zfs send -R --raw -I storage/containers@backup-20240115 storage/containers@backup-20240210 | zfs receive backup-pool/containers
- -I [prev-snapshot]: incremental data since specified snapshot
Automating Backup Procedure
- Created the below scripts to help automate in /root/backup_scripts/
- snapshot.sh
- snapshot-all.sh
- backup.sh
- backup-all.sh
- Set the snapshot-all.sh script on crontab to run monthly
- crontab -e
- 05 8 1 * * sh /root/backup_scripts/snapshot-all.sh
- remember that the cron time is UTC
- Manually push the backups
- nohup sh backup-all.sh >>all.log 2>&1 &
Scripts
snapshot.sh
snapshot-all.sh
sh /root/backup_scripts/snapshot.sh rpool
sh /root/backup_scripts/snapshot.sh storage
backup.sh
backup-all.sh
Appendix
Sources
- https://www.jeffgeerling.com/blog/2021/htgwa-create-zfs-raidz1-zpool-on-raspberry-pi
- https://forum.proxmox.com/threads/solved-help-needed-on-a-script-for-automating-zfs-snapshots-to-removable-media.81784/
- https://mtlynch.io/zfs-encrypted-backups/
- https://unix.stackexchange.com/questions/263677/how-to-one-way-mirror-an-entire-zfs-pool-to-another-zfs-pool
- https://www.reddit.com/r/zfs/comments/1c3vnkm/cannot_receive_incremental_stream_destination_has/
- https://openzfs.github.io/openzfs-docs/man/master/8/zfs-recv.8.html
- https://docs.oracle.com/cd/E36784_01/html/E36835/gnheq.html
- https://openzfs.github.io/openzfs-docs/man/master/8/zpool-scrub.8.html