Monthly Archive: July 2009

Time Machine on disk images on local hard drives

I guess this is more Technology than it is Linguistics. But, anyway. I have a Time Capsule at home, my Macs back up to it over the network via Time Machine. The way this works is that there is a disk image (a special, fragmented kind of expandable disk image called a “sparsebundle“) on the Time Capsule’s drive, which gets mounted during the backup process and then the backup takes place on this disk image.

Normally, when you use Time Machine on a locally-attached hard drive, there is no disk image involved, it just puts the backup into a folder called “Backups.backupdb“.

I have a pretty big external hard drive in my office, and I thought I’d like to set up a Time Machine backup there too. But it’s a really big hard drive, and I want to use it for other stuff, not just Time Machine. Yet, Time Machine likes to eat up all the space it is given access to. Re-partitioning the drive (in order to impose a hard limit on the size of the Time Machine backup) would mean erasing the drive, and I already have a bunch of stuff on it that I’m too lazy to move off and back on again. What would be ideal is if that same backup scheme that the Time Capsule uses, namely a disk image (which can have limits placed on its size), which could be used on the local hard drive.

Mounted disk images do not show up as valid Time Machine target drives, even when you monkey with the Terminal and set the hidden preference to allow unsupported network drives. However, I believe that I have discovered that, if you have an appropriately named disk image on the drive, Time Machine will use it.

So, here’s what you do. We will need two pieces of information: the MAC address, and the Computer Name. To get the MAC address, choose About This Mac in the Apple menu, click on More Info to bring up System Profiler. Click on Network in the side panel, then on Ethernet in the top panel. Near the bottom, find the MAC address, which is a 12-digit hex string like 01:23:45:67:89:ab. Take note of this number. You will use it shortly, but without the colons.

To get the Computer Name, choose “System Preferences” under the Apple menu, and click on Sharing. At the top, there is a Computer Name (often something like “Paul Hagstrom’s Computer” if you haven’t changed it to something intentionally). Take note of this as well.

Find Disk Utility (in the Applications folder, within the Utilities folder) and launch it. In the File menu, choose New, Blank disk image. Set the image format to: “sparse bundle disk image“. Set the Volume Name to be “Backup of Computer Name” (e.g., “Backup of Paul Hagstrom’s Computer“, substituting in whatever your Computer Name was). Set the size to be something appropriate, I picked 160GB, which might even be a bit on the small side. To do that requires picking a custom size, changing the popup to “GB” and typing 160. Finally, in the Save As field at the top, enter “Computer Name_MAC address.sparsebundle” exactly like that (e.g., “Paul Hagstrom’s Computer_0123456789ab.sparsebundle“). There are no colons in the MAC address when you are choosing the filename for the disk image, and there is an underscore between the Computer Name and the MAC address. All set? Hit Create. It’ll be pretty quick, because a sparsebundle is only as big as the data that’s been saved on it, and there hasn’t been any saved there yet.

When the image is created, if it isn’t mounted automatically, double-click on it so that the volume “Backup of XX” becomes available on the desktop.

Last step requires the Terminal (also in the Applications folder within the Utilities folder, same place Disk Utility was). Double-click on the Terminal to open it, and type the following, where by [tab] I mean “hit the Tab key”: “cd /V[tab]Back[tab]” and the hit return. This should have expanded to something like “cd /Volumes/Backup of Paul Hagstrom's Computer/“. Type “sudo touch .com.apple.timemachine.supported” (that has a space between sudo and touch and one between touch and the period, but then no further spaces) and hit return. You might get a message about using the power of “sudo” only for good if you’ve never done this before. Type in your password (the one you use when installing software, etc.). Now, type “cd /V[tab]XXYY[tab]” except instead of XXYY, type the first couple of letters of the hard drive on which you will be placing this disk image. And do the same thing as before, “sudo touch .com.apple.timemachine.supported“. You may not need to enter the password the second time if you did this soon enough after the first time. Then, quit the Terminal application.

Back in the Finder, eject the “Backup of XX” drive, and make sure that the sparsebundle you created is sitting at the top level of the hard drive it’s going to live on.

Now, you should be set. Open System Preferences, and go to Time Machine. Click on “Change Disk…” and pick the disk on which the sparsebundle lives. You’ll also want to probably want to turn Time Machine off (it’ll have switched on automatically) and click “Options…” and exclude various things from your backup so the backup isn’t unnecessarily huge. You can always reinstall the system from the Install DVD, after all. I generally exclude system files, and various transient folders like my Downloads folder, /Library/Caches/, ~/Library/Caches/, ~/.dropbox, and other things. Then Turn Time Machine back on, and choose Backup Now from the menu bar item or from the dock menu. What you should see happen is that it’ll think briefly and then your “Backup of XXYY” volume will automatically be mounted. This will look familiar happening for anyone who is used to doing Time Machine backups over a network. But that means it worked: the backup is now going to the sparsebundle on your local disk.

Having said all that, I have not really stress tested this. I trust that the sparsebundle will not exceed the size limit that I imposed upon it during its creation (160GB), but I will have to wait a while for it to fill up so I can see what happens. Perhaps I’ll post an update later. But I was pleased to see that it was relatively easy to get this far.

(A footnote: The procedure I outlined above is not exactly what I did, although it should work. If it doesn’t, what I actually did was this: I did a Time Machine backup straight to that external drive first. Then, I created the disk image as described above and put it on the external drive. Then I renamed the “Backups.backupdb” using sudo in the Terminal [sudo mv Backups.backupdb Backups.backupdbx], so Time Machine wouldn’t find it, and then started Time Machine. It found my sparseimage and started the backup over. At which point I dropped Backups.backupdbx into the trash and emptied it away. I don’t think that extra step of doing the initial Time Machine backup without the image was important, so I omitted it above. But if you try this and it doesn’t work, you could also try doing a first, possibly partial, backup without the image, and then move to the image.)