Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Automate iCal backups' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Automate iCal backups
Authored by: tedw on Aug 15, '10 01:08:54AM
yes, you can follow the same basic procedure: copy all the files/folders in ~/Library/Application Support/AddressBook into a folder called Address Book - YYYY-MM-DD, then give it the extension .abbu. I'd add it to the script, but the script is such a mess I'd feel compelled to rewrite it first, and that will have to wait till tomorrow.

[ Reply to This | # ]
Automate iCal backups
Authored by: Dave Creek on Aug 15, '10 09:36:15AM

Thank you, tedw
Dave



[ Reply to This | # ]
Automate iCal backups
Authored by: tedw on Aug 15, '10 11:24:43AM
Here's a modified script that handles both ical and address book. I've only tested it on 10.6 - it should work on 10.5, probably on 10.4, but no guarantees. Use at your own risk, and test it before using it. testing means:
  1. use the script to make a back up
  2. make a manual backup
  3. try restoring from the script-generated backup
  4. check to make sure it worked correctly
the script...
property keepFor : 10 * days -- how long to keep backups
property BUFoldName : "iCal and AB Backups" -- main backup folder name

-- set backup folder variables (creating if needed)
set dateStamp to ymdDateFormat(current date)
set mainBackupFolder to getFolder(BUFoldName, path to documents folder from user domain)
set iCalTimeStampedFolder to getFolder("iCal " & dateStamp, mainBackupFolder)
set ABTimeStampedFolder to getFolder("Address Book - " & dateStamp, mainBackupFolder)

tell application "Finder"
	-- find outdated backup files and move them to trash
	set oldBackups to files of mainBackupFolder where (name ends with ".icbu" or name ends with ".abbu") and modification date is less than ((get current date) - keepFor)
	delete oldBackups
	
	-- copy the folders *as folders* to the backup location, moving unneeded files and folders to trash
	if version ≥ 10.5 then
		-- iCal data location for Leopard and Snow Leopard
		set plistVers to "2.0"
		set iCalDuplicatedFold to (duplicate (folder "Calendars" of (path to library folder from user domain)) to iCalTimeStampedFolder)
		tell iCalDuplicatedFold
			set deletables to items whose name does not end with ".calendar"
		end tell
	else
		-- iCal data location for Tiger
		set plistVers to "1.0"
		set iCalDuplicatedFold to (duplicate (folder "iCal" of (path to application support from user domain)) to iCalTimeStampedFolder)
		tell iCalDuplicatedFold
			set deletables to {file "alarmsCache.plist"} & files whose name begins with "sync" and file extension is "plist"
		end tell
	end if
	delete deletables
	
	-- Address Book data location for all versions (I think)
	set ABDuplicatedFold to (duplicate (folder "AddressBook" of (path to application support from user domain)) to ABTimeStampedFolder)
	
	empty trash
end tell

tell application "System Events"
	-- make info.plist for the iCal folders
	set the rootDictionary to make new property list item with properties {kind:record}
	set the plistPath to (POSIX path of (iCalTimeStampedFolder as alias)) & "/info.plist"
	set plistFile to make new property list file with properties {contents:rootDictionary, name:plistPath}
	tell plistFile
		make new property list item at end of property list items with properties {kind:date, name:"date", value:(current date)}
		make new property list item at end of property list items with properties {kind:string, name:"version", value:plistVers}
	end tell
	
	-- convert folders to appropriate backup files
	set name of iCalTimeStampedFolder to name of iCalTimeStampedFolder & ".icbu"
	set name of ABTimeStampedFolder to name of ABTimeStampedFolder & ".abbu"
end tell

to ymdDateFormat(inDate) -- Old_date is text, not a date.
	--subroutine makes YYYY-MM-DD date strings from applescript date
	set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "-"}
	set outDate to (year of inDate & (month of inDate) * 1 & day of inDate) as text
	set AppleScript's text item delimiters to tid
	return outDate
end ymdDateFormat

to getFolder(f, p)
	-- subroutine returns reference to folder, creating folder if needed
	tell application "Finder"
		if exists folder f of p then
			return folder f of p
		else
			return (make new folder at p with properties {name:f})
		end if
	end tell
end getFolder


[ Reply to This | # ]