Skip to content

Instantly share code, notes, and snippets.

@R8s6
Created August 21, 2023 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save R8s6/347098d4f0cf0c195a7ee57226b6c150 to your computer and use it in GitHub Desktop.
Save R8s6/347098d4f0cf0c195a7ee57226b6c150 to your computer and use it in GitHub Desktop.
Backup & Restore ZFS to External USB Drive

Backup

1. Take a snapshot

Take a snapshot of the zpool you wish to backup

zfs snapshot tank@backup-jan-2020

2. Find external drive

Find the drive path for the external drive

For example, with a 64GB USB drive:

fdisk -l | grep 'Disk /dev'
[...]
Disk /dev/sdn: 62.4 GB, 62411243520 bytes, 121896960 sectors

/dev/sdn is the path we're interested in and will use in this tutorial.

3. Create zpool on external drive

Create a zpool on the destination drive. No need to format the drive.

zpool create backup1 /dev/sdn

4. Send snapshot to external drive

Send the snapshot to the external drive, this may take some time.

zfs send tank@backup-jan-2020 | pv | zfs recv -F backup1

5. Verify snapshot size

Compare the size of the snapshot on your data volume to the snapshot on the external volume.

The REFER amount should match.

zfs list -t snapshot | grep 'backup-jan-2020'
NAME                      USED  AVAIL  REFER  MOUNTPOINT
tank@backup-jan-2020      392K      -  1.79T  -
backup1@backup-jan-2020   0B        -  1.79T  -

6. Export the external zpool

Export the external zpool so your machine isn't looking for it

zpool export backup1

7. Power off the USB Drive (Optional)

udisksctl power-off -b /dev/sdn

Restore

1. Import the external zpool

Import the external zpool by name, or use zfs import to find the name

zfs import backup1

This should automatically mount it at /backup1, if not use zfs mount backup1 to force a mount.

2. Verify backup snapshot

Ensure a backup snapshot is present on the external drive

zfs list -t snapshot | grep backup1
NAME                      USED  AVAIL  REFER  MOUNTPOINT
backup1@backup-jan-2020   0B        -  1.79T  -

3. Send the snapshot from the external drive to the data volume

Send the snapshot to the data volume, this may take some time.

zfs send backup1@backup-jan-2020 | pv | zfs recv tank

4. Verify snapshot size

Compare the size of the snapshot on your data volume to the snapshot on the external volume.

The REFER amount should match.

zfs list -t snapshot | grep 'backup-jan-2020'
NAME                      USED  AVAIL  REFER  MOUNTPOINT
tank@backup-jan-2020      392K      -  1.79T  -
backup1@backup-jan-2020   0B        -  1.79T  -

5. Roll back to the snapshot

Roll back to the snapshot to make the data active

zfs rollback tank@backup-jan-2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment