Please note: This guide assumes you are using Snow Leopard. For Lion, things are a little different. I’m writing a new guide with Lion in mind but I haven’t got round to finishing it yet – the short version is: you need Netatalk 2.2 with its Avahi support built-in, and remove any manual Avahi service files you have created.
There are many guides on the Internet that deal with getting Apple’s Time Machine to back up to a network disk, however all of those that I managed to find rely on setting a hidden system preference to show unsupported disks – and hence don’t help with the problem of restoring from backup should the worst happen.
There is a way, though, to get Time Machine backing up to a Linux server without jumping through any hoops on the client. The backup volume just appears in the Time Machine preference pane, and the Mac OS X Install DVD’s restore mode also can see and restore from the network volume.
What you will need
I am basing these instructions on Debian Squeeze and Mac OS X Snow Leopard as that is what I’m running, however it looks like Netatalk 2.1 onwards has the necessary patches to support Time Machine (these implement the
afp_syncfork commands in AFP 3.2).
You have to use AFP for Time Machine to be “supported”. It works with Samba but only in its unsupported configuration, and I ran into many issues when I used Samba – especially with backups becoming corrupted. I can only really recommend the use of Netatalk 2.1 or above for Time Machine.
You will also require
avahi-daemon to be installed and running, as mDNS / Bonjour is required for the volumes to show up in the Time Machine preference pane.
Pull in the required packages:
aptitude install netatalk avahi-daemon
I prefer aptitude due to its dependency handling, but you can easily use apt-get or synaptic or whatever you wish.
Setting up Netatalk
/etc/netatalk/AppleVolumes.default file to export the Time Machine volume. At the end of the file you’ll find a line that reads:
~/Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "Home Directory"
Change this to look a bit like this:
/srv/timemachine Â Â Â Â Â "Time Machine"Â Â Â Â Â Â Â Â options:tm
It’s very important to add the
options:tm at the end of the line so that Netatalk enables various special options for Time Machine. I also recommend dedicating a filesystem entirely to Time Machine (e.g.
/srv/timemachine should be its own mountpoint). Additionally, Apple recommends not to use the volume for anything but Time Machine due to the way locks are used (see TMNIS, below).
Finally, restart Netatalk:
By default Avahi advertises your server’s name as its hostname, which by convention on Linux is all lowercase. If you wish to alter the name of the server as advertised, you can edit
/etc/avahi/avahi-daemon.conf and change the
host-name= line in the
[server] section to whatever you desire. This name will show up in the Finder’s list of Bonjour shared servers in the sidebar. Don’t forget to restart Avahi if you do this.
Next we need to set up an Avahi service file to advertise our Time Machine disk. Create
/etc/avahi/services/afpd.service and paste in:
<?xml version="1.0" standalone='no'?><!--*-nxml-*--> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name replace-wildcards="yes">%h</name> <service> <type>_afpovertcp._tcp</type> <port>548</port> </service> <service> <type>_device-info._tcp</type> <port>0</port> <txt-record>model=Xserve</txt-record> </service> <service> <type>_adisk._tcp</type> <port>9</port> <txt-record>sys=waMA=Â«MAC AddressÂ»,adVF=0x100</txt-record> <txt-record>dk0=adVF=0x83,adVN=Time Machine</txt-record> </service> </service-group>
Note: You must replace Â«MAC AddressÂ» above with your server’s MAC address. You can find this out using
ifconfig eth0 or
ip link list dev eth0. You should also replace whatever volume name you used in
AppleVolumes.default for the
adVN= field if you didn’t use “Time Machine”.
The service definition advertises 3 capabilities: AFP over TCP, which is required for Time Machine and which Netatalk provides, a Device Info virtual service which in this case tells Mac OS X that the device is in fact an Xserve (optional, but gives your server a pretty icon in the Finder) and the all-important AirDisk service with Time Machine flags.
adVF=0x83 field are the AirDisk flags which tell Mac OS X that Time Machine is supported on this volume. If you wish to expose additional volumes, duplicate the
dk0= line but call it
Avahi automatically reloads the contents of the services file each time it changes, so you should not need to restart Avahi for this to take effect.
Setting up Time Machine
The above should be enough for the volume to appear in the Time Machine control panel. However, as my Time Machine backups have evolved over time I don’t know if this is enough to create a new backup from scratch. If this doesn’t work for you please let me know so I can update the instructions as necessary!
HowTo: Make Ubuntu A Perfect Mac File Server And Time Machine Volume – The first guide I followed to set up netatalk. This uses the unsupported method and has some outdated instructions about having to recompile Netatalk.
Time Machine Network Interface Specification (TMNIS) – The official Apple doc on what’s required for Time Machine to work.
Time Machine / Time Capsule Success! (no afp_fsyncfork yet) – A thread on
netatalk-devel describing how to set up Time Machine with the mDNS configuration.
Time Machine on the FreeNAS forum. This discusses various combinations of the
adVF parameter on the
sys= line that I had to adjust.