wiki:FreeBSD ZFS Backup & Restore Full Instructions

Version 6 (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 trying to use the "LiveCD"

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
  • 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
      • best suggetion is to format an external usb drive using newfs
      • 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
    • 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.
    • 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
      • I took the time to sort that out and stripped my backup down to the root only.
  • 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
    • 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 i dont need>
    • before i could restore the file.
    • also keep in mind you probablyu have to backup all mount points seperately and restore them seperately ?
    • 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 zfspool import zroot
      • It will not mount but it loads the drivers needed to access the volume
      • next you will need to make a mount point for your data
      • 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.
    • 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.