I’ve been using the following script for a few years to backup all open DT databases. Barely understand AppleScript. No guarantees here. This was assembled from code I gathered from the support forum and elsewhere on the internet. It is on my toolbar.
It verifies, optimizes, and creates a dated zipped file of each of the open databases including the Inbox.
After it runs, I copy the files to an external HDD that is backed up to Backblaze.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "DEVONthink 3"
set theDatabases to every database
show progress indicator "Running Backup" steps (count of theDatabases)
repeat with thisDatabase in theDatabases
set this_database to thisDatabase
step progress indicator (name of this_database as string)
set this_date to do shell script "date +%Y-%m-%d-%H-%M-%S"
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 "~/DT_Backup/" & this_name & " " & this_date & ".dtBase2.zip"
set AppleScript's text item delimiters to od
with timeout of 1200 seconds
set thisMsg to "Verified: " & the name of thisDatabase & " with result "
set thisResultV to verify database this_database
set thisLog to log message (thisMsg & thisResultV & " errors and/or missing files")
if thisResultV = 0 then
set thisMsg to "Optimized: " & the name of thisDatabase & " with result "
set thisResultO to optimize database this_database
if not thisResultO then
set thisLog to log message (thisMsg & " Optimization of database failed.")
else
set thisLog to log message (thisMsg & " Optimization of database success.")
end if
if thisResultO then
set thisMsg to "Zipped: " & the name of thisDatabase & " with result "
set thisResultC to (compress database this_database to this_archive)
if not thisResultC then
set thisLog to log message (thisMsg & " zipped of database failed.")
else
set thisLog to log message (thisMsg & " zipped of database success.")
end if
end if
end if
end timeout
end repeat
hide progress indicator
display notification "DT backup finished."
end tell