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

That's brilliant!!

I just wanted to add a comment as I entered the commands and received an error with no sparsebundle created.
It turned out my computer name had a space in it: File Server.
The trick here is to use the FQDN shown below where it states:

Computers on your local network can access your computer at: File-Server.local

So I entered File-Server.local as the computer and away it went, created sparse bundle, copied into relevant folder and one time backup successfully created,
Thought I would add that in case someone else has this problem

September 24, 2010 | Unregistered CommenterPaul

This worked for me, at first. But after the initial backup, subsequent backups continue to fail with the same error. The server is not keeping the sparsebundle I created! Any ideas?

September 24, 2010 | Unregistered CommenterJB

@Paul - thanks for that.

@JB Have a look in the console logs to see if it gives you any clues - e.g. is it trying to use a different sparsebundle name on subsequent back-ups?

September 24, 2010 | Registered CommenterPhil Nash

I think you may be correct about the permission issue. I actually *do* have a ReadyNAS, with current firmware supposedly capable of behaving like a TC. When I try to run a backup, I can see TM building the file, then things fail with the dreaded "Error 45". Running the hdiutil command to create the sparsebundle directly on the (AFP-mounted) ReadyNAS, it fails with the last few lines of verbose output:

DIBackingStoreCreateWithCFURL: creator returned 0
DIBackingStoreCreateWithCFURL: creator returned 0
DIDiskImageCreateWithCFURL: creator returned 0
::getBandEntry: chown() - 501
Finishing…
DIHLDiskImageCreate() returned 1
hdiutil: create: returning 1
hdiutil: create failed - Operation not permitted

'501' is my UID/GID. Running the exact same command line, but with the pathname changed to reference the local (HFS+) disk, works fine, with the output ending:

DIBackingStoreCreateWithCFURL: creator returned 0
DIBackingStoreCreateWithCFURL: creator returned 0
DIDiskImageCreateWithCFURL: creator returned 0
DI_kextWaitQuiet: about to call IOServiceWaitQuiet...
DI_kextWaitQuiet: IOServiceWaitQuiet took 0.000004 seconds
Formatting…
Initialized /dev/rdisk2s2 as a 720 GB HFS Plus volume with a 65536k journal
Finishing…
created: /Users/<user>/<hostname>_<MAC>.sparsebundle
hdiutil: create: returning 0

I was then able to transfer the sparsebundle to the NAS via 'tar -cf - <hostname>_<MAC>.sparsebundle | (cd /Volumes/ReadyNAS && tar -xpf -)' and fire off a successful TM backup. Looking at the perms on that sparsebundle, I see:

drwxr-xr-x@ 6 root GID 204 Oct 3 18:09 <host>_<MAC>.sparsebundle

All its contents are similarly owned, so I'm guessing the NAS had a problem with the way the GIDs were being set over AFP.

October 4, 2010 | Unregistered CommenterGuy B. Purcell

Thanks so much for this. I have spent hours trying to get this to work. Your instructions worked brilliantly.

cheers Brett

October 4, 2010 | Unregistered CommenterBrett

Hello,

I'm having problems getting this to work.... I'm getting the same errors as Adam did. Can anyone help?

October 14, 2010 | Unregistered CommenterBilly

@Billy. Did you see the solution to Adam's problem? I believe it was that he'd left in the angle brackets <> from my placeholder strings when substituting his computer name and mac address in.
Is that your poblem? Also check the spellings are exactly right and that there are no other extraneous characters in there (apostrophes are common).

Failing that post the actual error you get here.

October 14, 2010 | Registered CommenterPhil Nash

This site gave great background for a beginner . . . which I am. THANKS Phil and all posters! This is what I did to try and get my drive working:

Step 1 – I opened a terminal window and pasted the following in and hit return: (I understand this command allowed the MyBookWorld drive to show up in the list of destinations available for storing backups.)

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

Step 2 - I then tried to create the sparse image using Phil's command line with my computer name and mac address in it, but it didn't work. All I got was ">"

Instead of: ~/Desktop/User's MacBook Pro_c42c0301af6e.sparsebundle
I tried: ~/Desktop/MyBackup.sparsebundle

I entered the following in Terminal Window:

sudo hdiutil create -size 800g -type SPARSEBUNDLE -nospotlight -volname "Backup of User's MacBook Pro" -fs "Case-sensitive Journaled HFS+" -verbose ~/Desktop/MyBackup.sparsebundle

It gave me the following result:
sudo hdiutil create -size 800g -type SPARSEBUNDLE -nospotlight -volname "Backup of User's MacBook Pro" -fs "Case-sensitive Journaled HFS+" -verbose ~/Desktop/MyBackup.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
DIFileEncodingCreatorProbe: interface 2, score -1000, CEncryptedEncoding
DIFileEncodingCreatorProbe: nothing to select.
DIBackingStoreCreatorProbe: interface 0, score 100, 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 CBSDBackingStore
DIBackingStoreCreateWithCFURL: CBSDBackingStore
DIBackingStoreCreateWithCFURL: creator returned 0
DIBackingStoreCreateWithCFURL: creator returned 0
DIDiskImageCreateWithCFURL: creator returned 0
DI_kextWaitQuiet: about to call IOServiceWaitQuiet...
DI_kextWaitQuiet: IOServiceWaitQuiet took 0.000004 seconds
Formatting…
Initialized /dev/rdisk2s2 as a 800 GB HFS Plus volume with a 65536k journal
Finishing…
created: /Users/user/Desktop/MyBackup.sparsebundle
hdiutil: create: returning 0

I don't know why this worked but it seemed to, so I continued

Step 3: I copied the resulting file (MyBackup.sparsebundle), from my desktop to the MyBookWorld drive. The MyBookWorld drive has two folders:
- ID22548006
- PUBLIC
The first is not available. I copied MyBackup.sparsebundle to PUBLIC

I opened Time Machine and selected PUBLIC.

When I try to backup, I get the following:

The backup disk image “/Volumes/PUBLIC-4/User’s MacBook Pro.sparsebundle” could not be created (error 45).

Any Ideas anyone?

I have been trying to get my NAS to work for days. Last night I read that even if this works, the backups that are created may not. The author was suggesting buying a "Time Capsule". Any truth to this?

October 14, 2010 | Unregistered CommenterChuck

OK...So my directory was wrong...fixed it got the sparse bundle to show on my desktop, moved it over to my networked hard drive and I'm still getting nothing.... I am a noobie at this.... so any help would be greatly appreciated. Thanks Phil... That was my first problem....then the directory.... now this....

October 14, 2010 | Unregistered CommenterBilly

Hey Phil,
thanks for the great how to...
i was wondering, in the command it says -fs "Case-sensitive Journaled HFS+"
im not that good with this kind of stuff, but is that specific to the mac file system on my mac, or is that telling timemachine the filesystem on the NAS? and if so, how do i change it as my NAS is FAT32.

October 14, 2010 | Unregistered CommenterLuca

@Chuck It looks like it's not finding the image file because the filename is not what it is looking for. That's because you used "MyBackup" instead of your computer name + MAC address. From what I can tell you did that because your computer name has spaces in it and that breaks the command if you don't allow for it. Take a look at my response to Roman on page 1 of the comments. In short you need to put the filename in quotes to get the spaces to work.
As for the TimeCapsule. I had one. It worked ok for a year (although I had to reboot it from time to time), then died. So I went back to using my NAS for TimeMachine and found it was a smoother experience. Not had any problems (other than those that led to this article) in the two years I've been doing that. The way the disk image is used is identical to how it used on the TimeCapsule. So once you get past these problems, as long as the disk image can be opened it should work exactly the same. Potentially you NAS will be more reliable, if you have it some RAID configuration.

@Billy Could you elaborate on "getting nothing"? Are you having the same problem as Chuck, perhaps?

@Luca The file system type specified by the -fs switch is for the file system it will create *within the disk image*. It is completely independant of the filesystem that the disk image will be stored in (and is one of the reasons why the disk image is used). So your FAT NAS should be fine.

October 15, 2010 | Registered CommenterPhil Nash

Many thanks for your help Phil. My Backup is up and running.

I used the filename XXXXX-MacBook-Pro_c42c0301af6e, without quotations. I got this name from the Terminal Window prompt. I entered the following command in Terminal Window:

sudo hdiutil create -size 800g -type SPARSEBUNDLE -nospotlight -volname "Backup of XXXXX-MacBook-Pro" -fs "Case-sensitive Journaled HFS+" -verbose ~/Desktop/XXXXX-MacBook-Pro_c42c0301af6e.sparsebundle

It created the sparsebundle file without asking for a password!

Again . . . my sincere thanks.

October 16, 2010 | Unregistered CommenterChuck

Thanks a lot for this tutorial! It worked great on my iMac and Windows XP share with below mentioned command:

sudo hdiutil create -size 60g -type SPARSEBUNDLE -nospotlight -volname "Backup of iMac van Willem" -fs "Case-sensitive Journaled HFS+" -verbose "/Users/willem/Desktop/iMac van Willem_ 99999e9e9999.sparsebundle"

Never the less, a problem has occured. Every 2 or 3 days the backup gets sort of corrupted and TM comes up with the message "Time Machine completed a verification of your backups. To improve reliability, Time Machine must create a new backup for you.".

The only way to solve this problem is to create an entirely new backup. Anyone here met with this problem? Any solution perhaps?

October 23, 2010 | Unregistered CommenterWillem

Apple does not support backing up to any drive except Time Capsule. After following the blog instructions here last year, last month I got the same message @Willem describes and my backup history was wiped out. I've come to the conclusion that Time Machine, while it can be hacked to "support" other NAS is not stable unless used with Time Capsule. I will reluctantly buy one of those and try again.

October 30, 2010 | Unregistered CommenterHarvey Ramer

For the time being, I've set my drive up again following these instructions ... I'm just not confident it's a long-term reliable solution.

October 30, 2010 | Unregistered CommenterHarvey Ramer

Great instructions. I used it to get my MacBook Pro but when I used this command...

sudo hdiutil create -size 100g -type SPARSEBUNDLE -nospotlight -volname "Backup of <wife's> MacBook" -fs "Case-sensitive Journaled HFS+" -verbose "~/Desktop/<wife's> MacBook_34159e080f1c.sparsebundle"

...this is what I get...

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

I'm hoping you can spot what I did wrong!

October 31, 2010 | Unregistered CommenterBob

Been playing with the Mac/Nas thing for a couple of days and this blog has definitely got me a step nearer.

I get as far as this: ( after taking the < > out of the string on the first run!)

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:
Sorry, try again.
Password:

The problem here is that I now cant type or copy any text into the password field, not even the man sudo request for info.

Any Ideas?

Thanks

November 9, 2010 | Unregistered CommenterSparky

@Bob, you might want to try:

"/Users/<wife>/Desktop/<wife's> MacBook_34159e080f1c.sparsebundle"

instead of

"~/Desktop/<wife's> MacBook_34159e080f1c.sparsebundle"

November 9, 2010 | Unregistered CommenterWillem

B.T.W. I managed to temporarily solve my own problem regarding the message "Time Machine completed a verification of your backups. To improve reliability, Time Machine must create a new backup for you.".
The cause of the message seems to be the fact that the TM-backup can't be unmounted at certain moments. After I manually unmounted the backup (using Diskutility) I was able to connect to and use the TM-backup again. But not for long because much more severe problems occured until the backup finally became completely corrupted. So I've given up...

November 9, 2010 | Unregistered CommenterWillem

Thank you for this fantastic work-around!
Finally my stuff is reliably backed-up.

November 14, 2010 | Unregistered CommenterIanI

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>