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

Very interesting blog Phil, I wish I had known about this blog before I bought my Time Capsule a few weeks ago. Perhaps another related article that I would find terribly interesting would be - How to make your TM volume (either networked or TC based) accessible while you are out on the road - away from your local network.

I haven't researched this subject too much or even know if its an absolute no-no BTW.

Shogo

October 30, 2009 | Unregistered CommenterShogoDodo

Thank you so much for this. I've been searching for several days trying to figure out why my Time Machine backups won't work after upgrading to Snow Leopard. I was just about to give up when I ran across your article. It worked like a charm.

November 27, 2009 | Unregistered Commentermac user

Thanks very much for the blog post. I've been going crazy trying to understand why TM would stop with Error 45 when trying to create a disk image on a NAS, and now I know it was because I was using the Wireless (en1) MAC address in the sparsebundle name instead of the Ethernet (en0). (I was using the LG N4B1N nas which has support for TM and creates the sparsebundle itself using the name and MAC entered in its WebUI)

Thanks again.

December 25, 2009 | Unregistered CommenterBoris

Thanks for all the positive feedback, guys - it's nice to know this has helped more than just me me. As it happens I've had to set-up TM with my NAS another three times since writing this post, so it's been really handy for me too :-)

December 30, 2009 | Registered CommenterPhil Nash

Thanks for posting this. Seems like I'm closer than ever, but I get this error:

hdiutil: create: Only one image can be created at a time.
hdiutil: create: returning 0
Usage: hdiutil create <sizespec> [options]
hdiutil create -help


Any ideas would be very much appreciated.

January 11, 2010 | Unregistered CommenterRoman

@Roman I suspect you have spaces in your computer name. If so you'll need to put the last filename in quotes. So if your computer is called My Computer, for example you'd use:

"~/Desktop/<computer_name>_<mac address>.sparsebundle"

HTH

January 11, 2010 | Registered CommenterPhil Nash

Thanks for this post.... but i think im doing something wrong.


Last login: Wed Jan 20 15:30:30 on ttys000
Adam-Smiths-iMac:~ adamsmith$ defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1
Adam-Smiths-iMac:~ adamsmith$ ifconfig en0 | grep ether | awk '{print $2}' | sed 's/://g'
00233292c9c0
Adam-Smiths-iMac:~ adamsmith$ sudo hdiutil create -size 700g -type SPARSEBUNDLE -nospotlight -volname "Backup of <Adam_Smiths_iMac>" -fs "Case-sensitive Journaled HFS+" -verbose "~/Desktop/<Adam_Smiths_iMac>_<00233292c9c0>.sparsebundle"
Password:
Initializing…
Creating…
DIDiskImageCreatorProbe: interface 4, score -1000, CWOUDIFDiskImage
DIDiskImageCreatorProbe: interface 5, score -1000, CRawDiskImage
DIDiskImageCreatorProbe: interface 7, score -1000, CSparseDiskImage
DIDiskImageCreatorProbe: interface 8, score 1000, CSparseBundleDiskImage
DIDiskImageCreatorProbe: interface 9, score -1000, CCFPlugInDiskImage
DIDiskImageCreatorProbe: selecting CSparseBundleDiskImage
DIDiskImageCreateWithCFURL: CSparseBundleDiskImage
CBSDBackingStore::createProbe directory, not a valid image file.
DIBackingStoreCreatorProbe: interface 0, score -1000, CBSDBackingStore
DIBackingStoreCreatorProbe: interface 1, score 1000, CBundleBackingStore
DIBackingStoreCreatorProbe: interface 2, score 0, CRAMBackingStore
DIBackingStoreCreatorProbe: interface 3, score 100, CCarbonBackingStore
DIBackingStoreCreatorProbe: interface 5, score -100, CCURLBackingStore
DIBackingStoreCreatorProbe: selecting CBundleBackingStore
DIBackingStoreCreateWithCFURL: CBundleBackingStore
DIBackingStoreCreateWithCFURL: creator returned 2
DIDiskImageCreateWithCFURL: creator returned 2
Finishing…
DIHLDiskImageCreate() returned 2
hdiutil: create: returning 2
hdiutil: create failed - No such file or directory
Adam-Smiths-iMac:~ adamsmith$

January 20, 2010 | Unregistered CommenterAdam

It would help if i put the right dir.

Adam-Smiths-iMac:~ adamsmith$ sudo hdiutil create -size 700g -type SPARSEBUNDLE -nospotlight -volname "Backup of Adam_Smiths_iMac" -fs "Case-sensitive Journaled HFS+" -verbose "/Users/adamsmith/Desktop/Adam_Smiths_iMac_00233292c9c0.sparsebundle"


Thanks again for this post.

January 20, 2010 | Unregistered CommenterAdam

I have an identical error to Adam -hdiutil: create failed - No such file or directory

I'm trying to backup to QNAP TS-109....

January 20, 2010 | Unregistered CommenterMatt

Phil,

I was getting mad with this issue! My MacBook would back up perfectly on our NAS, while my wife's would not. Completely puzzled by the problem, but also the solutions I found on the Internet. Your post is admirably clear and it worked!
Thanks a lot!

Antoine

January 24, 2010 | Unregistered CommenterAntoine

@Adam - if I read you right you solved your problem, right?

@Matt - again, if I read Adam right, he solved his problem by removing the placeholder from the sparsebundle name - is that the issue you have?

@Antoine - glad it worked out for you - thanks for the feedback.

January 24, 2010 | Registered CommenterPhil Nash

Phil / Adam,
I now have a Time Machine backup!

Thanks guys!

January 25, 2010 | Unregistered CommenterMatt

Thanks. Neatly written, very clear and really helpful.

January 25, 2010 | Unregistered CommenterCesar

Phil,
very well written blog. I am trying to backup my mac wirelessly through my PC network to a 500gb external USB drive. For several minutes TM will say :Making backup disk available….. before saying

The backup disk image “/Volumes/MacArthurPro_001ff359570e.sparsebundle-1/MacArthurPro.sparsebundle’ could not be created (error 45)

Please note the -1 added to the sparsebundle name and I'm not sure what /Volumes/ is refering to, I followed your instructions to the T so I'm stuck as to what my problem is. One other bit of info: the backup drive contains 2x250GB partitions. One backs up the PC the other the Mac. Do I need special instructions when writing to a partitioned disk??
Hope you can help

January 30, 2010 | Unregistered CommenterMacArthur

Great post, Phil. Thanks to you, I'm now backing up to my DNS-323 with Time Machine.

I have spaces in my computer name and I had to use absolute paths, so my command looked like this:

sudo hdiutil create -size 320g -type SPARSEBUNDLE -nospotlight -volname "Backup of Rahil's MacBook Pro" -fs "Case-sensitive Journaled HFS+" -verbose "/Users/rahil/Desktop/Rahil's MacBook Pro_d49a21014d72.sparsebundle"

February 13, 2010 | Unregistered CommenterRahil Sondhi

boom! thanks Phil!

February 16, 2010 | Unregistered CommenterTom

Hey Phil

Dude, thanks for this post. I wish all solutions were as clear and concise as this one. I have a mac mini and a mac book pro. (New to the mac stuff as of about 8 months.... .NET guy moving to the darkside). I have a stand along PC that I use as a file server. I stupidly thought that I need time capsule to make backups or use time machine. Well that wasn't the case and then I thought, well, I can't use time machine on a network drive. I talked with a co-worker and he convinced me to give it a shot on my network drive. After a few days of frustration, I came across this. Worked the very first time I treid it. Thanks a lot man.

I have 2 questions:

1) The volumes I created are 100GB (for the mini) and 280GB (for the mac book pro). As time goes on, will backups extended pass 100GB and 280GB? Or once it approachs that mark, will it start to truncate the older history/backups. I ask because these locations are on a file server and I don't want my hard drive to fill up with backups. If this is the case, I need to put in a dedicated hard drive just for backups.

2) If someone was to steal either the mini or the mac book pro...and I buy a new one....even though the time machine backups reside on a network share, will I still be able to restore/transfer from time machines?

Thanks again

February 18, 2010 | Unregistered CommenterNate

@matt, @cesar, @macarthur, @rahil, @tom - glad you all found his useful.

@Nate:
1) If you followed the command line I gave for creating the disk image then what I said at that point should apply, "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.". That has been my understanding and I've had no experience that suggests otherwise so far. When all that space is used up then TimeMachine will start deleting the oldest historical versions until the whole volume is filled up only with the latest versions. At that point, the next time it attempts a backup it will fail with a message telling you why. I *have* had experience of that.
2) Yes you can either restore a new machine from a backup of another machine, browse the backup set using the Time Machine interface or just open the raw file system in the disk image and copy from there (that's what I usually do). All the historical versions appear as folders so you can easily see what is the latest and what is historical (although they may refer to the same files, of course).

February 18, 2010 | Registered CommenterPhil Nash

Hi Phil,

Great post. Thank-you... I published a guide earlier today on the macintosh forums on how build a time capsule server on Linux. I credited and reference you and this page. If you have an issue with that, please let me know and I will correct.

Thanks
Robb

Hey Phil,

This worked like a charm, thanks man! Such a time saver, wow! I created the image without a hitch and rsync'ed it to my Ubuntu nas and am currently backing up through nfs.

This is the best solution if you've got a macbook sitting in the living room and don't want this ugly usb disk attached all the time...

ps: having nfs working with leopard is absolute bliss, this coming from a 10+ years linux desktop user... but now i'm way OT.

March 23, 2010 | Unregistered CommenterMichiel

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>