« Stackoverflow DevDays London | Main | Code formatting in C++ Part Two »
Saturday
Oct102009

Using a networked drive for Time Machine backups (on a Mac)

You'll find similar information to this around the web, but I find it fiddly enough to piece together reliably, and I need it often enough, that I thought I'd blog about it. That way it at least gives me a single place to look. Maybe it will help others too. Much of the specifcs, especially the hdiutil command line and the ifconfig trick, I sourced from this thread in the ReadyNAS forums. Note that the advice is by no means specific to ReadyNAS drives (I have a Thecus NAS myself). Many thanks to btaroli in that thread for the insight.

Time Machine

Time Machine is Apple's easy-to-use backup system, baked into OS X (as of Leopard). Unfortunately it doesn't allow you to back-up to a networked drive out of the box. Enabling this ability is pretty easy. Early on there were some reliability issues - which were largely due to the fact that Time Machine created a disk image (more specifically, a sparse bundle) on the network drive, and this was prone to corruption if the network connection was disrupted during a backup. I don't know if all the issues here have been entirely resolved now, but it does seem more reliable. Apple's own Time Capsule, which has been specifically designed to work with Time Machine, uses this same method, so it is no longer an entirely unsupported technique.

Enabling Time Machine for network drives

So how do you enable backing up to network drives? Open a terminal window and paste the following in (then hit return, of course):
defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1
Mounted network drives will then show up in the list of destinations available for storing backups.

Getting a working disk image

Unfortunately this is not always enough. Often, after doing this, Time Machine will appear to start preparing a backup then fail with a cryptic error code. The error I have seen is:
Time Machine could not complete the backup.
The backup disk image "/Volumes/backups-1/Wall-E.sparsebundle" could not be created (error 45).
"Error 45"? What's that. If I try to create a sparse image myself in the same location I'm told, "the operation could not be completed". This is not much more helpful. If you google there are many references around to these errors - mostly in forums. Many of them are not terrible helpful, or require a lot of knowledge and/ or patience. I still don't really know what the problem is, although I suspect it's something to do with permissions and/ or attributes. Either way the solution generally seems to be to create the sparse image manually using a command called hdiutil. If you get this right then Time Machine will think it created it and just start using it. Simple eh? Well, it's not rocket science - but it does involve piecing a few things together. The name of the sparse bundle has to be something very specific which is made up from a few pieces of information unique to your set-up. I'll now take you through how to find those pieces of information.

Finding the Computer Name

We'll start with the easy one. The computer name. Specifically this is whatever the computer is named in the Sharing preferences. So open System Preferences, select "Sharing", and copy the name from the "Computer Name" section at the top.

Finding the MAC Address

This is the physical address of your network card (not your IP address, which is a logical address. Also the term "MAC" here is nothing to do with your Mac as a computer - it stands for Media Access Control address). Now you have to be careful here. Most macs these days have at least two network cards! You will probably have an ethernet port (for a network cable connection) as well as wifi. You may also have a USB based device, such as a mobile broadband device. Regardless of which one you use to connect to the network drive you'll be backing up to, the address we need is of the first network card (usually the ethernet port). If this seems a bit odd at first, consider the case where you usually connect over wifi, but to do an initial backup you connect by cable. If the backup name was dependant on the network connection used this wouldn't work. The address is only used to identify your computer. Anyway, it turns out there is an easy way to obtain this. Back in the terminal window, type the following:
ifconfig en0 | grep ether | awk '{print $2}' | sed 's/://g'
What's that doing? The short answer is "don't worry, it works". The slightly longer answer is that ifconfig dumps all the information it has about all it's ethernet ports. The first port is called en0, so the command ifconfig en0 dumps information about just that one. The pipe character, |, is the unix instruction for sending the output of one command to the input of the next. So we send the information from en0 to "grep ether", which filters out just the lines that have the word "ether" in them - which in this case happen to be where the MAC addresses are shown. To get that line into the form we need for our filename we pipe it to another command, awk, which just picks out the second part of the string, then finally to sed, which removes the colons. Phew. Like I said, it just works. Trust me.

Creating the sparsebundle

Now we have the information we need to create the name of the sparsebundle. Following is the instruction you need to issue to create it. Replace the <mac address> and <computer name> placeholders with the information we obtained above. You may need to change the size parameter (320g here) if you have a large drive to back up. The disk image doesn't take up that space to start with, but will grow up to the size you specify here, so use it to set an upper limit. Also you will be prompted to enter your admin password (sudo runs the command as SuperUser):
sudo hdiutil create -size 320g -type SPARSEBUNDLE -nospotlight -volname "Backup of <computer_name>" -fs "Case-sensitive Journaled HFS+" -verbose ~/Desktop/<computer_name>_<mac address>.sparsebundle
Note that this will create the sparsebundle on your desktop. Once there you can copy it to the desired location on your network drive (then delete from your desktop). This seems to be more reliable than creating it in place. Once you've done that you can start Time Machine and point it at the drive where the sparsebundle resides and it will find it and start using it. If this still fails, check that the name is exactly right and that you followed all the steps above carefully. Now sit back and relax, knowing that all your hard work is being backed up.

PrintView Printer Friendly Version

EmailEmail Article to Friend

References (1)

References allow you to track sources for this article, as well as articles that were written in response to this article.
  • Response
    Response: Time Machine OS X
    Time Machine OS X

Reader Comments (192)

@MacArthur

You need to make sure you are connecting to your drive as so

cifs://x.x.x.x/folder1/folder2/

Where ever you put the sparse file you will need to connect to server to the same folder. i.e. you can't just use:

cifs://x.x.x.x/folder1/

Hope it helps!

June 11, 2010 | Unregistered CommenterMatt

I have this working on one machine and not working on another. Both are Snow Leopard patched to the latest. On the one where it doesn't work, I just get "The Backup Disk is not available." The spelling of the hostname and MAC address (from en0) are fine. Kind of a head scratcher.

June 14, 2010 | Unregistered CommenterBlaine

Hi there!

I got a other problem that i cant find on the internet.

Easy: im trying to make a backup from our server.
This server is a windows pc that has a folder shared.

My mac has time machine so i wanne make a backup of this nework folder.

How to do?

June 25, 2010 | Unregistered CommenterTaro van Gelderop

Great post. Solved my problem. Thank you

July 11, 2010 | Unregistered CommenterStig

Thanks! Worked like a charm after making the mistake of underestimating the naming convention.

Keep up the good work!

J

July 19, 2010 | Unregistered CommenterJordane

Phil, thats fantastic, and worked a treat.

I was just about to go and buy a direct connected drive rather than my lacie network drive, but your simple guide has solved the problem.

Backup is busy grinding away as we speak.

I would say there is lots of information about this on the web with varying levels of 'geekness' but your post has provided a simple to follow concisely described solution.

Many thanks.

Ryan.

July 24, 2010 | Unregistered CommenterRyan Walker

Phil, As you said, there is a lot of info on the web, yous is clear and simple and it works! BTW, Implementes with iomega home NAS. Thanks!

July 29, 2010 | Unregistered CommenterPato

You're my hero Phil!

July 31, 2010 | Unregistered CommenterMagic V

Excellent write-up. Works like a charm! Thanks a ton!!!!

August 1, 2010 | Unregistered CommenterHelostoma

...wanted to add: Using this for running TimeMachine on two Mac Minis with a D-Link DNS-323.

August 1, 2010 | Unregistered CommenterHelostoma

As with all the others, thanks for the great post. You write instructions for numpties like me really well - ever thought of doing it professionally? I'm serious - you're really good!

August 16, 2010 | Unregistered CommenterColin

Works perfectly for me although I can't get it to work twice ie I want to use TM on a second computer (but the same NAS). I'm guessing my Buffalo NAS is the problem but if someone else has done it then do share!

August 16, 2010 | Unregistered CommenterTim

Thanks all.
@Colin: I *do* write professionally - but only software. Thanks, though.

@Tim. No reason it shouldn't work from multiple computers - I have about five different Macs backing up to my NAS. They should all be using different files (ie follow the same procedure for each of them to get it set up in the first place). What happens when you try?

August 17, 2010 | Registered CommenterPhil Nash

Phil

Thanks for taking the time to write this article so clearly and making it straightfoward. I'm now taking my first iMac backup for a year - long overdue - which works well with the QNAP 209 NAS file server, and feeling like I will sleep at nights again.

I wasn't sure if the command line you gave could cope with apostrophes or spaces in the local machine name so I just renamed my machine without these in System Preferences to avoid the problem

Would be much happier if this workaround weren't required and NAS backup was just built into Leopard though

Keep sharing the good work

David

August 26, 2010 | Unregistered CommenterDavid

Hello! I MUST commend you for this post. It looks like it was written over a year ago and such nice execution that it still works!

Thank you SOOOO much for the help! It worked perfectly, and I'm now happily backing up the hard drive of my computer. I'll be back to visit your blog for sure. Adding to my rss feeds now.

August 29, 2010 | Unregistered CommenterM.Grant

thanks for the guide. i finally got it to work with wireless. here's my setup
- terastation 4TB firmware 1.32
- OSX 10.6.4
- apple airport extreme v7.4.2

took me a few hours and a lot of googling. this guide helped a lot. the important thing that i don't see mentioned is make sure you get the wired network method of time machine to work. to do this, you must use the mac address of your wired network, not your wireless. get time machine to begin to back up. once you see it starting to back up, you can stop it. unmount any mounted drives from the terastation then unplug the cable and enable your wireless. then go back to time machine and do a back up. it should remember your configurations for the wired and use it as wireless... at least that's how i finally got my wireless time machine to work.

September 17, 2010 | Unregistered Commentersherwin

Once i am prompted for the pw, terminal window won't let me type it in..?

September 17, 2010 | Unregistered CommenterJulia

@Julia: you are using sudo which requires a password. so once you invoke the command terminal will display

Password:

just type your password. the cursor/prompt will not move as if it's doesn't know you're typing something. it's normal. once you typed your password, just hit return/enter and it should work

September 17, 2010 | Unregistered Commentersherwin

@Sherwin
Thank you!

September 21, 2010 | Unregistered CommenterJulia

You know you have a successful blog entry when your commenters start helping each other out before you get a chance to respond :-)
Thanks Sherwin - and glad you're all sorted, Julia

September 21, 2010 | Registered CommenterPhil Nash

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>