Thursday, December 30, 2010

Automatated Back-Up Disc Switching

I have an external harddrive at work and a different one at home that both have Time Machine back-ups.  I'm inconceivably lazy, and got tired of going to the Time Machine settings every time I brought the laptop home.

Soooooo.....this guy told me how to fix it up nice.  I'm not smart, and I couldn't really figure out what he was doing, so anything dumb is my fault, anything smart is his doing.

1. Copy a smarter person's scripts
    • This is because I don't know any of the syntax for the commands.  I'm copying the aforementioned "this guy."
2. Download Marco Polo.
    • It's a program that tries to figure out where you are based on what USB devices you have, and a bunch of other things.  Pretty cool.
    • You need it because it also has the option to automatically perform actions based on the "context" it detects.
3. Figure out what TimeMachine calls your harddrives
    • When TimeMachine is using the right harddrive, open "Terminal" and copy this exact text in:
defaults read /Library/Preferences/com.apple.TimeMachine BackupAlias
    • It gives you a butt-ton of numbers and letters.  That's apparently more easier for computer brains to deal with.  They are weird.
"This guy" says "write a little shell script."  He might as well have said "drink the froth forthwith," because I got no idea what that means in terms of what I actually need to do.  The next 9 steps are me trying "write a little shell script."

4. Make a text file with the smarter person's scripts
    • I used TextEdit.
    • The actual content of the text file should be:

#!/bin/bash
defaults write /Library/Preferences/com.apple.TimeMachine BackupAlias '<a whole paragraph of numbers and letters that you got from step 3>'
/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper &
killall Terminal


    • You have to go Format -> Make Plain Text before you save it.  This is because TextEdit defaults to Rich Text Format, and apparently that richness just acts like coagulated fat in the streaming veins of intercomputer communication.
    • Save it on Desktop (you can save it other places, but there's some weirdness with "Paths" that I don't understand)
    • This does three things: First it switches the harddrive being used for TimeMachine, then (the /System/Library....line) it makes it start a new back up (otherwise it doesn't do it for a while and you might switch again before backing anything up) and then it KILLS ALL TERMINALS!  BWA HA...no.  It just quits that program because otherwise the little window stays there, and it bugged me.
    • The last two command are different than "this guy's," because I couldn't get his to work.
5. Turn your text file into a program
    • Two parts:
      • First, change the name of the file manually so that it ends with ".command"
      • Second, open terminal and paste this text, replacing You with your user name and FileName with the actual name of the file
chmod 755 Users/You/Desktop/FileName.command
      • This apparently gives you permission to run the program.  I don't think I need permission from a little texty box on my computer, but...I am apparently wrong.
6. Tell MarcoPolo to run your program
    • Preferences -> Actions, add an open type of action, and pick your ".command" file in the Open File... dialog that pops up.
    • I set a rule to use the harddrive as a USB device to determine the context at 100% confidence.  I wonder what would happen if I connected both harddrives at once?
    • I think it's also good to set a delay, just to make sure everything's all connected and happy before trying to start the backup.
7. Do steps 3 to 6 again for the other places and the other harddrives you want to switch to
    • It sounds like wifi isn't a good thing to use for rules because it's iffy and hard to monitor, so probably use other stuff.
    • A good way to test it is to right-click the menu bar icon and go Force Context -> Automatic.  Then, if your Rules are working, it will switch to the new one and (hopefully) switch backup disks.
Sort of 7.1, in a way.  
    • Marco Polo doesn't automatically run when you start up the computer, and it's not in the Dock so I didn't know how to make it do that.
    • It's easy, just do what this other guy or possibly lady says.
8. Be amazed that I figured this out!
    • It only took three hours.  I am not productive.
UPDATE 12-29-10:  I took out the "killall Terminal" command and replaced it with "Exit."  It leaves the Terminal program running, but I think the "killall" just ends the backup processes I asked it to start.

UPDATE 12-30-10:  There's an annoying pop-up that the "identity of the backup disk has changed since the previous backup" that comes up with this.  Then the TimeMachine preferences pane pops-up, and you have to close it and the Terminal, which really isn't saving me any time at all.  I don't like it, so I tracked down alternative solutions.  The problem with that approach is that you have to edit the TimeMachine preferences files, and I'm not sure I want to be doing that.

Update 12-30-10 + about 10 minutes:  This forum tells how to solve this.  It says the problem is that you have to tell TimeMachine two things about the change, so you have to first get the DestinationUUID using

defaults read /Library/Preferences/com.apple.TimeMachine DestinationUUID
Note that if this prints out with hyphens you have to delete them.  Also, make sure you have the right harddrive selected in TimeMachine - it prints out the DestinationUUID of whatever it's currently using for backups.

Then add this a line so that the new script looks like:

#!/bin/bash
defaults write /Library/Preferences/com.apple.TimeMachine BackupAlias '<a whole paragraph of numbers and letters that you got from step 3>'
defaults write /Library/Preferences/com.apple.TimeMachine DestinationUUID '<a few numbers and letters from above>'
 /System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper &
Exit 
But I did that, and it's not working...yet.

UPDATE (FAIL):  I give up and I hate this.

UPDATE (STILL FAIL):  I tried this guy's GUI scripting technique.  I couldn't get the script to run with Marco Polo, so I tried Do Something When.  It ran, but it stopped before picking the right disc, and it bugged me watching it go.  So.  That.

No comments:

Post a Comment