Location Aware Time Machine

My Time Machine backup is AFP based network share that is located at my office LAN, but regardless of my location, Time Machine tries to access this share and when it can, it starts backing up. This might not be that bad idea, but my home network upload is not that good, which results in waste of time and bandwith as TM never completes even the first step of calculating differences.

So, first I sought out for solution to disable access to AFP volume from the world, which would cut me off the whole volume, though. But then I stumbled upon this post, which in essential shows how to toggle Time Machine from command line. Combine this with Marco Polo and you get yourself a Location Aware Time Machine.

Configure Marco Polo

First of all you have to configure Marco Polo, but as this is different for every case, you have to do it yourself.
As an example I have two contexts: Work and Automatic and three rules to detect the Work context: external monitor, IP number and a low confidence rule for ethernet cable connection (which I might have at home also).

Write shell scripts

Now you have to write two shell scripts. First one is named TurnOnTM.sh and contains:

defaults write /Library/Preferences/com.apple.TimeMachine AutoBackup -boolean YES

And another script named TurnOffTM.sh, which contains:

defaults write /Library/Preferences/com.apple.TimeMachine AutoBackup -boolean NO

It does not matter where you save these scripts as long as you point Marco Polo to the right location.

Add scripts to Marco Polo

Now open Marco Polo preferences and switch to Actions pane. Add new ShellScript Action and point it to the TurnOnTM.sh you created before. Don’t forget to select Work context for this action and event On Arrival.

Repeat this process for TurnOffTM.sh, but this time set the event to On Departure. Now test the configuration either by forcing context upon Marco Polo from the menu or triggering the context switch manually (e.g. remove network cable). When forcing context, be sure to have the Stick forced context option set from the same menu, otherwise Marco Polo will switch the context back on the next poll.

If you were successful you should see messages like these and no errors reported:

If there are errors reported, refer to Console to find out what went wrong.

After successful context switch you should verify that TM is turned ON/OFF correctly by coing to Time Machine Preferences.

Note: Do not leave TM preferences open while switching context as this does not refresh the new state and on closing overwrites the setting by it’s own value.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s