So, how great is Time Machine, right? You already know. If you’re like me, you back up all your Macs to an external hard drive or Time Capsule or some such. It’s certainly saved my butt more than once, and I can definitely sleep better at night knowing that years’ and years’ worth of mp3’s and pictures and everything else is backed up, safe and sound, in case of catastrophe. I’ve got most of my media on a Mac mini that’s always on at home, always being backed up. But work and other documents live on my Macbook, which is often not at home. So it’s great when I’m sitting on the couch, I just open it up, Time Machine start’s spinnin’ and blammo, backed up. Nice. Except…I’m not sitting on the couch at home as often as I’d like. So if I want to back something up while I’m away from home, or even retrieve an older version of a document, I’m up a creek until I get back to the homestead. Which is a shame, because that big ol’ hard drive with all my data is sitting at home, lonely, collecting dust.
# Step 1: Accessing the Time Machine disk remotely
First off, this obviously isn’t going to work unless your Time Machine is always on, either as a drive connected to another mac, or a Time Capsule disk on your Airport. Secondly, it’s probably not directly connected the internet, it’s likely sitting behind a router (unless it’s a Time Capsule, but even then, it’s not directly accessible to the outside world by default). Thirdly, you probably don’t have a static IP Address with which to access it. So the basic strategy for making the Time Machine Disk available is this: First forward the afp (the network file sharing protocol on macs) port on your router to the machine with Time Machine disk. You’ll need to forward port 548 to the machine with the Time Capsule disk. I’m not going to go into detail how to do this, as it will vary depending on your router, and there are plenty of excellent resources and tutorials out there on the Googles that would do a much better job of explaining it. Important exception! If you’re using a Time Capsule or your disk is connected to an Airport, you won’t actually need to forward the port, as they are directly connected to the internet anyway. However, you will have to open the ports up for access outside of your home. Open Airport Utility and click “Manual Setup”. Click on “Disks” and then “File Sharing”. Check “Share disks over WAN.” Also, I’d advise turning OFF Guest Access to the disks and using a very secure password to access them, as this disk is now exposed to the outside world.

Next you’re going to need an address to access this disk from if you don’t have a static IP address. (If you do have a static IP, you can skip this step, obviously.) There are plenty of services that will provide you with a domain name for your dynamic IP address, personally, I use DynDNS. It’s free and they’ve got a reliable OS X client. Note, if you’ve just got a Time Capsule, and not an always-on mac to run this, you’ll have to update it manually when you’re home. But honestly, your IP probably isn’t going to change all that much, likely only when you restart your cable or dsl modem. At any rate, register for a domain name and you should now be able to get to your router from the outside world via “yourdomain.dyndns.org”. To test out the domain and the port forwarding, while you’re away from home, open Finder, click “Go” —> “Connect to Server”. In the dialog box that pops up, type: afp://yourdomain.dyndns.org/

If everything worked, your Time Machine disk should now be mounted on your desktop!

# Step 2: Switching Time Machine Disks
Now, while the Time Machine disk is mounted remotely, open the Time Machine preferences and change the disk by choosing “Select Disk”.

You should see the share located at yourdomain.dyndns.org (or your static IP, or whatever). Select that.

That’s it! Now you’re backing up to the remote disk! You can also enter the Time Machine app and restore from previous backups, just like you were at home. When you’re back home, however, you’ll likely want to switch back to the “local” disk, as syncing of the LAN is preferable (more secure, faster) than syncing over the WAN. Plus it seems sort of silly to send your data outside your router, just to send it right back. So when you get back home, you can just open Time Machine preferences again and select the “local” drive.
# Step 3: (Optional) Switching between local and remote Time Machines automatically
Part of the thing that makes Time Machine so great is that it’s always backing up, every hour, without any input from me. It just works. So obviously, switching back and forth between local and remote disks would hinder this. At this point, I went a-googling for a shell script that would switch Time Machine disks for me, and I stumbled across this site, with a very helpful tip on how to do this. Basically, you will need to capture the encoded value for each drive, and then create one script for each disk, which you’ll trigger when you switch networks. To launch the scripts, I use a little program called MarcoPolo, which can perform any number of actions when you change networks, such as a launch a shell script. While you’re at home and the local disk is selected, open up Terminal and type the following:
defaults read /Library/Preferences/com.apple.TimeMachine BackupAlias
Now open up TextEdit and paste the following:
#!/bin/bash defaults write /Library/Preferences/com.apple.TimeMachine BackupAlias 'disk'
but replace “disk” with the results from Terminal. Save this file wherever you like to save your scripts, for example, ~/Library/Scripts/time_machine_local.sh. Repeat these steps for the remote disk and call it time_machine_remote.sh. In Terminal, navigate to the folder where you saved the scripts and make them executable:
chmod a+x time_machine_local.sh
chmod a+x time_machine_remote.sh
Next, to get these to run automatically, download and install MarcoPolo (if you are using Snow Leopard use this beta). Set up two contexts “Home” and “Automatic” (or whatever you wish to call them). Set “Automatic” to be your default context. Set up automatic context-switching (I prefer to do this by WiFi SSID.) Next, set up some actions to trigger on context change. Select new ShellScriptAction and create one to trigger time_machine_local.sh when you arrive at the “Home” context. When you depart, trigger time_machine_remote.sh.

# Final Thoughts on Security
Is this secure? Well, no, not really. It’s password protected, but your backup disk is now open to the internet, and additionally, the transfers are not encrypted. If this is a concern for you, there are a couple things you could try (but I haven’t tried personally):
- Set up a VPN at home (iVPN is one solution) instead of opening up the afp port and connect that way.
- Set up an SSH server at home and tunnel the afp port through that.
- ShareTool sets up a VPN over SSH and supports Bonjour.
- ??? Do you have any better ideas? Let me know!
