wiki:FreeBSD ZFS Backup & Restore Full Instructions

Version 16 (modified by Paul Kulda, 4 months ago) ( diff )

--

FreeBSD ZFS Backup & Restore Full Instructions

Ok in my search for a way to shrink a zfs partition (which you can not do) I found a bunch of articles on the FreeBSD website.

I appreciate all the information on "how to" backup a zfs volume and the restore it on another drive fully in tact.

Issue is the restore part was way more complicated when trying to use the "LiveCD" which was nessesary as you can not restore a mounted drive and if you import the pool and rename it, it will not boot as it can no longer find the name.

The following assumes you just want to backup your FreeBSD zfs formatted boot drive and restore it on a seperate drive.

That being said here is how you do it.

  • You can backup to a network share or a portable usb drive
    • Drive or network share must be the same size or larger of the size of data.
    • Example if you are backing up a 2TB system you will need an external 2TB drive
    • Or 2TB avaliable on the nfs network share
    • please be aware on the actual data size gets backed up but best to be safe.
  • Next you need to consider the following before proceeding.
    • FreeBSD Live CD does not allow mounting of zfs pools etc (which you dont want anyways for a restore)
    • It also does not allow mounting of ntfs (windows) file system *(which means dont save your backup on a windows formated device)
    • best suggetion is to format an external usb drive using newfs
      • this will create a standard ufs file system useable anywhere.
    • or backup to a network nfs share (also supported on the LiveCD)
  • to backup the zfs volume do the following :
    • zfs snapshot zroot/ROOT/default@backup (this makes a snapshot of the zfs file structure)
    • then to do the actual backup
    • zfs send zroot/ROOT/default@backup > backup.zfs
      • destination file does not matter but the @backup does, restore name must match.
      • if you use zroot/ROOT/default@backup
      • you must restore with the same mountpoint info
    • please Do Not zip the file
    • you can for archiving purposes, but you need the raw file to restore.
    • Next you need to make note of the ZFS pools that you have
      • FreeBSD for some reason makes extra mount points on a default install
        • (/var/log, /usr/home, /usr/ports etc) - use df to show all your mountpoints
      • I took the time to sort that out and stripped my backup down to the root only.
      • you will need to consider this for all the pools being backed up and restored.
  • To restore a backup file to the zfs volume do the following :
    • You need to load FreeBSD from the cd as per usual, only the minimum install is required
    • Make sure that you are only installing to one hdd,
      • i had extra ones and the recovery did not work.
      • as the boot loader was looking for other hdd's that did not exist.
    • When you load FreeBSD on a new drive intended for the restore
    • You will need to duplicate the structure of the way it was backed up.
    • for example i had to do a bunch of zfs destroy <mount point(s) i dont need>
      • you need to do a normal boot after installing FreeBSD
      • and remove the pools
      • after removing the extra pools (if needed)
      • keep in mind if a pool is active/busy (like /var/log) then you need to umount -f /var/log (for example)
      • reboot and make sure the pool structure is exactly the same as the backup was.
      • You can now proceed to the LiveCD to restore.
    • before i could restore the file.
    • also keep in mind you probably have to backup all mount points seperately and restore them seperately ?
    • (why i took the time to strip the extra zfs mount points down to a single one)
    • Launch the Installer CD (ZFS Versions must match or be higher, best to use the same Installer for all)
      • Once logged into the LiveCD you WILL need to zpool import zroot
      • It will not mount but it loads the drivers needed to access the volume
      • You should get an error saying unable to mount to read only file system, this is GOOD!
      • next you will need to make a mount point for your data (the file that has your drive backup)
      • use /tmp/<mountpoint> as it is already in ram and will allow mounts.
      • i used /tmp/tmp for example
      • Next depending on where the backup file is located,
        • For nfs
          • Run dhclient <interface> to get connected to a network
          • then mount_nfs - o soft ipaddress:/<mountpoint>
          • verify you see the file(s) you are going to restore in /tmp/tmp
        • for usb drive
          • plug in usb drive note the device that comes up usually /dev/da(x)
          • mount the usb drive using mount /dev/da(x) /tmp/tmp
          • verify you see the file(s) you are going to restore in /tmp/tmp
  • ok now for the restore
    • zfs receive -F zroot/ROOT/default@backup < backup.zfs
    • IMPORTANT mountpoint and volume location and @ must match to what was used above.
    • Note the -F which will overwrite the destination (which is what you want)
    • From here the backup file should restore, time is dependant on how much data
    • when you get a command prompt type reboot to restart,
    • unplug any usb devices (ie dvd, usb drives etc)
Note: See TracWiki for help on using the wiki.