Update 11/27/2009 — As HarryD notes in the comments, FreeNAS 0.7 (which was still in RC at time of this writing and did not contain this feature) allows a much easier way to setup Time Machine using AFP. See his post here. I’ve not tested this feature in 0.7 and currently using the approach as follows.
In my overall strategy, Time Machine serves as a point-in-time backup and restore. The use case here is I’m working on a project and realize I accidentally deleted an important file a few days ago. Using Time Machine, I can go back and recover that file. I’ve never attempted to do a full restore from Time Machine, and while I hear it works well, that’s not how I would do it. If I have a catastrophic incident, I will treat it as a refresh point and rebuild my system from a new OS install and then reinstall all of my applications. I find it to be a great way to do a spring cleaning of sorts—re-identifying the important tools in your workflow.
The first step is to carve out some space on the NAS. After a lot of experimentation I determined the best file protocol to handle this was AFP (Apple File Protocol). In FreeNAS, you can enable AFP from the Services->AFP menu. Check the “Enable” box in the upper right of the screen. I entered a server name (thenas-afp, to differentiate from the samba server), checked “Enable local user authentication” and checked “Disable AFP-over-Appletalk to prevent DDP connections”.
I created a directory structure on the NAS to store Time Machine backups (/mnt/NAS01/Backup/Time Machine) and then a directory for my primary MacBook Pro, which is named jb15uni. You can create directories via the File Manager (Advanced->File Manager). Next I created an AFP share so my MacBook could access the NAS. On the Services->AFP Shares tab, I added a new share with a name (TM for jb15uni), a comment and set the path to my jb15uni backup directory. I left the other options as default. I verified the share was working and I was able to write to the share. If you use the File Manager to create directories, you may need to set proper permissions so your local user can write to the NAS. To do this you can SSH into your FreeNAS and run some chown and chmod commands.
By default, Time Machine is not configured to use network shares as a destination for backups. To enable it, you have to turn on a preference to tell Time Machine to show network volumes. To do this, run Terminal and enter the following command:
defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1
I researched quite a few ways to accomplish this next step, which is to create the sparsebundle image that Time Machine usually creates on its own. The problem with the way Time Machine creates sparsebundles is that it will use the maximum available drive space because it’s supposed to be used with an attached drive dedicated to backups. I certainly didn’t want 2.6TB of Time Machine backups on my NAS. Because of how I’m using Time Machine in my backup strategy, I want just enough space to keep a few weeks worth of history. I have a 320GB drive on my MacBook Pro of which about 220GB are used. I wanted Time Machine to only take up a maximum of 500GB for backups.
The best tutorial I found that worked was this one which you should follow to create the sparesebundle. One thing I learned—painfully—is that the way OSX names your computer by default will not work for the sparsebundle name on the NAS. The problem seems to be the apostrophe in the default name (e.g. Jonathan Brown’s MacBook Pro). To change the name of your computer, open Sharing in the System Preferences. Be sure to change the “Computer Name” field as well as click the “Edit” button and change the local hostname. I decided to keep my computer name short and descriptive—less than eight alpha-numeric characters.
Time Machine expects the sparsebundle to be named a particular way—<COMPUTER NAME>_<MAC ADDRESS>.sparsebundle. You can find your MAC address by opening up Terminal and running an ifconfig command. Your MAC address will be listed under the en0 device and will look like this:
In my case, the sparsebundle name is:
The command in Terminal I used to create my sparsebundle was (this is a one line command):
hdiutil create -size 500g -fs HFS+J -volname “Backup of jb15uni” jb15uni_00264a0025c8.sparsebundle
That command creates a sparsebundle file on the Mac computer that will grow to a maximum of 500GB, formated with HFS+Journaling file system. Once Time Machine maxes out that space, it will begin getting rid of the oldest backups to make room for new.
Next, I copied the sparsebundle file to the share I created earlier on the NAS. Initially the file is a few hundred MBs in size. If you are connected to your network wirelessly, I recommend plugging into your network before configuring Time Machine as it will kickoff backup shortly after selecting the disk.
Open the Time Machine preferences in System Preferences, click the “Select Disk” button and choose the new backup share. Time Machine will ask for credentials to the NAS share. Be sure to enter your credentials to FreeNAS, not your Macintosh. Time Machine will start the first backup shortly after selecting the disk. The initial backup will take some time even if on a gigabit network. I let it work while I slept. After the initial backup, Time Machine will kick off hourly.
It’s a good idea to take a look at your files and exclude some directories that are not necessary to backup. In my case I have a few virtual machines that total about 50GB. I exclude those as well as iTunes music as my MacBook Pro contains a subset of music that’s already on my NAS. iMovie events are huge and I’ve got backups of those which I’ll talk about in another post.
That’s pretty much all there is to it. It may sound daunting, but it’s a pretty simple thing to do.