Time Machine Backups

From OpenZFS on OS X
Jump to: navigation, search

Backup to Local Disk

There are two approaches to using ZFS for Time Machine Backups - Sparsebundles on a ZFS data set and zvols formatted as HFS+.

Sparsebundles

Here's one approach to using ZFS for your Time Machine Backups.

Because Time Machine doesn't recognize ZFS datasets as a compatible disk for Time Machine backups, as a work around, we create an HFS+ sparsebundle disk image, store it on a ZFS dataset, and set the mounted image as a backup destination (no "TMShowUnsupportedNetworkVolumes" needed).

1. Create, and mount, a sparsebundle from a ZFS dataset (e.g., with makeImage.sh or Disk Utility.app).

2. Set the sparsebundle as the (active) backup destination:

# tmutil setdestination -a /Volumes/[sparse bundle volume name]

While it has been discussed in heated arguments (e.g., https://github.com/openzfsonosx/zfs/issues/66) I still believe there's at least one ZFS feature I'd like to test with Time Machine: compression.

The hypothesis being that an HFS+ sparsebundle stored on a compressed (gzip, lz4), deduped dataset should yield a compression ratio > 1.0 (previously observed 1.4 with compression=on, dedup=off, FreeBSD network Time Machine drives).

Does not work under Ventura.

zvols

    Tested successfully under Ventura using raidz1 with cache disk (all disks on USB).
  1. Create a zvol to use for Time Machine backups:

    sudo zfs create -V [size] [pool]/[volume]

    For example, the following will create a 1TB volume named tmdisk1 on a zpool named Backup:

    sudo zfs create -V 1T Backup/tmdisk1

  2. Get OSX disk number corresponding to the zvol:

    ioreg -trn "ZVOL [pool]/[volume] Media" | awk -F'"' '/BSD Name/ {print $4;}'

    For example, if a zvol named tmdisk1 was created as shown above, the following will get its disk number and store it in the shell variable DISKID:

    ioreg -trn 'ZVOL Backup/tmdisk1 Media' | awk -F'"' '/BSD Name/ {print $4;}'

  3. Format the zvol as a HFS+, using its disk number from the previous step:

    sudo diskutil eraseDisk JHFS+ [OSX Disk Name] [disk number]

    For example, if the zvol was disk5 in OSX, the following will format that disk as a HFS+ disk named "TimeMachine":

    sudo diskutil eraseDisk JHFS+ "TimeMachine" disk5

    For newer systems (Big Sur), because Time Machine now prefers apfs (see https://support.apple.com/en-au/guide/mac-help/mh15139/mac), the following commands should create a apfs zvol that Time Machine can use:

    sudo diskutil eraseDisk JHFS+ [OSX Disk Name] GPT [disk number]
    sudo diskutil apfs create [disk number]s[slice number] [OSX Disk Name]

    For example, if the zvol was disk5 in OSX, and the HFS+ volume on that zvol was on slice 1 (which can be confirmed using 'diskutil list disk5') the following should format that disk as a apfs disk named "TimeMachine":

    sudo diskutil eraseDisk JHFS+ "TimeMachine" GPT disk5
    sudo diskutil apfs create disk5s1 "TimeMachine"
  4. Set the zvol as a Time Machine destination:

    sudo tmutil setdestination -a /Volumes/[OSX Disk Name]

    For example, if the zvol was formatted as HFS+ named "TimeMachine" in the previous steps, the following will set it as a Time Machine destination:

    sudo tmutil setdestination -a /Volumes/TimeMachine

  5. (Optional) Enable encryption for Time Machine backups on the zvol:
    • For HFS+ formatted zvols, the following procedure should work:
      1. Get the disk identifier for the HFS+ disk on the zvol:

        diskutil list [OSX Disk Name] | awk '/[OSX Disk Name]/ { print $NF;}'

        For example, if the zvol was formatted as HFS+ named "TimeMachine" in step 3, the following will get its disk identifier:

        diskutil list TimeMachine | awk '/TimeMachine/ { print $NF; }'

      2. Convert the HFS+ disk to use encryption:

        sudo diskutil coreStorage convert [Disk ID] -passphrase

        This will ask for the encryption password (which may be stored in the Keychain). For example, if the if the zvol was formatted as HFS+ named "TimeMachine" in step 3, whose disk identifier was returned as disk5s2 in step 5.1, the following will convert the disk to use encryption:

        sudo diskutil coreStorage convert disk5s2 -passphrase

        Please note, this process can take a considerable amount of time (several hours for a 1TB volume). You can check on the progress of the encryption using the following command:

        diskutil cs list | grep -e "Conversion" -e "Volume Name"

    • For apfs formatted zvols, the following procedure should work (based on comments in the forums, see https://openzfsonosx.org/forum/viewtopic.php?f=26&t=3612):

      sudo diskutil apfs encryptvolume [Disk ID] -user disk

      This will ask for the encryption password (which may be stored in the Keychain). For example, if the zvol was formatted as apfs named "TimeMachine" in a prior step, whose disk identifier was returned as disk5s1, the following will convert the disk to use encryption:

      sudo diskutil apfs encryptvolume disk5s1 -user disk

      Based on the forums (see https://openzfsonosx.org/forum/viewtopic.php?f=26&t=3612), it is possible to "bless" the Time Machine zvol by "open /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericTimeMachineDiskIcon.icns", select the first icon in the resulting window, copying (⌘-C) the icon, then Get Info (⌘-I) on the Time Machine disk icon, and pasting (⌘-V) the copied image to the Time Machine disk to "bless" it as a Time Machine disk. For some reason, Time Machine won't do that by itself, as it does with normal external volumes when it first starts using them for Time Machine.

Backup to Network Share

Time Machine can backup over the network to either HFS+ or APFS target volumes, shared via SMB. If you try to do this with a ZFS target volume, the client gets an error saying "The selected network backup disk does not support the required capabilities."

You have two options from this point on:

  1. You can create an HFS+ or APFS target volume on your zpool. There are two ways to do that, explained in the section above about local backups: create the volume as a sparse bundle, or as a zvol.
  2. You can set the properties com.apple.devdisk and com.apple.mimic_hfs to 'on' on the dataset you wish to put your backups onto, through the zfs set command. (note that if you do this through an already mounted dataset, you may have to unmount it and re-mount it again after issuing the zfs set commands)

You don't need the steps that set the volume as a time machine destination on the server; it's just going to be shared over the network. When you share the volume on the network, follow the instructions at https://support.apple.com/guide/mac-help/a-shared-folder-time-machine-mac-mchl31533145/mac to make it available as a TimeMachine volume.