Wednesday 18 July 2007

Neat folder backup script

I wrote this script to provide incremental backups to a work in progress folder on my mac. It copies this foler to an external hard drive, then appends the date to the folder name. This means that every day you get a new backup (and when you get too many, you can just delete the older ones). Replace the file paths with your own:

-- This script will copy a folder of your choice to a destination of your choice, and then append today's date to the newly backed up folder. This means that you'll have a daily incremental backup of you're 'work in progress' folder, for example. --

-- If you save this as a run only application on your hard drive, then use iCal to open it at, say, 5.30 every weekday, it'll backup all your work in progress. You can then schedule your machine then to shut down at, say, 6pm using the 'Energy Saver settings in System Preferences. Obviously, if these backups build up you'll eventually run out of disk space, so you'll need to regularly 'clean out' the backup folder --


tell application "Finder"
activate
make new Finder window to startup disk
set target of Finder window 1 to folder "Hard_Drive:Users:Home:Documents:Workshop:" -- this should be the path to your work in progress folder --

ignoring application responses

-- duplicate your folder to your backup location --

duplicate folder "Workshop" of folder "Documents" of folder "Home" of folder "Users" of startup disk to "Backup_location:Backup_location folder"

-- Note: if you're backing up to a networked drive, you must make sure that you've connected to the drive before the script is run --

end ignoring

delay 120 -- set this to an appropriate number of seconds to ensure the backup is completed --

-- this next bit appends today's date to the newly backed up folder --

set theDate to current date
set todaysDate to ((the month of theDate & " " & the day of theDate & ", " & the year of theDate) as string)
if name of folder "Backup_location:Backup_location folder:Workshop" is not "" then
set name of folder "Workshop" of folder "Backup_location folder" of folder "Backup_location" to "Workshop" & " " & todaysDate
end if
end tell


cheers,

Kev

No comments: