Re: Backup/restore recipe

From: Daniel Tameling <tamelingdaniel_at_gmail.com>
Date: Thu, 13 Nov 2025 14:20:40 UTC
This is how I cloned a VM in the past:

old machine:

bectl create migrate
zfs snapshot zroot/ZROOT/migrate@2025
zfs send -prec zroot/ZROOT/migrate@2025 | ssh server 'cat > bectl.txt'

zfs snapshot zroot/home@migrate
zfs send -R zroot/home@migrate | ssh server 'cat > home.txt'

new machine: install the same version of FreeBSD. At the end of the installation don't reboot into new system yet. If you do, you will end up using zfs datasets you want to destroy, which makes the destruction impossible. Drop to shell and execute:

ssh server 'cat bectl.txt' | zfs recv zroot/ROOT/newbe
zfs activate newbe

zfs list -H -o name -t snapshot zroot/home | xargs -n1 zfs destroy
(WARNING: this will nuke zroot/home and all associated snapshots!)
ssh server 'cat home.txt' | zfs recv -dF zroot

Reboot now. If everything is working you can destroy the "old" boot environment:
zfs destroy default
bectl rename newbe default

This will give you a new machine with the old home with all snapshots but only the migrate boot environment without snapshots. I think I did this because my home snapshots were almost the same as the dataset, so there was not much overhead in keeping them and just sending boot environments means I can also "update" a live system. The problem there is the home snapshot, you can't be logged in as a user that uses zroot/home or you can't destroy it. But I think if you log in as root it works.

Also keep in mind, that bectl doesn't do a perfect clone. I think typically /usr/src and /var are not included. You might want to check the man page.

To be honest, these notes are quite old as I moved to a different backup strategy. You should test whether they really restore the system before you rely on them for backup.

What I do now is backup boot/loader.conf, etc and usr/local/etc, save the output of "pkg query -e '%a = 0' %o", and tar+rsync the important files that I haven't constantly synched anyway. 

Best regards,
Daniel