ZFS Backup
Previous Poudriere setup Return Freebsd Knowledge Base
ZFS Backup
- 1. ZFS Backup Prerequisites
- 2. Create snapshot
- 3. Set backup server to Receive snapshot to disk.
- 4. Send snapshot to backup-server
- 5. Test send snapshot to google drive
- 6. Send / Receive backup server zroot backup
ZFS Backup Synopsis
ZFS Backup DRAFT
ZFS Backup
For bigboy zroot to file
2 Create snapshot on bigboy. Remove the old snapshots first ># for f in `zfs list -H -rt snapshot zroot | cut -f 1`; do zfs destroy -nvf $f; done Then create the new snapshot: ># zfs snapshot -r zroot@bigboy_zroot2001201454
3 Set backup server jacup to Receive snapshot to file. ># mkdir -p /var/zfsbackup/bigboy/zroot2001201454 ># cd /var/zfsbackup/bigboy/zroot2001201454 ># nc -l 9876 | pv -p | split -a 4 -b 250m This produces files named x???? with size of 250mb.
4 Send snapshot to backup server For host bigboy that will be: ># zfs send -R zroot@bigboy_zroot2001201454 | bzip2 | pv -p | nc -w 5 jacup.sjakio.com 9876
5 Rename files to include backup name Then rename the generic files to include the backup name with: ># for file in x* ; do mv $file bigboy_zroot2001201454.$file; done
For poud zpoud to file
2 Create snapshot on poud. Remove the old snapshots first ># for f in `zfs list -H -rt snapshot zpoud | cut -f 1`; do zfs destroy -nvf $f; done Then create the new snapshot: ># zfs snapshot -r zpoud@zpoud2001201625
3 Set backup server jacup to Receive snapshot to file. ># screen ># mkdir -p /var/zfsbackup/poud/zpoud2001201625 ># cd /var/zfsbackup/poud/zpoud2001201625 ># nc -l 9876 | pv -p | split -a 4 -b 250m This produces files named x???? with size of 250mb.
4 Send snapshot to backup server For host bigboy that will be: ># zfs send -R zpoud@zpoud2001201625 | bzip2 | pv -p | nc -w 5 jacup.sjakio.com 9876
5 Rename files to include backup name Then rename the generic files to include the backup name with: ># for file in x* ; do mv $file zpoud2001201625.$file; done
For zfire to file Note we zip here on the server because of the limited resources on the firewall
2 Create snapshot on fire. Remove the old snapshots first ># for f in `zfs list -H -rt snapshot zfire | cut -f 1`; do zfs destroy -nvf $f; done Then create the new snapshot: ># zfs snapshot -r zfire@zfire2001201930
3 Set backup server jacup to Receive snapshot to file. ># mkdir -p /var/zfsbackup/fire/zfire2001201930 ># cd /var/zfsbackup/fire/zfire2001201930 ># screen ># nc -l 9876 | pv -p | bzip2 | split -a 4 -b 250m This produces files named x???? with size of 250mb.
4 Send snapshot to backup server ># screen ># zfs send -R zfire@zfire2001201930 | pv -p | nc -w 5 jacup.sjakio.com 9876
5 Rename files to include backup name Then rename the generic files to include the backup name with: ># for file in x* ; do mv $file zfire2001201930.$file; done
For zfirebox to file
Note we zip here on the server because of the limited resources on the firewall
2 Create snapshot on fire. Remove the old snapshots first ># for f in `zfs list -H -rt snapshot zfirebox | cut -f 1`; do zfs destroy -nvf $f; done Then create the new snapshot: ># zfs snapshot -r zfirebox@zfirebox2001201925
3 Set backup server jacup to Receive snapshot to file. ># mkdir -p /var/zfsbackup/firebox/zfirebox2001201925 ># cd /var/zfsbackup/firebox/zfirebox2001201925 ># screen ># nc -l 9876 | bzip2 | pv -p | split -a 4 -b 250m This produces files named x???? with size of 250mb.
4 Send snapshot to backup server ># screen ># zfs send -R zfirebox@zfirebox2001201925 | pv -p | nc -w 5 jacup.sjakio.com 9876
5 Rename files to include backup name Then rename the generic files to include the backup name with: ># for file in x* ; do mv $file zfirebox2001201925.$file; done
For bigboy zdata to disk
2 Create snapshot on bigboy. Remove the old snapshots first ># for f in `zfs list -H -rt snapshot zdata | cut -f 1`; do zfs destroy -nvf $f; done Then create the new snapshot: ># zfs snapshot -r zdata@bigboy_zdata2001211004
3 Set backup server jacup to Receive snapshot to disk. ># screen ># nc -l 9876 | bunzip2 | pv -p | zfs recv zbackup/var/zfsbackup/bigboy/zdata
4 Send snapshot to backup server
># screen
># zfs send -R zdata@bigboy_zdata2001211004 | bzip2 | pv -p | nc -w 5 jacup.sjakio.com 9876
3 Set backup server to Receive snapshot to disk. The same command is used for both the base and the incremental. First go to screen so you can detach from the session if it takes along time. ># screen In screen ># nc -l 9999 | bunzip2 | pv -p | zfs recv zbackup/var/zfsbackup/[hostname]/[dataset] To receive the root of host bigboy that will be: ># nc -l 9999 | bunzip2 | pv -p | zfs recv zbackup/var/zfsbackup/bigboy/zroot To receive the root of host firedoor that will be: ># nc -l 9999 | bunzip2 | pv -p | zfs recv zbackup/var/zfsbackup/firedoor/zroothit To receive the root with the hostname in the zpool for host firebox that will be: ># nc -l 9876 | pv -p | zfs recv zbackup/var/zfsbackup/firebox/zfirebox ># nc -l 9876 | pv -p | zfs recv zbackup/var/zfsbackup/firebox/zfirebox
mkdir -p /var/zfsbackup/fire/ ># nc -l 9876 | pv -p | zfs recv zbackup/var/zfsbackup/firebox/zfirebox
2 Create snapshot.
># zfs snapshot zroot@[hostname]_zroot[yymmddhhmm]
For host bigboy that will be: Remove the old snapshots first ># for f in `zfs list -H -rt snapshot zroot | cut -f 1`; do zfs destroy -nvf $f; done Then create the new snapshot: ># zfs snapshot -r zroot@bigboy_zroot2001201454
For host firedoor that will be: ># zfs snapshot -r zroothit@firedoor_zroothit2001041904 Or when the zroot has the host name z[host]. use ># zfs snapshot -r z[host]@z[host]2001041904 For host jacup that will be: ># zfs snapshot -r zroot@jacup_zroot2001201010 For host firebox that will be: ># zfs snapshot -r zfirebox@zfirebox2001182237 For host firebox that will be: ># zfs snapshot -r zfirebox@zfirebox2001182237 For host firebox that will be: ># zfs snapshot -r zfirebox@zfirebox2001182237
3 Set backup server to Receive snapshot to disk. The same command is used for both the base and the incremental. First go to screen so you can detach from the session if it takes along time. ># screen In screen ># nc -l 9999 | bunzip2 | pv -p | zfs recv zbackup/var/zfsbackup/[hostname]/[dataset] To receive the root of host bigboy that will be: ># nc -l 9999 | bunzip2 | pv -p | zfs recv zbackup/var/zfsbackup/bigboy/zroot To receive the root of host firedoor that will be: ># nc -l 9999 | bunzip2 | pv -p | zfs recv zbackup/var/zfsbackup/firedoor/zroothit To receive the root with the hostname in the zpool for host firebox that will be: ># nc -l 9876 | pv -p | zfs recv zbackup/var/zfsbackup/firebox/zfirebox ># nc -l 9876 | pv -p | zfs recv zbackup/var/zfsbackup/firebox/zfirebox
mkdir -p /var/zfsbackup/fire/ ># nc -l 9876 | pv -p | zfs recv zbackup/var/zfsbackup/firebox/zfirebox
3 Set backup server to Receive snapshot to file.
4 Send snapshot to backup server If base backup use: ># zfs send -R zroot@[hostname]_zroot[yymmddhhmm] | bzip2 | nc -w 5 [dns backup server] 9999 If manual add pv to see activity. ># zfs send -R zroot@[hostname]_zroot[yymmddhhmm] | bzip2 | pv -p | nc -w 5 [dns backup server] 9999
For host firedoor that will be:
># zfs send -R zroothit@firedoor_zroothit2001041026 | bzip2 | pv -p | nc -w 5 jacup.sjakio.com 9999
For host firebox that will be:
># zfs send -R zfirebox@zfirebox2001071144 | bzip2 | pv -p | nc -w 5 jacup.sjakio.com 9876
># zfs send -R zfirebox@zfirebox2001182237 | pv -p | nc -w 5 jacup.sjakio.com 9876
5 Send backup server snapshot to backup server
For host jacup there is a special case as we are local. So that will be:
Create directory for chopped files.
># mkdir /var/zfsbackup/jacup/zrootATjacup_zroot2001201010.chopped ># cd /var/zfsbackup/jacup/zrootATjacup_zroot2001201010.chopped ># screen ># zfs send -R zroot@jacup_zroot2001201010 | bzip2 | pv -p | split -a 4 -b 250m
5 Send / Receive backup server zroot snapshot Example from Freebsd handbook voor een incremental backup is: zfs send -v -i mypool@replica1 mypool@replica2 | zfs receive /backup/mypool zfs send zroot/desktop@backup > /backup-desktop.zfs ># zfs snapshot -r zroot@[hostname]_zroot[yymmddhhmm] ># zfs snapshot -r zroot@jacup_zroot2001192218 ># zfs send -R zroot@jacup_zroot2001192218 | pv -p | bzip2 > /var/zfsbackup/jacup/zrootATjacup_zroot2001192218.bzip2
If incremental snapshot use:
># zfs send -v -i zroot@[hostname]_zroot[yymmddhhmm(T-1)] [hostname]_zroot[yymmddhhmm(T)] | bzip2 | pv -p | nc -v -w5 [dns backup server] 9999
For big boy that will be:
># zfs send -v -i zroot@[hostname]_zroot[yymmddhhmm(T-1)] [hostname]_zroot[yymmddhhmm(T)] | bzip2 | pv -p | nc -v -w5 [dns backup server] 9999
4 Test send snapshot to google drive For testing we can use the command sequence. -a is the suffix length. Max is 13 we use 12 as we will not have file names just the suffix -b is the block size in bytes, set as 100m is 100 megabytes. ># cd /var/zfsbackup/rclone ># zfs send -R zbackup/var/backup/srvr@srvr_zroot1912131246 | bzip2 | split -a 12 -b 100m ># ls total 1064262 -rw-r--r-- 1 root wheel 104857600 Dec 15 12:48 xaaaaaaaaaaaa -rw-r--r-- 1 root wheel 104857600 Dec 15 12:49 xaaaaaaaaaaab -rw-r--r-- 1 root wheel 104857600 Dec 15 12:49 xaaaaaaaaaaac -rw-r--r-- 1 root wheel 104857600 Dec 15 12:50 xaaaaaaaaaaad -rw-r--r-- 1 root wheel 104857600 Dec 15 12:50 xaaaaaaaaaaae -rw-r--r-- 1 root wheel 104857600 Dec 15 12:50 xaaaaaaaaaaaf -rw-r--r-- 1 root wheel 104857600 Dec 15 12:51 xaaaaaaaaaaag -rw-r--r-- 1 root wheel 104857600 Dec 15 12:51 xaaaaaaaaaaah -rw-r--r-- 1 root wheel 104857600 Dec 15 12:52 xaaaaaaaaaaai -rw-r--r-- 1 root wheel 104857600 Dec 15 12:52 xaaaaaaaaaaaj -rw-r--r-- 1 root wheel 40527524 Dec 15 12:52 xaaaaaaaaaaak Restore from this can be done with: ># cat x* | bunzip2 | pv -p | zfs recv zbackup/var/backup/restore_srvr
6 Send backup to google drive zfs send -R zbackup/var/zfsbackup/jacup@jacup_zroot1912151310 | bzip2 | split -a 12 -b 100m ># zfs send -R zbackup/var/zfsbackup/bigboy/zroot@bigboy_zroot1912152022 | bzip2 | \
split -a 12 -b 100m | pv -p | rclone rcat
># zfs send -R zroot/poudriere/data/packages@jacup_zroot1912151310 | bzip2 | split -a 12 -b 50m | pv -p | rclone rcat gdrive-zfs:bigboy_zroot1912152022.zfs --config /usr/local/etc/rclone.conf
For bigboy that would be First create a temp directory in: /var/zfsbackup/tmprclone ># cd /var/zfsbackup/tmprclone ># mkdir bigboyzrt ># cd bigboyzrt Then create the files in this directory: ># zfs send -R zbackup/var/zfsbackup/bigboy/zroot@bigboy_zroot1912152022 | bzip2 | split -a 12 -b 250m Then send the files with rclone to gdisk, -P shows the progress zo we can see what is happening. ># rclone copy bigboyzrt secret:bigboy_zroot1912152022 -P --config /usr/local/etc/rclone.conf
For jacup that would be: ># cd /var/zfsbackup/tmprclone ># mkdir jacupzrt ># cd jacupzrt ># zfs send -vR zbackup/var/zfsbackup/jacup/zroot@jacup_zroot1912151310 | bzip2 | split -a 12 -b 250m ># rclone copy jacupzrt secret:jacup_zroot1912151310 -P --config /usr/local/etc/rclone.conf
7 Receive backup from google drive ># mkdir recvbigboyzrt ># cd recvbigboyzrt ># rclone copy secret:jacup_zroot1912151310 jacupzrt -P --config /usr/local/etc/rclone.conf
8 Restore backup
Previous Poudriere setup Return Freebsd Knowledge Base