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

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)

Hi I used all this a while ago and every went great and was backing up to NAS dive. Now 6 monthhs later I seemed to have had a problem in that the Backups failed and stuff ( sorry not specific) . However long story short I re-did all the scripts and created a new share on NAS drive. The .sqlite file is got generated ok.

However when I try to either copy or move it to the NAS drive my MAC says "Preparing" and it just sits there "preparing" for hours. Is this right or wrong or how long should i give it.. Have left it for up to 10hours ( overnight " and no change

August 16, 2011 | Unregistered CommenterDerek

One key thing when you copy the .sparsebundle fil to the NAS - it needs to go in the root of the disk you select in the Time Machine dialog window.

I tried putting in a deeper hierarchy and got the infamous Error 45.

August 20, 2011 | Unregistered Commenterjc

My problem appears to have been solved by following a tip found elsewhere....

Basically the advice is... Even if you are backing up over wireless, you need to use the ethernet (not airport) MAC address for the target MAC address.

Hope that helps someone else.

Thanks for the info and scripts -- they were the light at the end of a ton of frustration!

August 22, 2011 | Unregistered Commenterde bits

Hi This worked great on three of my various Mac books.

However I have hit a problem on one Mac book Pro. The scripts and every thing run fine. I have connected the macbook via Network cable for the initial backup (indicates about 100G) . It kicks off but stops when it gets to about 1.22Gb.

No error messages or any thing the back up just appears to stop doing anything and hangs I have repeated this several times and the same thing around the 1.2Gb point. I have allocated 400Gb of a dedicated Share for it on the NAS drive

August 26, 2011 | Unregistered Commenterderek

Great post! Thanks!

August 28, 2011 | Unregistered CommenterJohannes

Finally my backup problems are solved. I have been looking for hours in several forums without any luck. I only think Apple needs to put more effort in using something besides Time Capsule these days. It's very hard to find this kind of information.

Thxs a lot!

August 30, 2011 | Unregistered CommenterJeroen

I have been looking for this solution for quite a while now. No one has described it as concise or efficiently as you have. Thanks a million. Now I can back up my daughter's laptop that she uses for her school work without having to fear of, "the dog ate it," scenario. Best, Pete.

September 11, 2011 | Unregistered CommenterPeter Buchta

And the thanks continue...
There is NO way I would have figured this out on my own.

I'm using a SAMBA mount to my UNRAID media server. I could use my MAC for everything I wanted on my UNRAID media server except use Time Machine to back up my MAC.

I'm now able to back up my MAC to my UNRAID media server and everything is working the way I imagined it could.

Thank you for taking the time to put this out there for the rest of us.

October 9, 2011 | Unregistered CommenterEric

Thanks Phil - this has been doing my head in!
I was still stuck having followed your instruction - getting a "no such file error" and it turned out that I was using the the wrong type of quotes (")!! Having copied them out of your post it worked fine.
I think I originally caused the problem when I reset the my NAS harddrive and renamed it.
Now I just have a several hour wait whilst it does the initial back up!
Thanks again, Matt

November 6, 2011 | Unregistered CommenterMatt

Man, just a simple word : thanks !!

For people like me that use a Buffalo LinkStation Mini : disable the TimeMachine function on the Linkstation and follow the text above.
(My mistake was I used the wifi mac address !)

Thanks again !

November 20, 2011 | Unregistered CommenterEl Manu

I read a number of web pages on the topic, and though they were all similar to this, this was the only one that had the information I needed to understand how this works and finally make it work. Thanks.

December 7, 2011 | Unregistered CommenterKathy M

Great info, it worked great. I wrote a script in case you have to do this fixe on several Macs like i did, here is the link: http://yaxzone.blogspot.com/2011/12/apple-time-machine-and-error-45-when.html

December 20, 2011 | Unregistered CommenterLuis Yax

Thank you!

January 2, 2012 | Unregistered CommenterDamonJM

Hey Phil,

Your method works like gold for creating the backup file, and regular backups for 4-5 months. Then, after disconnecting the backup drive (last time I cut the power over Christmas) I get the dreaded 'error 45':

Time Machine could not complete the backup.
The backup disk image "/Volumes/Storage-1/Marge.sparsebundle" could not be created (error 45).

Now I cannot access my 150Gb Time Machine backup file! I know that I can delete it and start over using your method, but I should not have to do this every few months. Why does Time Machine fail to reconnect with a familiar image after being disconnected? I can read the drive's folders and other files not problem but TM is not happy. Funny thing is: TM accepts the drive as a backup resource, but throws the error during validation.

Is there any way to 'fix' the Time Machine connection with the sparsebundle?


January 21, 2012 | Unregistered CommenterQJ

This is fantastic. There is so much confusing trash out there and using this writing really helped me. I have one suggestion though, when grabbing the mac address to form the sparsebundle filename, you mention that you need to use en0, but in my case, my logic said "wait a minute, you will be using wireless, so use the wireless adapter's mac address instead", and, of course, it fails... so to save people some time, maybe you can add the note in the article itself to use en0 regardless of how you'll access your NAS. I know the answer is in the comments, but there are quite a lot of them...

Again, thanks for this writing!

January 29, 2012 | Unregistered CommenterMariano Asselborn


Thanks for your comments. Actually I thought I did go to some lengths to explain why you should use en0. In the first paragraph under the heading "Finding the MAC Address" I spend the whole second half discussing it.
I use italics and everything :-)
Anyway, glad you got it working.

January 29, 2012 | Registered CommenterPhil Nash

I'm trying to set this up on an encrypted, university-maintained, networked Fat32 storage server. I created an HFS+J sparsebundle as you directed, named <my computer's sharing name>_<ethernet mac address>.sparsebundle. I put the sparsebundle in my home directory on the server (the mount point that appears in /Volumes, which I can read from, and write to, just fine via smb in Finder). Time Machine allows me to select my home directory on the storage server as my backup disk. But when it comes time to begin the backup, Time Machine throws this error: "The backup disk is not available." Any ideas?

February 15, 2012 | Unregistered CommenterEli

Hi Phil,
Thank you for a great, well written method. I created a Time Machine backup on my ICYBOX using this method and it worked a treat, that is until i decided to move and for some reason i can't get it to work since then. I can see the NAS drive on the network but the backup folder shows a no entry sign and when i click it it tells me i do not have permission to access the file. A shortcut to the file is located on my desktop. Things that have changed since it last worked: Upgrade to OS Lion, New Router, New Location, Mac linked to router via WiFi now v.s ethernet cable. I have read that Apple have discontinued support for DHX authentication and implemented, in its place, DHX2 authentication. Not sure if this is the problem. Any advice you have will be greatly helpful. Regards Andre

March 18, 2012 | Unregistered CommenterAndre Jones

When I try to copy the sparsebundle file from desktop to the timemachine on my iomega Network drive, it gives me the following error:

The operation can’t be completed because you don’t have permission to modify “Parth-Patels-iMac_c8bcc889c63e.sparsebundle”.

Any help please

May 28, 2012 | Unregistered CommenterParth Patel

PostPost a New Comment

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