Improve Time Machine performance on network drives

For those who use Time Machine backups over a network drive, it’s possible to optimize Time Machine disk image using larger sparsebands with some command line steps.

Time Machine creates a sparse bundle disk image to store backups.
A sparse bundle disk image is a virtual disk consisting of blocks stored on files. The image could be mounded and used like any external disk.

By default, the size of the bands (which are the physical files in which virtual disk data blocks are stored) is 8 MB, so for a backup of 100 GB over 12000 band files are created and modified during subsequent backups.
This can cause performance bottlenecks and slow down your backup time, in particular on network drive.

This guide explains how to simple convert the Time Machine image file in order to use 128 MB band size and therefore improve backup performance.
The protocol used in this guide is AFP (which is the one used by almost all NAS producer), but can be adapted also for other protocols.

The fastest way is to convert the image file during the creation, so during first backup.
In this case, the best way is to:

  • Open Console application
  • Setup Time Machine to backup on your network drive
  • While Time Machine starts first backup, keep looking at the Console window
  • Stop the backup after this line appears:
    com.apple.backupd[*]: Forcing deep traversal on source
  • At this point, the volume is already created and can be converted quickly because will be near empty

The conversion could be done also on a volume already in use, but will temporary duplicate the volume, so verify the available space on the network drive (including user quotas) and be prepared to huge runtime for the conversion.

You must fit the parameters in highlighted lines:

  • <hostname/IP> : Hostname or IP of the server/appliance that hosts the Time Machine share
  • <share_name> : Name of the Time Machine share
  • <share username>  / <share password> : Username and password used on network share by Time Machine
  • <volume name> : Name of the backup volume (instead of the default “Time Machine Backups”)

Commands 10 to 12 are optional, in case you want to rename your Time Machine volume.

sudo -i
BCK_SRV=<hostname/IP>
BCK_DIR=<share_name>
BCK_USR=<share username>
BCK_PWD=<share password>
BCK_VOL="<volume name>"
BCK_BND=`hostname -s`
BCK_BND_TMP=`hostname -s`_tmp
mkdir /Volumes/$BCK_DIR
mount_afp afp://$BCK_USR:$BCK_PWD@$BCK_SRV/$BCK_DIR /Volumes/$BCK_DIR
hdiutil attach /Volumes/$BCK_DIR/$BCK_BND.sparsebundle -mountroot .
diskutil rename Time\ Machine\ Backups "$BCK_VOL"
hdiutil detach Time\ Machine\ Backups
hdiutil convert /Volumes/$BCK_DIR/$BCK_BND.sparsebundle -format UDSB -tgtimagekey sparse-band-size=262144 -o /Volumes/$BCK_DIR/$BCK_BND_TMP.sparsebundle
cp /Volumes/$BCK_DIR/$BCK_BND.sparsebundle/com.apple.TimeMachine.* /Volumes/$BCK_DIR/$BCK_BND_TMP.sparsebundle/
rm -R /Volumes/$BCK_DIR/$BCK_BND.sparsebundle
mv /Volumes/$BCK_DIR/$BCK_BND_TMP.sparsebundle /Volumes/$BCK_DIR/$BCK_BND.sparsebundle
umount /Volumes/$BCK_DIR
exit

For older OS X versions (up to and including OS X 10.9 “Mavericks”), you can directly create the Time Machine volume with the right sparse bundle size, before the first backup.
The trick I’ve used is to name the file as hostname plus mac address of en0 network interface, so Time Machine uses (and renames) it, during first backup.

sudo -i
BCK_SRV=<hostname/IP>
BCK_DIR=<share_name>
BCK_USR=<share username>
BCK_PWD=<share password>
BCK_VOL="<volume name>"
BCK_BND=`hostname -s`
BCK_BND_TMP=`hostname -s`_tmp
mkdir /Volumes/$BCK_DIR
mount_afp afp://$BCK_USR:$BCK_PWD@$BCK_SRV/$BCK_DIR /Volumes/$BCK_DIR
hdiutil create -size 100m -layout GPTSPUD -fs "Journaled HFS+" -volname "$BCK_VOL" -type SPARSEBUNDLE -nospotlight -tgtimagekey sparse-band-size=262144 ./`hostname -s`_`ifconfig en0 | grep ether | sed "s|:||g" | cut -f2 -d' '`.sparsebundle
umount /Volumes/$BCK_DIR
exit

After that, Time Machine will run faster on network drives.
I’ve also experienced less problem of backup volume corruption, but I haven’t made any scientific experiment about this point.


Amazon offers related to this article