Setup Time Machine on FreeNAS

September 5, 2009

NAS - Time Machine on NAS

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:

ether 00:26:4a:00:25:c8

In my case, the sparsebundle name is:

jb15uni_00264a0025c8.sparsebundle

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.

Related posts

  • http://www.facebook.com/people/Steve-Wasko/586423060 Steve Wasko

    Jonathan,

    Great series of posts and pretty inspiring! Would love to implement similar for home purposes here. I had a couple of questions from the series:

    1. Time Machine – have you used the method described to do both TM backups and restores? I agree that not having bare metal restore isn't that big of a deal – just wondering how it's been working over the last month for you.
    1a. Does this also work well with Snow Leopard (10.6)?

    2. IO Graphs – In looking at the 4 graphs in Part 5 of your series, it's hard to determine just how much performance you're seeing. The first chart seems to indicate write speed to the NAS of around 37MB/s, with Graph 2 showing around 17-18MB/s on both reads and writes. The last summary table shows data values for each individual drive that are around 6-6.5MB/s. What are you seeing as average speed for large writes? What protocol (SMB/CIFS or AFP?) *

    For me, writes will likely be much more frequent than reads and I'd love to understand, in real world use (copying ISO images, doing TM backup, copying large media files to the NAS, etc.) what sort of write performance you are seeing.

    * In question 2, I was dividing Mbps by 8 to get a sense for what the MB/s of data written would look like, similar to what chart 4 shows.

  • http://jonathanbrown.me Jonathan Brown

    Steve, thank you!

    1. I've been doing the TM backups using this method for over a month now. I've not tried a full restore, but I have tested single file restores and it works perfectly. You'd think it would take significant amount of time to bring up TM considering it needs to mount the drive and all, but it only takes about 6 seconds before the TM interface is ready.
    1a. Yes, I'm running Snow Leopard without changes (my original setup was under 10.5) and it works just fine.

    2. To be honest, I do not really have a handle on the I/O performance yet. I am getting about 37MB/sec on a wired 1Gbit network using SMB/CIFS (WinXP/Mac to NAS). That graph was from a large 12GB file copy with my MacBook Pro wired to router, but I'm seeing same performance from a WinXP box wired. I susepect my LinkSys WRT310N router is a bottleneck, but I've not proved it. I've had poor N performance on this router as well. I've tweaked the FreeNAS settings and my router config here and there, but I've not stumbled upon the magic combination that dramatically improves the I/O performance.

    I've been a bit busy since this post, and I have on my agenda to document the various tweaks I've made to the NAS. I do think there's a lot more performance to squeeze out of it, but I've just not had the time to figure it out yet.

  • Pete

    Got this working – great guide- I'm in the middle of my first backup now- do you know if its normal for TM to still report the full size of my NAS? Its saying that I have over 2 TB available for backup!! The sparsebundle I created is only 250 gb. Is this something that will fix itself and report correctly after the first backup? Thanks

  • http://jonathanbrown.me Jonathan Brown

    Pete, I noticed that when I first set up TM and it doesn't change after first backup. I figured it was TM assuming the total drive was being used (as normal configuration) and that's why it estimates the entire NAS as available. Remember, this is an unsupported configuration, so it may be just a quirk with TM.

  • jeffismac

    umm, almost made this work but can't find the sparsebundle on the mac to copy to the freenas.

  • http://jonathanbrown.me Jonathan Brown

    If you didn't change the directory when you opened Terminal, it will be in your user folder.

  • jeffismac

    Hi found out that your 2 line instruction to create the sparse is actually a one line command. I have created the sparsebundle (with finder minimised it shows in the folders without the sp at the beginning which is unfortunate!0 Anyway thanks for the help.

    2 questions

    can I use the lan mac not the airport mac in the filename? Even though I will be more likely to be wifi rather than wired.

    and can i delete the sparse from the mac once it's been copied over?

  • http://harryd71.blogspot.com/ harryd71

    Hey great post and I've run a similar for several months without any problems. But with FreeNAS 0.7 this way is a little bit outdated, check my latest howto -> http://harryd71.blogspot.com/2009/11/mac-osx-ti…

  • http://jonathanbrown.me Jonathan Brown

    Thanks for that. I've updated the post with a link to your post. This feature was not available in the 0.7RC I was running, but good to see it.

  • http://jonathanbrown.me Jonathan Brown

    Sorry about the confusion on the command. I've updated the post to note that it is one line. How you connect to your network is irrelevant to the name of the sparsebundle. You can delete the sparsebundle file from your mac once you've copied it to your NAS.

  • Vadim

    Thank you for your guide, I got Time Machine up running on my freenas but not without some hickups.

    My problems started with TM saying how it's unable to write due to permissions. I enabled local user authentication and used a user login with admin privileges.

    I checked the permissions for the sparsebundle and it only had r/w permissions for the ftp user, which I think is guest by default. My approach was to enable permissions for all by logging in as superuser and modifying permissions for the sparsebundle to include everyone. That fixed the issue, however, I'm not comfortable with this approach.

    I made sure that the subdirectories of my afp share had proper permissions, it's only the sparsebundle that had the limitation. Did I go wrong somewhere in my setup, configuration of users maybe?

    Thanks again for your guide.

  • Vadim

    Thank you for your guide, I got Time Machine up running on my freenas but not without some hickups.

    My problems started with TM saying how it's unable to write due to permissions. I enabled local user authentication and used a user login with admin privileges.

    I checked the permissions for the sparsebundle and it only had r/w permissions for the ftp user, which I think is guest by default. My approach was to enable permissions for all by logging in as superuser and modifying permissions for the sparsebundle to include everyone. That fixed the issue, however, I'm not comfortable with this approach.

    I made sure that the subdirectories of my afp share had proper permissions, it's only the sparsebundle that had the limitation. Did I go wrong somewhere in my setup, configuration of users maybe?

    Thanks again for your guide.

  • Tony

    Have you tried to do a full recovery this way (using your freenas share as the source)?

  • mattjuna

    We had to attempt a restore of a Leopard OSX server which proved to be a little tricky, see my post http://www.junasoftware.com/blog/system-restore…, we were backing up a server so the sparse image was about 1.5GB. We ended up copying a few directories off another functional OSX server to get the server functioning again. We did need to add all the users again though.

    It is a hard thing to test unless you have a spare mac lying round. I now use a combination of Time Machine for a on site versioned backup and use rsync to mirror our file directory off site to a data centre. Seems to work well and we have our bases covered.

  • Lawrence Gosset

    Jonathan – I was wondering if you could help me out.

    I've mounted up my FreeNAS drive, linked Time Machine to it, the whole initial test backup ran flawlessly with no error but I just get one huge image file, is this correct?

    You talk about creating a custom sparsebundle file with MAC address and then using that. I tried this method but the sparsebundle did not link and it just created another one, but I'd quite like to get this method working so I can limit the backup size.

    Also when I run a backup another volume mounts called “Time Machine Backups” but once the backup is done this disappears. This means I cannot access the files unless the backup is running or if I mount the huge sparsebundle image.

    Have I done anything wrong/right – I'm mainly concerned with limiting my sparsebundle size to be honest!

    Appreciate any help,
    Lawrence

  • http://harryd71.blogspot.com harryd71

Previous post:

Next post: