Modfying the Export/Daily Backup Archive Script

This question was already asked here, but no answer was given (to this particular part of the question).

I would like to modify the script Export/Daily Backup Archive so that instead of backing up the current database only, it instead backups all (three, in my case) databases. Unfortunately I am not familiar with applescript, and don’t know how to do this.

The relevant line in the script seems to be:

set this_database to current database

You have to use a loop instead:

repeat with this_database in databases
end repeat
1 Like

Thanks, I changed the script to:

tell application id "DNtp"
		repeat with this_database in databases
			set this_date to do shell script "date +%y-%m-%d"
			set this_path to path of this_database
			set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
			set this_name to the last text item of this_path
			set AppleScript's text item delimiters to ""
			if this_name ends with ".dtBase2" then set this_name to (characters 1 thru -9 of this_name) as string
			set this_archive to "~/Backup/" & this_name & " " & this_date & ""
			set AppleScript's text item delimiters to od
			show progress indicator "Daily Backup Archive" steps 3
			with timeout of 1200 seconds
				step progress indicator "Verifying..."
				if (verify database this_database) is not 0 then error "Database is damaged."
				step progress indicator "Optimizing..."
				if not (optimize database this_database) then error "Optimization of database failed."
				step progress indicator "Zipping..."
				if not (compress database this_database to this_archive) then error "Backup failed."
			end timeout
			hide progress indicator
		end repeat
	on error error_message number error_number
		hide progress indicator
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell

This seems to work fine, apart from after it’s finished it hangs for a while and then eventually displays a “Database is damaged” message. This is after it’s correctly zipped all my (= 3) databases, so perhaps it is trying to run again on a non-existent fourth database? Or did I do something wrong with the script?

1 Like

Please verify all databases (and the global inbox too) via File > Verify & Repair Database…