A very nice way to do a live backup of your server/work station is with ZFS snapshots, of course, if you use ZFS.
You can send a snapshot to: a file, the local system, via ssh, via netcat and who know what else.
I’m going to cover how to do incremental snapshots to your local system using a USB drive.
To do zfs snapshot, zfs send & zfs receive you are going to need elevated permissions. Always be extremely careful with ZFS operations because you can easily destroy all of your data! The following commands worked for me but might not work for you, alway be sure before you execute a command, do NOT copy&paste them from here.
- Connect the drive, look what’s coming up in /var/log/messages. Let’ say is da0
- Check the disk and create a new zpool
diskinfo -v /dev/da0
zpool create backup_pool /dev/da0
-
- Now let’s see if the pool is available
zpool import
Then import it
zpool import backup_pool
- Now let’s see if the pool is available
- Let’s take a snapshot of a single dataset or an entire pool we want to backup
zfs snapshot zroot/files@20180410
– snapshot only files dataset
zfs snapshot -r zroot@20180410
– recursive snapshot of zroot pool
- Send the snapshot, do this from a terminal multiplexor such as tmux or screen, when you do something like this always do a dry run first “-n”. Depends on the size of the dataset or pool, it can take hours or days or more.
zfs send -v zroot/files@20180410| zfs receive -vun zbackup/files@20180410
zfs send -vR zroot@20180411 | zfs receive -vu zbackup/zroot_20180411
-
- To do an incremental snapshot, do not remove the original snapshot from the system, create a new then send it, with incremental snapshots you can save a lot of time because it will only send the differences
zfs send -vi zroot/files@20180410 zroot/files@new_snapshot | zfs receive -vnuF zbackup/files
zfs send -viR zroot@20180410 zroot@new_snapshot| sudo zfs receive -vnuF zbackup/zroot
- To do an incremental snapshot, do not remove the original snapshot from the system, create a new then send it, with incremental snapshots you can save a lot of time because it will only send the differences
- Check if the snapshots are there
zfs list -t snapshot
- To remove the USB drive
zpool export zbackup
Do azpool status
to check if indeed was removed
FreeBSD ZFS manual: https://www.freebsd.org/cgi/man.cgi?zfs
FreeBSD ZPOOL manual https://www.freebsd.org/cgi/man.cgi?zpool
FReeBSD GPART manual: https://www.freebsd.org/cgi/man.cgi?gpart
There are dedicated tools as well to do backups and more with zfs, one of them is: zxfer
To be continued…
2 thoughts on “ZFS snapshot on FreeBSD”