« 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)

Comfort Comment:

I recently had difficulty getting Time Machine to backup to a WD 2 TB network drive. During the process of resolving the issue, (which was done successfully thanks to this site), I read some comments about the reliability of the backups. FEAR NOT! . . . Shortly after I got everything working, I installed some new software and in the process lost a very large "Documents" folder. I had to "restore" using my backup file. Everything worked without a hitch and I had no trouble with the backup or Time Machine.

Again, my thanks to this site and all those who took the time to post comments here.

November 14, 2010 | Unregistered CommenterChuck

Great article! I have spaces in my computer name so had to make that change (putting in quotes) as well as changing the directory path a little but it's backing up right now (may take all day!)

May the force be with you.

-Spencer

November 21, 2010 | Unregistered CommenterSpencer

Thank you Phil. The iTimeMachine fix works really well. Creating the sparsebundle was not straight forward but with reading the other comments I got to work.

Thanks again.

November 24, 2010 | Unregistered CommenterPaven

Very many thanks for this - worked exactly as you instructed. Very much appreciated!

Cheers,

Billy

November 25, 2010 | Unregistered CommenterBilly

This Worked great, it looks hard but was really easy, nice one mate, a real life saver *****

December 5, 2010 | Unregistered CommenterRonnan Dex

Excellent post, used this on my DNS-323 and works perfectly. You just saved me a lot of money, thanks man.

December 22, 2010 | Unregistered CommenterChris Bartkoski

Good article.like it very much,thank you.

December 29, 2010 | Unregistered Commentersupra shoes

Phil, you have saved me so much time and grief!! Thanks muchly for the helpful article!

December 29, 2010 | Unregistered CommenterFiona

Hi, i've been racking my brains out trying to get this to work with my iomega network drive. I get to the stage where I enter my password, hit enter then it comes up with some writing but nothing appears on my desktop Here is what it all says


> sudo hdiutil create -size 2000g -type SPARSEBUNDLE -nospotlight -volname "Backup of Kyriacos Demetriou's Mac Pro" -fs "Case-sensitive Journaled HFS+" -verbose ~/Desktop/Kyriacos Demetriou's Mac Pro_0017f20b06bc.sparsebundle
Password:
hdiutil: create: Only one image can be created at a time.
hdiutil: create: returning 0
Usage: hdiutil create <sizespec> [options]
hdiutil create -help
unknown-00-17-f2-0b-06-bc:~ Kyriacos$

January 3, 2011 | Unregistered CommenterKyriacos

U da man. So many other articles did not work. I am running OSX 10.6.5 and backing up to a Iomega Storcenter iX2. Your tips worked like a charm. I spent 2 hours before finding this blog. Took me 2 minutes after reading your post. I owe ya a pint. Cheers.

January 3, 2011 | Unregistered CommenterJeff

@Kyriacos - did you miss quotes around the path at the end (it has spaces in it"?

January 3, 2011 | Registered CommenterPhil Nash

@Phil Nash - Thanks sooo much! It worked, just need to do it on another 4 macs, HA! Nice one, thanks for the fix and for getting back to me.

January 3, 2011 | Unregistered CommenterKyriacos

Thank you! I used Rahil's sudo command (2/13/10) since I also had spaces in my computer name and it worked.

January 10, 2011 | Unregistered CommenterMatt

In reply to Phil's response... What are console logs? I'm new at this.
Also worth noting, that to get past this issue whenever it pops up again, I go through this process again (make a new sparsebundle, drag it in) and it works fine.. for a while. Maybe a few days, sometimes a few weeks. Eventually I end up with the same error 45 message :( One time, the sparsebundle was completely gone after a few weeks, it disappeared. Another time, the file name had a ".tmp" in it - it changed on it's own. Weird.

January 14, 2011 | Unregistered CommenterJB

@JB:
/Applications/Utilities/Console.app
A bit worrying if it's actually removing the image file!

January 14, 2011 | Registered CommenterPhil Nash

thank you SO much. i had been banging my head against the wall trying to get my network drive set up with time machine. rock on!

January 15, 2011 | Unregistered Commenterjules

@Phil
Ok... It only goes back a certain amount of time, the last failure in the log has something a little fishy, not sure what to make of it.
It has an error 256 when looking up immutability for /Volumes/Satan/JB's imac <mac address>.sparseundle/token
This is weird because the computer in question's name is "Satan", but should not be connected to JB's imac? although this imac and other computers are on the same disk. (note, I didn't put the actual mac address in this post but it was in the log). Maybe it's supposed to be like this, I don't know.

Then it creates a disk image under the right name, exits with exit code 255. Five minutes later, it tries intializing the journal. Then there is an error 45 creating backup disk image. Finally, a couple of seconds later it reports a backup failed with error 20.

Any ideas?

January 17, 2011 | Unregistered CommenterJB

you. are. the. freaking. best.

January 24, 2011 | Unregistered CommenterJohn

Phil thank you very much for your work. I get prompted for the password and type it in but nothing happens (I press the keys but nothing gets entered). I press enter and it says wrong password. 3 attempts and I am out.
Have I done something wrong? I even created the user "superuser" and the password on the network drive.

sudo hdiutil create -size 200g -type SPARSEBUNDLE -nospotlight -volname "Backup of Janis McAloon's MacBook Pro" -fs "Case-sensitive Journaled HFS+" -verbose "/Users/jmcaloon/Desktop/Janis McAloon's MacBook Pro_58b035f366f7".sparsebundle

Hope you can help, sorry to be a bother.

January 25, 2011 | Unregistered CommenterJanis

I spent a few days unsuccessfully trying to get this to work. I finally got it working today after switching my ubuntu server from NFS to AFP and manually setting up the sparse bundle.
Instructions for setting up AFP on Ubuntu
I also had to add ",tm" to the options part of the configuration line of /etc/netatalk/AppleVolumes.default to enable time machine backups (source)
The Netatalk package install properly until I added the line "- -ipaddr your.ip.address.here" to a configuration file per these instructions.

Time machine still had trouble making its own disk image, so I had to create it manually following the naming conventions described at the top of this article. My mac didn't have enough free space on the drive to make a large enough image for the backup, so I made a small version, moved it to the network drive, resized it with Disk Utility, mounted it, and repartitioned it to use all of the new space.

Macs really need to have better integration with standard *nix services.

February 7, 2011 | Unregistered CommenterJosiah Johnston

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>