Faster MacOS Drive Images with SuperDuper, SSHFS, and Netcat

Article summary

I recently found myself needing to make a really thorough system image of my MacBook when my Mac OS install picked up some subtle corruption that was causing some really crazy suspend/resume bugs. I chose to make full system images with SuperDuper!, since it has proven itself quite capable in these matters in the past.

I already had Netatalk set up on my trusty personal file server, so I set up a gigabit ethernet connection with jumbo packets, mounted an AFP share on my mac, and started a backup to a new sparse bundle. “Slow” does not even begin to describe for how painfully sluggish the speeds reported by SuperDuper! were, at less than 8MB/sec. Over 18 hours were estimated to complete the backup. Since I need to work on my laptop at least 8 hours a day, this was unacceptable. Thankfully, I found a faster way.

An Alternative

Clearly, there was a bottleneck somewhere along the line. I found an article on the Shirt Pocket (creators of SuperDuper!) forums explaining how one could back up over sshfs. This was already quite a bit faster at ~26MB/sec, but I knew I could do even better. In the past, I’ve used alternative ciphers to lower the CPU load imposed by an SSH session. SSHFS, however, offers an option to bypass the “ssh” command entirely, and connect directly to a port. The unencrypted result gave me transfers at greater than 32MB/sec.

I already had OSXFuse and its SSHFS package installed on my laptop to be imaged, but if you don’t, you can grab them from homebrew (osxfuse and sshfs) or as binaries from the website.

To provide a port for SSHFS to connect to, you’ll also need something like netcat or socat on your target server. I already had “ncat” from the nmap project installed on my file server, so no further software was needed.

The Process

Here’s the final process:

  1. Create a sparse bundle on your *local* disk with Disk Utility (File > New > Blank Disk Image).
    • Make sure you choose “sparse bundle disk image” as the “Image Format,” and ensure the size is large enough to hold all the contents of the disk you want to image.
  2. Unmount the sparse bundle you just created.
  3. Start the sftp-server executable on the file server by SSHing into the file server and run the following command: ncat -l 7777 -e /usr/lib/sftp-server
    • The sftp-server executable may live in a different location on your linux server. For Arch Linux systems, try /usr/lib/ssh/sftp-server.
  4. Mount the sshfs directory you want to store your backups in. sshfs -o directport=7777 remote:/dir/backups /local/dir
  5. Move the sparse bundle from the directory you created it into the directory mounted via SSHFS.
  6. Mount the sparse bundle with MacOS. This can be done either by double-clicking it in finder or by running hdiutil attach disk_image.sparsebundle.
  7. Start SuperDuper and tell it to back up to the mounted sparse bundle.
  8. When the backup is finished, unmount the sparse bundle in finder, then unmount your sshfs connection.

Anyone who knows linux reasonably well is probably wondering why I didn’t just set up NFS on my file server. While it’s certainly a more direct route, I didn’t want to set up a permanent NFS share for what was (hopefully) going to be a single-use application. As bonuses, everything can be done without root access on your target server, and there are no pesky problems with things like NFS uid/gid conflicts.

Of course, this approach should not be used over the public internet, as it is *entirely* unencrypted. Were I to want to create a system image on a non-local machine, I’d probably fall back to standard SSHFS, as the encryption overhead would no longer be the bottleneck for most internet connections.