Backing Up #1 – Mirroring with Fetch
Saturday, April 22nd, 2006Having survived a few catastrophic hard drive failures, I cannot emphasize enough how important it is to implement an thorough and automatic backup routine into your daily and weekly workflow. This is the first part in a series outlining backup strategies for various environments.
This first article describes mirroring a remote site directory on a Mac using Fetch, AppleScript, Automator, and iCal.
First: Why would you download a directory? Normally you are developing locally and syncing remote files with your local ones. However, let’s say that you have a Flickr-like site that allows users to upload images. You would need to archive those files frequently in order to avoid irrevocable data loss and some very unhappy customers.
So let’s get started.
In Fetch, go Fetch > Preferences and make sure the following is set:
General:
[on] Use Passive mode transfers
[on] Keep connections alive
Download:
Default download mode: automatic
Miscellaneous:
[on] Allow duplicate connections
[on] Omit filenames beginning with a period
Now, still in Fetch, open a connection to the site and navigate to the folder that you wish to mirror (probably just the root). Now, go Remote > Mirror… and set your mirror event up. It is important to make sure the checkbox next to “Run automatically” is UNCHECKED, or this AppleScript will try to run the mirror event twice. Make sure you have the mirror remote to local (the lower of the two ?¢‚ǨÀúdirection’ buttons, or ?¢‚ǨÀúRight to Left’) selected. The default is UPLOAD, which you do not want to do. Make sure Delete Strays is selected. Click Save… and save the mirror file somewhere.
Launch the AppleScript editor (Finder > Go > Applications > AppleScript > AppleScript Editor) and click Record. With AppleScript recording your actions, go to Fetch and go File > Open to open your newly saved mirror file. Back in the AppleScript Editor, click the Stop button. Back in Fetch, stop the mirror; there’s no need to continue.
You should now have something like this in your AppleScript window:
***************
tell application “Fetch”
activate
open {alias “Path:to:mirror:file”}
mirror remote folder “ftp://username :password@ftpsite.com/path/to/folder/in/mirror/file/” to alias “path:to:local:backup:folder:in:mirror:file:” with delete strays
quit
end tell
***************
It is important to set a timeout of 0 to avoid the AppleScript from timing out before your mirror event is complete.
Add the timeout lines (2nd and 2nd to last below) to your script. You should now have something like:
***************
tell application “Fetch”
with timeout of 0 seconds
activate
open {alias “Path:to:mirror:file”}
mirror remote folder “ftp://username :password@ftpsite.com/path/to/folder/in/mirror/file/” to alias “path:to:local:backup:folder:in:mirror:file:” with delete strays
quit
end timeout
end tell
***************
Save the AppleScript as an application (make sure ?¢‚ǨÀúRun Only’, ?¢‚ǨÀúStartup Script’, and ?¢‚ǨÀúStay Open’ are NOT checked). You can quit the AppleScript editor.
Now in Automator (Finder > Go > Applications > Automator), select Finder in the Library window on the left. Drag the following from the Actions window:
1) Get Specified Finder Items ?¢‚Ǩ‚Äú click the ?¢‚ǨÀúplus’ button find your newly created AppleScript application.
2) Open Finder Items
Save this as an iCal plug-in and set the event to repeat daily, weekly, or however often you want to run the script.
Sphere: Related Content


