# Backup all open databases

**URL:** <https://discourse.devontechnologies.com/t/backup-all-open-databases/50932>\
**Category:** Automation\
**Created:** [October 11, 2019, 4:50pm UTC](https://discourse.devontechnologies.com/t/backup-all-open-databases/50932 "2019-10-11T16:50:59Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![jsn](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/j/e56c9b/32.png) [@jsn](https://discourse.devontechnologies.com/u/jsn)\
**Post date:** [June 9, 2022, 8:35pm UTC](https://discourse.devontechnologies.com/t/backup-all-open-databases/50932/13 "2022-06-09T20:35:10Z")

</div>

```auto
-- Daily backup archive - all open databases
-- Created by Christian Grunenberg on Mon Jun 22 2009.
-- Copyright (c) 2009-2022. All rights reserved.
-- addition for all open databases by coolgoose85
-- https://discourse.devontechnologies.com/t/backup-all-open-databases/50932
-- Modifications courtesy of chrillek's advice: https://discourse.devontechnologies.com/t/backup-all-open-databases/50932/12

tell application id "DNtp"
	
	set this_date to do shell script "date +%Y-%m-%d-%H-%M-%S"
	set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
	set all_databases to every database
	
	repeat with this_database in all_databases
		try
			set this_path to path of this_database
			set this_name to the last text item of this_path
			if this_name ends with ".dtBase2" then set this_name to (characters 1 thru -9 of this_name) as string
			set this_archive to "/Volumes/YourBackupDriveName/Backup/" & this_name & " " & this_date & ".dtBase2.zip" -- was ˜Backup before, which created a folder under documents.
			
			show progress indicator "Daily Backup Archive of " & this_archive steps 3
			
			with timeout of 3600 seconds
				step progress indicator "Verifying database " & this_name & "..."
				if (verify database this_database) is not 0 then error "Database " & this_name & " is damaged."
				
				step progress indicator "Optimizing database " & this_name & "..."
				if not (optimize database this_database) then error "Optimization of database " & this_name & "failed."
				
				step progress indicator "Zipping database " & this_name & "..."
				if not (compress database this_database to this_archive) then error "Backup of database " & this_name & "failed."
			end timeout
			
			hide progress indicator
		on error error_message number error_number
			hide progress indicator
			if the error_number is not -128 then log message "DEVONthink:" & error_message
		end try
	end repeat
	
	set AppleScript's text item delimiters to od
end tell

```

Thanks for all of the tips.  
I think I got everything but please if anybody sees a comment I missed or something I did wrong, correct it or let me know and I’ll correct it. I put the web links in the comments so that if anybody copies the script, they know where they got it and where they can go back to reference it.

I also changed the thisDatabase to this\_database to stick with snake case convention.  
And I changed the : to - in the time generation.

I did go through privacy parameters, but I think I’ve granted all the access that DEVONthink 3 requests in System Parameters, but I still have the error in my script. It’s an error that acts like a warning because the name is generated just fine. So perhaps I will see if there is a list of Privacy Parameters and make a visual guide to the System Parameters window. Wish all developers would make these parameter windows expandable and searchable with filters. Seems more logical to me if I could just type DEVONthink and then be shown all the settings related and check the boxes…

---

_[View the full topic](https://discourse.devontechnologies.com/t/backup-all-open-databases/50932)._
