Restoring files from TimeMachine backup on Synology

I have a large Time Machine backup on my Synology NAS and wanted to restore files from it to a computer other than the source of the backup. In fact, I wanted to only get (unknown) incremental changes from the backup. Because it was a separate computer I was not able to use the Apple interface easily plus I wasn’t sure what the incremental changes were. And so I was planning to use Unison with a forced direction to get all the latest files from a 2TB backup. Initially I mounted the sparsebundle backup image on the destination computer, unsurprisingly running Unison on this was extremely slow as Unison needed to read the 2TB over a Wifi connection. Next I thought it would be faster to mount the sparsebundle on the Synology and have a instance of Unison go through the files locally while communicating with another instance of Unison on the destination computer.

Below is a write up of how the time machine sparsebundle can be mounted in the Debian Chroot environment of the Synology, using sparsebundlefs and tmfs. This could be useful for others that want to access their Time Machine backup information directly from the Synology NAS side.

The first requirement is the Debian Chroot environment; see my previous post for instructions on the configuration of this. Next you will need to install the necessary dependencies in the chroot environment (use sudo for all commands to elevate your rights if you are not logged in as root). sparsebundlefs requires fuse-utils which is not included in Debian Jessie as a package, but is included in Debian Wheezy. We will need to add the wheezy main repository for it to be installed.

Edit the file /etc/apt/sources.list to include the following line:
deb wheezy main

Next install the following packages:

apt-get update
apt-get -t wheezy install fuse-utils
apt-get install curl build-essential libfuse-dev libfuse2 parted pkg-config tmfs

Download the latest sparsebundlefs source:
curl -L | tar xvz
Enter the directory that was created and compile the source code:
The build should result in a binary executable called sparsebundlefs. This will allow you to mount the sparsebundle disk image (where iMac.sparsebundle is the name of my backup sparsebundle created by Time Machine on my Synology).
mkdir /mnt/sparsebundle
./sparsebundlefs iMac.sparsebundle /mnt/sparsebundle

You will find the sparsebundle available as a .dmg diskimage (/mnt/sparsebundle/sparsebundle.dmg) that we can mount. However, the disk image likely holds two partitions (the first being the EFI System Partition), and we only want to mount the partition with the backup data. We run parted to find out the start position and size of the HFS data partition.

parted /mnt/sparsebundle/sparsebundle.dmg unit B print

Which returns the following output for my backup:

Model: (file)
Disk /mnt/sparsebundle/sparsebundle.dmg: 3221225472000B
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 20480B 209735679B 209715200B fat32 EFI System Partition boot, esp
2 209735680B 3221091233791B 3220881498112B hfsx disk image

Use the Start position and size as reported by parted for the following:
losetup -f /mnt/sparsebundle/sparsebundle.dmg --offset 209735680 --sizelimit 3220881498112 --show
Which to me returned /dev/loop1, if it returned something else for you make sure you use the correct loop in the below step.
We can mount the offset partition:

mkdir /mnt/iMac
mount -t hfsplus /dev/loop1 /mnt/iMac

You can try to browse through the mounted backup, however you’ll notice that files are likely not accessible because these are stored as hardlinks and these are not supported on hfsprogs by default. So the last step is to re-mount the partition using tmfs which will make the hardlinks work.

mkdir /mnt/iMac_backup
tmfs /mnt/iMac /mnt/iMac_backup

Now you should be able to browse through the files at /mnt/iMac_backup without a problem! Note: if you want to browse the files on the Synology user interface, you’ll probably want to mount it on a location that is already available in the file manager.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s