At it’s World Wide Developer’s conference in June of 2006, Apple released a product that changed the way that a great many people think about backup: Time Machine. While I cringe at the thought, I need to descend into the fawning adoration public relations speak that masquerades as critical coverage of Apple Products. (Actually, forget that, here’s how Apple describes their backup system.)
Time machine is a breakthrough automatic backup that’s built right into Mac OS X. It keeps an up-to-date copy of everything on your Mac – digital photos, music, movies, TV shows, and documents. Now, if you ever have the need, you can easily go back in time to recover anything … Time Machine takes care of it … Automatically, in the the background. You’ll never have to worry about backing up again.
General sarcasm and bitterness aside, Time Machine really is a spectacular piece of kit. Sure, you can very successfully imitate a Time Machine experience using the tools within Windows Vista or Linux (or via third party tools such as Norton Ghost). Even so, Time Machine is just just about the perfect combination of simple, powerful, and integrated. And like most Apple products, when used within the Apple eco-system is a lovely experience.
However, if you migrate too far out of the walled garden, Time Machine isn’t quite so nice to work with. Actually, it can be a bit demanding and temperamental. For example, it requires its own formatted hard drive or the ready availability of a specialized Apple router (called a TimeCapsule). Alternatively, it can be a bit flaky; when I was backing up to a local hard drive, it would often quit with an indecipherable error. Luckily, however, these limitations are pretty easy to overcome. In this article, I will look briefly at how to setup Time Machine so that it works with a simple home server running Samba and Subversion.
A Few Goals
Before jumping into how to change settings, it might be good to talk about why I’ve chosen the configuration options I have: it’s all about simplicity and convenience. As Apple (redundantly) points out, the more simple a task is, the more likely it is to happen. In terms of backup, this means that it should be automated. So, while having a disk connected to a computer is sufficient, backup over the network to a network attached storage (NAS) is much better. "Why," you ask? In the case of NAS, there is no worry about turning the dedicated backup disc on, letting Time Machine do its thing, and then shutting the disk off.
There is, however, one major drawback to backing up over the network. That first backup-up takes a REALLY long time. In my case, it took my MacBook Pro the better part of three straight days to finish. And should you ever need to restore your complete hard drive (due to failure or the purchase of a new computer), you can expect it to take the same amount of time. Once that first backup completes, however, this limitation no longer exists. Subsequent runs only include files that have been modified and go quite quickly.
But what about convenience? The point of a backup is knowing that your work/information is safe. For single files, restoring over the network is easy. But what happens should disaster strike and you lose a hard drive? No one wants to wait three full days before resuming work. Luckily, you can get the benefits of over the network back-up and the convenience of quick recovery by configuring your home back-up server to use USB hard-drives.
Should your hard-drive fail, you can detach the USB drive and then use TimeMachine to restore your data locally. I discovered this lovely side benefit recently when the hard-drive in my MacBook Pro decided to die and I refused to wait three days for it to restore over the network. I disconnected the network drive from the server and plugged it into the Mac. I then booted from the recovery CD and it magically found my Time Machine backup. Instead of three days, I was ready to go in slightly less than three hours. So, now that we have the goals (simplicity and convenience), let’s talk about how to reach them.
Network Backup to Samba
Out of the box, a default Leopard installation won’t work with a Samba share. You will need to follow a relatively simple three step procedure to have Samba supported Time Machine goodness: 1) Create a sparse bundle image on the local file system, 2) copy the sparsebundle to the root of the network share, 3) enable support for “unsupported” network volumes.
1) Create a Spase Bundle Image on the Local File System
Time machine saves backups in an extremely specific format, called a sparse bundle or image. A sparse bundle is a special file that can also behave like a physical hard drive. When you click on it, it will launch a new volume in the finder that then contains other files and folders. A unique characteristic of the sparse bundles included in Leopard is that they will automatically resize based on their contents.
When using Time Machine on Apple hardware, the process of creating a sparse bundle is automated. Unfortunately, this isn’t true on a generic Samba share. In order to make Time Machine work, we need to manually create a sparse bundle and copy it to the Samba share where we will be backing the computer up.
As we create our image, the file name of the image is extremely important. It has a general form of:
Where Computername is the name of your computer and MACaddress is the MAC address for your ethernet card. Luckily, both of these pieces of information are relatively easy to find. The computer’s name is found by opening “System Preferences” and clicking on the “Sharing” link under “Internet and Network.”
For the Time Machine backup to work correctly, it is important that your computer’s name not have any spaces in it. Should you need to, this might be a good time to change it by clicking on the “Edit” button.
You can locate the MAC address by typing the following command into the Terminal:
ifconfig en0 | grep ether | sed s/://g | sed s/ether//
It will return a list of letters and numbers, for example: 001ec4b8f9b3.
Make note as this information is important in the next step. After you have edited your computer’s name (without symbols or spaces) and have your MAC address, you are ready to create the sparse bundle on your local computer. We will later copy it to the correct place on the NAS hard drive. To do, open the terminal and type the following:
sudo hdiutil create –size 250g –type SPARSEBUNDLE –nospotlight –volname “Backup of My Mac” –fs “HFS+J” –verbose ./Computername_MACaddress.sparsebundle
Be sure to replace everything in red with information that is pertinent to your computer (In my case, Computername_MACaddress is RobOakes-Mac_001ec4b8f9b3.sparsebundle). In this example, I have limited the size of the sparse bundle to 250g (through the –size flag). If you omit the "-size" flag, the sparse bundle will expand until it fills the entire available space of the drive.
Update (2009 07-02): The file system (fs) command line option above was changed from "Case Sensitive Journaled HFS+" to "HFS+J".
2) Copy the Sparse Bundle to the Appropriate Location
After you finish creating the sparse bundle, it needs to be copied to the root of the Samba share which you will be using for your backups. This can be done from the finder or from the command line. In my case, I keep my Time Machine backups on a Samba share called PC-Backup.
Update (2009 07-02): The first comment below explains how to copy the sparsebundle image using the command line.
3) Configure Time Machine to Support Samba Network Volumes
To enable Samba shares in Time Machine, type the following into the terminal:
defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1
After you have changed this setting, you may need to restart the computer for it to take effect. (Alternatively, you can also log-out and then log back in.) At this point, everything is set-up for Time Machine to use your Samba share for back-ups.
Since Samba does not use Apple’s zero configuration network protocol (known as Bonjour), you will need to help Mac OS X find your backup-up volume the first time you use it. This can be done a variety of ways, you can either manually mount the volume by using the command line, or by navigating to the disk with the finder. (To check if the disk has been mounted, open up a finder window and see if a small eject icon appears next to the computer which hosts the share. Alternatively you can navigate to the /Volumes/ folder, where you will also see a list of currently mounted remote shares.)
Next, open the Time Machine configuration from the System Preferences and press the “Change Disk” button. This will give you a list of all the disks and samba shares that are currently available to OS X. Select which disk that you you would like to use and press the “Use for Backup” button. Since I placed my sparse bundle in the root of PC-Backup, that is the volume that I should select.
Time Machine will begin a full back-up that can be accessed either over the network, or by manually plugging the hard drive into your Mac.