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

I keep getting 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

anything wrong with my command below?

sudo hdiutil create -size 300g -type SPARSEBUNDLE -nospotlight -volname "Backup of My Name MacBook Pro" -fs "Case-sensitive Journaled HFS+" -verbose ~/Desktop/My Name MacBook Pro_109afd48dfe4.sparsebundle

I will be using a Seagate GoFlex

Thanks

May 14, 2011 | Unregistered Commenteresoteric

Hi Phil,

Just wondering if this will work with iDisk or if you know if you can get Time Capsule to backup over an internet connection?

Thanks

May 18, 2011 | Unregistered CommenterMark

Phil, THANK YOU for this wonderful post. Helped me out tremendously and saved me a bunch of time.

Karl
Austin, TX

May 19, 2011 | Unregistered CommenterKarl

Problem always coming back.
I am suffering here, time machine setup like proposed worked and I was happy. But after around 1 month the old bad message is showing up again (...tatata.... error code 45).
If i repeat the whole process again like described above everything will work fine again... till the next time.
At first i thought it might be the change of IP addresses ... due to DHCP protocol, so I gave iMac, router and my NAS a static one. Same result.
I am using iMac, linksys router and the NMH410 with 1GB hardrive (acutally 2 HD raid system).
Why is this on and off all the time? The permanent redoing really sucks...

Any suggestions?

Deperate Dan

May 22, 2011 | Unregistered CommenterDaniel

@Daniel I'm afraid I can't explain the issue you're seeing. I doubt the IP address is relevant - it uses the mac address of your first Ethernet port but other than that it should use dns names. When you re-create the disk image does it have exactly the same name? If so it has probably become corrupted (see if you can open it manuall). If not then there may be an issue with your Ethernet port.

May 23, 2011 | Registered CommenterPhil Nash

@Mark While I'm sure you can get TM working over the internet if you try hard enough I think a more dedicated solution is a better bet.
I can recommend Livedrive (disclaimer: I used to work there) - which has Dropbox-like cloud sync, with unlimited storage - and a dedicated scheduled backup solution too.
The downside is that the Mac client is still in beta (it works well enough tho) and doesn't quite have a native Mac feel to it (it's a Mono app).
There are other, similar, services - including many dedicated to back-up (mostly as a front-end to Amazon S3 storage).

May 23, 2011 | Registered CommenterPhil Nash

@esoteric: looks like you haven't quoted the last mention of the backup filename. ie:

"~/Desktop/My Name MacBook Pro_109afd48dfe4.sparsebundle"

May 23, 2011 | Registered CommenterPhil Nash

Thanks Phil and Rahil, solved this problem for me

May 26, 2011 | Unregistered CommenterGraeme

Hi, thank you for posting this, I am glad to finally find something that seems to work for people. Unfortunately I get:
sed: 1: "s/://g34159e1fb222": more than one number 'g' in substitute flags

I get this when I attempt to find the MAC address. Any ideas?

Thank you,

Ali

June 3, 2011 | Unregistered CommenterAli

I'm having continual problems getting this solution to work with OS X Lion and Windows Home Server. The error I keep getting (after successfully creating the sparsebundle and copying it to the share on my WHS) is that the volume selected for Time Machine doesn't support AFP. I have Mac File Sharing on the WHS and have a Time Machine on OS X 10.6 working wonderfully. Any ideas?

Thanks,

Jason

June 5, 2011 | Unregistered CommenterJason Thibeault

Fantastically useful post. Just bought a 1TB iomega network drive at a bargain price, and after following your instructions, time machine worked like a charm.

June 11, 2011 | Unregistered Commentermike wooldridge

Hi

Does this work with OS X. I am following the instructions to the T but with no luck. Pls help, going a bit mad here....

Last login: Sat Jun 11 21:14:30 on ttys000
You have mail.
Greg-Hopkinss-MacBook:~ Greg$ defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1
Greg-Hopkinss-MacBook:~ Greg$ ifconfig en0 | grep ether | awk '{print $2}' | sed 's/://g'
e80688f39d2c
Greg-Hopkinss-MacBook:~ Greg$ sudo hdiutil create -size 950g -type SPARSEBUNDLE -nospotlight -volname "Backup of <Greg_Hopkins's_MacBook>" -fs "Case-sensitive Journaled HFS+" -verbose ~/Desktop/<Greg_Hopkins's_MacBook>_<e80688f39d2c>.sparsebundle
>

June 11, 2011 | Unregistered CommenterGreg

I had time machine working up until about a week ago, backing up to my HP EX495 backup server. Then it stopped working and I started getting the error "Time Machine could not complete the backup.
The backup disk image "/Volumes/Mac-3/Prada.sparsebundle" could not be created (error 45)." I found this page on the Internet and tried it, and it works. But Time Machine is not just backing up the files that have changed in the past week. It's backing up all 394 GB, and it appears that it will take about 15 hours. I don't want to lose all of my old Time Machine backups. How can I start where I left off?

June 14, 2011 | Unregistered CommenterHarry

Never mind, I figured it out. the HP EX495 does it a different way, and doesn't use the sparsebundle file. I just had to go into preferences (for HP MediaSmart Server), stop backup, go to preference (Time Machine), reselect the backup disk, go back to preference (HP MediaSmart Server), and turn backup back on. The error message fooled me!

June 14, 2011 | Unregistered CommenterHarry

@ Greg Take out the <> surrounding your computers name and mac address

I am having a problem of my own. After creating the sparsebundle and saving it to my TM backup I get a new error.

Time Machine could not complete the backup.
The backup disk image "\Volumes\TMBackup-1\Computername.sparsebundle" could not be accessed (error 109)

June 16, 2011 | Unregistered CommenterBen

I tried this, but I get an error:

Time Machine could not complete the backup.

The backup disk image "/Volumes/GoFlex Home Personal-12/Ben Harper's Macbook Pro_001b63a9d9ff.sparsebundle" could not be accessed (error -1).

###

Each time I try the number after "Personal-" increases by three. First there was no hyphen and number, then it was "-3" then "-6" then "-9" then "-12"

This was my command:

sudo hdiutil create -size 999g -type SPARSEBUNDLE -nospotlight -volname "Backup of Ben Harper's MacBook Pro" -fs "Case-sensitive Journaled HFS+" -verbose "/Users/tomcares/Desktop/Ben Harper's MacBook Pro_001b63a9d9ff.sparsebundle"

June 17, 2011 | Unregistered CommenterBen

(I'm the Ben who posted on 6/17, not the one who posted on 6/16)

It's working great for me now, and I'm very grateful.

I originally skipped the first step (defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1) and used a program called itimemachine instead, which I thought did the same thing. I started over from scratch though - deleting the sparsebundles and everything - and doing exactly by your instructions (the command to create the sparsebundle didn't change) and it worked.

Thanks a lot.

June 18, 2011 | Unregistered CommenterBen

Phil,

Just wanted to thank you very much for that! People like you helping the rest of us out are lifesavers!

June 22, 2011 | Unregistered CommenterWilliam

Thanks so much for this post. I used it to with success on an Iomega Home Media drive. The only convenience I would add is using Disk Utility to create the sparsebundle. Nice description of this on the Iomega support site:

https://iomega-eu-en.custhelp.com/app/answers/detail/a_id/24273/kw/manual

June 27, 2011 | Unregistered CommenterAndy J.

Thank you very much. Very useful for me.

June 28, 2011 | Unregistered CommenterJuan Luis

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>