LinuxDojo

How to Set Up a ZFS Snapshot Backup from FreeBSD to a Raspberry Pi

This guide documents the process of configuring a Raspberry Pi as a ZFS backup server and performing an initial snapshot transfer from a FreeBSD machine.

Step 1: Prepare the Raspberry Pi Backup Server

The first step is to install the necessary ZFS packages and configure the external storage on the Raspberry Pi.

1.1 Install ZFS Packages

We used apt to install ZFS on the Raspberry Pi. The zfs-dkms package is crucial as it ensures the ZFS kernel modules are always compatible with your kernel, even after updates.

sudo apt update
sudo apt install raspberrypi-kernel-headers zfs-dkms zfsutils-linux

1.2 Identify the Backup Drive

To ensure robustness, we identified the external drive using its unique, persistent ID rather than a generic device name like /dev/sda. This prevents issues if the drive order changes on reboot.

ls -l /dev/disk/by-id/

1.3 Create the ZFS Pool

We used zpool create to create a new ZFS pool that will store your backups. The -f flag was necessary to force the creation and overwrite any existing data on the disk, as it had an old filesystem. We named the pool fbsdserver-backup-072625.

sudo zpool create -f fbsdserver-backup-072625 /dev/disk/by-id/usb-Seagate_BarracudaFastSSD_00000000NABF00ZX-0:0

We then enabled compression on the new pool, which saves disk space with minimal performance overhead.

sudo zfs set compression=on fbsdserver-backup-072625

Step 2: Create a Snapshot on the FreeBSD Server

A ZFS snapshot is an instant, read-only copy of your filesystem at a specific point in time. This is the data we will be sending to the backup server.

sudo zfs snapshot -r zroot@fbsdserver-backup-072625

Step 3: Transfer the Snapshot

This is the core of the backup process. We use a combination of ZFS commands and SSH to securely stream the data from the FreeBSD server to the Raspberry Pi.

sudo zfs send -R zroot@fbsdserver-backup-072625 | ssh joe@192.168.1.12 "sudo zfs receive -F fbsdserver-backup-072625"

This initial transfer is a full copy. All subsequent backups will be much faster and only transfer the incremental changes between new snapshots.