Re: backup script
Re: backup script
- Subject: Re: backup script
- From: Mr Tea <email@hidden>
- Date: Tue, 13 Feb 2001 17:06:51 +0000
This from Jolly Roger - dateline 2/13/01 12.23 am:
>
tell application "Finder"
>
duplicate myFile to zipDisk with replacing
>
end tell
Hi JR.
I think B.H. will find that when he does this, the replaced items on the Zip
disk are moved to the trash rather than deleted. (This was true in OS 9.0.4,
but I haven't tested it in OS 9.1 yet.) So the stuff appears to have been
deleted, but is still taking up space on the Zip.
One solution is for the script to empty the trash after its done the backup
(or repeatedly during), but some people (god bless 'em) actually use the
trash for storing stuff that they might want to keep. My preferred method is
to use the deleteFile command from Jon's Additions.
I use a number of zip disks to back up specific important folders on my hard
drive The script that does the back-ups is an 'on open' folder action
attached to a folder that is left open on the zip disk, so when I insert the
zip disk, the folder window pops open and the script runs automatically.
The source to be backed up is defined as a path in the comment of the folder
to which the backup script is attached - I've reproduced the script below.
Watch out for line wraps, but note that the wraps in the first two 'display
dialog' text strings are intentional.
Experienced scripters will notice that parts of this script are cribbed from
the 'Synchronise Folders' droplet provided as one of the ready-made
'Automated tasks' with some versions of the Mac OS. The script only runs if
the host folder's label index has been set to 1, and can be disabled easily
enough when inserting a zip disk by holding down the option key to prevent
the folder window from opening.
on opening folder BackupDest
with timeout of 600 seconds
try
tell application "Finder"
activate
copy comment of BackupDest to BackupSource
copy name of folder BackupSource to theSource
if label index of folder BackupDest is 1 then
if (round ((physical size of folder BackupSource) / 1048576)) < 94 then
display dialog "Backing up the folder " & theSource & ".
Please select an option..." with icon 1 buttons {"Cancel", "Replace",
"Update"} default button 3 giving up after 10
if gave up of result or the button returned of the result is "Update"
then
SyncFolders(BackupSource, BackupDest) of me
else if the button returned of the result is "Replace" then
copy every item of BackupDest to xFiles
deleteFile xFiles without safety net
copy every item of folder BackupSource to newFiles
duplicate newFiles to BackupDest
end if
say "The " & theSource & " has been backed up."
set the clipboard to (container of folder BackupDest) as text
ignoring application responses
tell application "Auto Eject" to run
end ignoring
else
display dialog "The source folder has grown too large to
fit on this disk. Please archive some of the
contents before proceeding." with icon 2
end if
end if
end tell
on error errmsg
display dialog errmsg
end try
end timeout
end opening folder
on SyncFolders(BackupSource, BackupDest)
SyncEm(BackupSource, BackupDest)
end SyncFolders
on SyncEm(BackupSource, BackupDest)
try
tell application "Finder"
set Folder1Contents to list folder BackupSource without invisibles
set Folder2Contents to list folder BackupDest without invisibles
repeat with x in Folder1Contents
set label index of alias ((BackupDest as text) & x) to 1
if x is not in Folder2Contents then
--say "Backing up " & x
duplicate alias ((BackupSource as text) & x) to folder BackupDest
set label index of alias ((BackupDest as text) & x) to 1
else
if kind of alias ((BackupSource as text) & x) is "folder" then
SyncFolders(((BackupSource as text) & x) as alias, ((BackupDest as
text) & x) as alias) of me
else
set date1 to modification date of alias ((BackupSource as text) & x)
set date2 to modification date of alias ((BackupDest as text) & x)
if date1 > date2 then
--say "Backing up " & x
deleteFile alias ((BackupDest as text) & x) without safety net
duplicate alias ((BackupSource as text) & x) to folder BackupDest
end if
end if
end if
end repeat
set label index of every item of folder BackupDest to 0
end tell
on error errmsg
display dialog errmsg & return & x
end try
end SyncEm
--
Brew of the day: Assam