Backup, Sync and Share – Part 4: Apple Time Machine and Samba

 | June 9, 2009 9:58 pm

Mac OS X - Leopard - Disc At it’s World Wide Developer’s conference in June of 2006, Apple released a product that changed the way that a great many people think about backup: Time Machine.  While I cringe at the thought, I need to descend into the fawning adoration public relations speak that masquerades as critical coverage of Apple Products.  (Actually, forget that, here’s how Apple describes their backup system.)

Time machine is a breakthrough automatic backup that’s built right into Mac OS X.  It keeps an up-to-date copy of everything on your Mac – digital photos, music, movies, TV shows, and documents.  Now, if you ever have the need, you can easily go back in time to recover anything … Time Machine takes care of it … Automatically, in the the background.  You’ll never have to worry about backing up again.

General sarcasm and bitterness aside, Time Machine really is a spectacular piece of kit.  Sure, you can very successfully imitate a Time Machine experience using the tools within Windows Vista or Linux (or via third party tools such as Norton Ghost).  Even so, Time Machine is just just about the perfect combination of simple, powerful, and integrated.  And like most Apple products, when used within the Apple eco-system is  a lovely experience.

However, if you migrate too far out of the walled garden, Time Machine isn’t quite so nice to work with.  Actually, it can be a bit demanding and temperamental.  For example, it requires its own formatted hard drive or the ready availability of a specialized Apple router (called a TimeCapsule).  Alternatively, it can be a bit flaky; when I was backing up to a local hard drive, it would often quit with an indecipherable error.   Luckily, however, these limitations are pretty easy to overcome.  In this article, I will look briefly at how to setup Time Machine so that it works with a simple home server running Samba and Subversion.

A Few Goals

Before jumping into how to change settings, it might be good to talk about why I’ve chosen the configuration options I have: it’s all about simplicity and convenience.  As Apple (redundantly) points out, the more simple a task is, the more likely it is to happen.  In terms of backup, this means that it should be automated.  So, while having a disk connected to a computer is sufficient, backup over the network to a network attached storage (NAS) is much better.  "Why," you ask?  In the case of NAS, there is no worry about turning the dedicated backup disc on, letting Time Machine do its thing, and then shutting the disk off.

There is, however, one major drawback to backing up over the network.  That first backup-up takes a REALLY long time.  In my case, it took my MacBook Pro the better part of three straight days to finish.  And should you ever need to restore your complete hard drive (due to failure or the purchase of a new computer), you can expect it to take the same amount of time.  Once that first backup completes, however, this limitation no longer exists.  Subsequent runs only include files that have been modified and go quite quickly.

But what about convenience?  The point of a backup is knowing that your work/information is safe.  For single files, restoring over the network is easy.  But what happens should disaster strike and you lose a hard drive?  No one wants to wait three full days before resuming work.  Luckily, you can get the benefits of over the network back-up and the convenience of quick recovery by configuring your home back-up server to use USB hard-drives.

Apple Time Machine

Should your hard-drive fail, you can detach the USB drive and then use TimeMachine to restore your data locally.  I discovered this lovely side benefit recently when the hard-drive in my MacBook Pro decided to die and I refused to wait three days for it to restore over the network.  I disconnected the network drive from the server and plugged it into the Mac.  I then booted from the recovery CD and it magically found my Time Machine backup.  Instead of three days, I was ready to go in slightly less than three hours.  So, now that we have the goals (simplicity and convenience), let’s talk about how to reach them.

Network Backup to Samba

Out of the box, a default Leopard installation won’t work with a Samba share.  You will need to follow a relatively simple three step procedure to have Samba supported Time Machine goodness:  1) Create a sparse bundle image on the local file system, 2) copy the sparsebundle to the root of the network share, 3) enable support for “unsupported” network volumes.

1) Create a Spase Bundle Image on the Local File System

Time machine saves backups in an extremely specific format, called a sparse bundle or image.  A sparse bundle is a special file that can also behave like a physical hard drive.  When you click on it, it will launch a new volume in the finder that then contains other files and folders.  A unique characteristic of the sparse bundles included in Leopard is that they will automatically resize based on their contents.

When using Time Machine on Apple hardware, the process of creating a sparse bundle is automated.  Unfortunately, this isn’t true on a generic Samba share.  In order to make Time Machine work, we need to manually create a sparse bundle and copy it to the Samba share where we will be backing the computer up.

As we create our image, the file name of the image is extremely important.  It has a general form of:


Where Computername is the name of your computer and MACaddress is the MAC address for your ethernet card.  Luckily, both of these pieces of information are relatively easy to find.  The computer’s name is found by opening “System Preferences” and clicking on the “Sharing” link under “Internet and Network.”

Find you computer's name by clicking on the "Sharing" pane of the System Preferences.

Your computer's name can't have any spaces or other forbidden characters.

For the Time Machine backup to work correctly, it is important that your computer’s name not have any spaces in it.  Should you need to, this might be a good time to change it by clicking on the “Edit” button.

You can locate the MAC address by typing the following command into the Terminal:

ifconfig en0 | grep ether | sed s/://g | sed s/ether//

It will return a list of letters and numbers, for example: 001ec4b8f9b3.

Make note as this information is important in the next step.  After you have edited your computer’s name (without symbols or spaces) and have your MAC address, you are ready to create the sparse bundle on your local computer.  We will later copy it to the correct place on the NAS hard drive.  To do, open the terminal and type the following:

sudo hdiutil create –size 250g –type SPARSEBUNDLE –nospotlight –volname “Backup of My Mac” –fs “HFS+J” –verbose ./Computername_MACaddress.sparsebundle

Be sure to replace everything in red with information that is pertinent to your computer (In my case, Computername_MACaddress is RobOakes-Mac_001ec4b8f9b3.sparsebundle).  In this example, I have limited the size of the sparse bundle to 250g (through the –size flag).  If you omit the "-size" flag, the sparse bundle will expand until it fills the entire available space of the drive.

Update (2009 07-02): The file system (fs) command line option above was changed from "Case Sensitive Journaled HFS+" to "HFS+J".

2) Copy the Sparse Bundle to the Appropriate Location

After you finish creating the sparse bundle, it needs to be copied to the root of the Samba share which you will be using for your backups.  This can be done from the finder or from the command line.  In my case, I keep my Time Machine backups on a Samba share called PC-Backup.

Update (2009 07-02): The first comment below explains how to copy the sparsebundle image using the command line.

3) Configure Time Machine to Support Samba Network Volumes

To enable Samba shares in Time Machine, type the following into the terminal:

defaults write TMShowUnsupportedNetworkVolumes 1

Time Machine-Unsupported Network Volumes

Select "Change Disk" from the Time Machine configuration pane under "System Preferences." After you have changed this setting, you may need to restart the computer for it to take effect.  (Alternatively, you can also log-out and then log back in.)  At this point, everything is set-up for Time Machine to use your Samba share for back-ups.

Since Samba does not use Apple’s zero configuration network protocol (known as Bonjour), you will need to help Mac OS X find your backup-up volume the first time you use it.  This can be done a variety of ways, you can either manually mount the volume by using the command line, or by navigating to the disk with the finder.  (To check if the disk has been mounted, open up a finder window and see if a small eject icon appears next to the computer which hosts the share.  Alternatively you can navigate to the /Volumes/ folder, where you will also see a list of currently mounted remote shares.)

Next, open the Time Machine configuration from the System Preferences and press the “Change Disk” button.  This will give you a list of all the disks and samba shares that are currently available to OS X.  Select which disk that you you would like to use and press the “Use for Backup” button.  Since I placed my sparse bundle in the root of PC-Backup, that is the volume that I should select.

Time Machine - Available Volumes

Time Machine will begin a full back-up that can be accessed either over the network, or by manually plugging the hard drive into your Mac.

Similar Posts:

12 Responses to “Backup, Sync and Share – Part 4: Apple Time Machine and Samba”

Mike Andrews wrote a comment on July 3, 2009

Thanks for this! It worked awesomely for me on Leopard, with the following two minor changes:

1. The filesystem type needs to be "HFS+J", not "Case Sensitive Journaled HFS+".
2. I specified an extension of ".sparsebundle" to the hdiutil command line.
3. I used "cp -rp Computername_MACaddress.sparsebundle /Volumes/backup/. to copy the bundle. I wasn't sure if preserving attributes is important. (my backup share is simply called "backup")

With changes 1 and 2, your hdiutil cmdline became:

sudo hdiutil create –size 250g –type SPARSEBUNDLE –nospotlight –volname “Backup of My Mac” –fs “HFS+J” –verbose ./Computername_MACaddress.sparsebundle

Thanks Rob! This was a giant help!

Rob Oakes wrote a comment on July 3, 2009

Hi Mike, I originally put it together for my own reference from a bunch of other posts/forum comments around the internet. I'm glad that it worked for you as well.

Also, thanks for the feedback. The addition of .sparsebundle to the image name is extremely important (and represents a typo on my part). I've updated the post above with your recommendations.

[...] this is why Time Machine (a backup program for Mac OS X) is the standard against which all other backup solutions are [...]

Robert Carlisle wrote a comment on August 1, 2009

I have been doing this for some time now. Now that I have a need to perform a full restore from the backup I keep on an SMB volume, there does not seem to be a way to restore directly from the Time Machine backup.

If I start from the installation DVD and go to the terminal to mount my smb share containing the backup (mount -t smbfs //user@server/sharepoint /Volumes/sharemount) I get an error: "Failed to load smb library: Unknown Error 1102." This error does not occur when started from a full 10.5 installation. I can find no information regarding a workaround at this time.

While it is possible to restore files from the backup to a live 10.5 system, it is not (apparently) possible to fully restore the system using the Restore System from Backup on the install DVD.

If any one has tried and succeeded in a full restore from a remote smb volume, I would like to know how you managed it.

Rob Oakes wrote a comment on August 1, 2009

Hi Robert,

I haven't tried restoring directly over the network from the smb store (smbfs, the module used to mount the remote system is a little finicky). I had a copule of ideas though. Can you try and mount the system over ssh? I haven't used it on Mac, but sshfs on Linux is much more stable than smbfs.

A secondary thought, I use two external USB drives for the data stores on my server. In the case of failure on my Mac (happened after a Boot Camp misadventure), I can unplug the USB drive from the server and plug it in directly to the Mac. This is a bit of a cheat (because you aren't restoring directly over samba), it did work spectacularly. The boot CD found the time machine archive immediately and I was able to get back to work. This has the added benefit of being much, much faster than an over the network restore. (You might also just copy your time machine backup to external drive, it will accomplish the same thing and will be faster than a network restore.)

After I was up and running, I plugged the USB drive back into the server and was able to pick right up where I'd left off.

Last thought, if your server runs Linux, you could try and get lib-avahi up and running. This will enable afp for the server and might use that to restore. I wish you the best of luck. Personally, I think your best option is to copy the image to external USB and use that. It's worked for me twice and the whole process takes only a few hours.



[...] back of my head when I set it all up but I figured someone had it figured out, otherwise why would so many articles exist to show you how to set it [...]

David Goodger wrote a comment on August 19, 2009

Thanks for the info! It sounds like part of a great backup solution.

A couple of questions:

What OS does your server run?

What disk format do you use for the server-attached external hard drives?

Rob Oakes wrote a comment on August 19, 2009

@David: I've been really happy with it. Right now, the server runs Ubuntu server (currently version 8.04, the long term support edition). A couple of months ago, I tested 8.04, 8.10 and 9.04 (each for a week or so) to see if I was ready to upgrade to a newer version of Ubuntu.

I found out that the answer is, "Not yet." Mac OS X doesn't seem to play nicely with newer versions of Samba, I'm hoping that this will change in the coming weeks as Snow Leopard is released.

Initially, I set up the drives to use NTFS so that I could quickly unplug the disks and make use of them on a Windows machine. In the past year or so that the server has been running, though, I've done this a grand total of 0 times. I did, however, have to unplug the drive to restore my Mac when the hard drive decided to fail. As a result, I've reformatted the backup drive to HFS+.

Linux can read/write to essentially everything. And since I only access that drive through the server, I'm not concerned about directly plugging it in to a Windows machine any longer. Thus, at any point in the future should I need to directly restore via time machine, I can simply plug it into the Mac and continue about my business.

The second hard drive I have plugged in (which is used as a public file store) is formatted in NTFS.

Apolitically Incorrect » Glass Houses and Stones sent a pingback on October 6, 2009

[...] Want to use Time Machine to back up to a network storage unit different than their ticking time bomb?  Sorry, you can’t do that.  “It’s not supported.” [...]

[...] [...]