Date created: 03/25/10 20:09:17. Last modified: 12/13/12 11:41:20

TimeMachine Automation

TM likes to backup to a sparse image so for a server I backup via TM this script mounts the SMB volume on another server where the sparse image resides (the username & password for the SMB share are stored in the local server admin's account keychain to automate this step).

Next TM is turned on (I don't leave it on otherwise, during the day when the server storing the sparse image is down, TM can't backup and despite that at night that server is on, after a week of failed backups during the daytime TM starts to go a bit loopy spawning child processes that don't terminate).

Finally a "do shell script" is used to kick a TM backup off instantly rather than waiting an hour for the schedule to roll round.

Note: You may need to enable the use of unsupported drives with TM in this scenario, I haven't tested it without, if so use the following command to set this preference;

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1
-- Set an smb volume where our TM sparse image is located
set smbvolume to "smb://10.0.0.8/triden"
 
-- Try and mount the smb volume
tell application "Finder"
        try
                mount volume smbvolume
        on error
                display dialog "poopies" buttons "ok" default button 1
        end try
end tell
 
-- Active TM for auto backups
do shell script "defaults write /Library/Preferences/com.apple.TimeMachine AutoBackup -bool true"
 
-- Start a TM backup now
do shell script "/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper >/dev/null 2>&1 &"

When we are all done we simply disable TM, umount the sparse image and them unmount the SMB volume;

-- Set the name of the TM sparse image
set sparseimg to "Backup of triden"
 
-- Set the name of the smb volume
set smbvolume to "triden"
 
-- Disable the TM auto backup feature
do shell script "defaults write /Library/Preferences/com.apple.TimeMachine AutoBackup -bool false"
 
-- Unmount our TM sparse image
tell application "Finder"
        eject sparseimg
       
        -- Unmount the smb volume
        eject smbvolume
       
end tell