Backup all open databases


I have modified existing script “Daily backup archive” which is located at ~/Library/Application Scripts/com.devon-technologies.think3/Menu/Export/ to go through all the open databases and create the backup.

It also create back with date and time so that it can be created multiple times in a day instead of just once in a day.

Feel free to review it and let me know if anyone find any issues.

– Daily backup archive.
– Created by Christian Grunenberg on Mon Jun 22 2009.
– Copyright © 2009-2019. All rights reserved.

tell application id “DNtp”
set allDatabases to every database
repeat with thisDatabase in allDatabases
if not (exists thisDatabase) then error “No database is open.”
set this_database to thisDatabase

        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 "~/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
    on error error_message number error_number
        hide progress indicator
        if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
    end try
end repeat

end tell

It generates backup files as


You can create a script file as
touch script_name.scpt
open script_name.scpt
paste above code and put it in
~/Library/Application Scripts/com.devon-technologies.think3/Menu/Export

DEVONthink will pick up the new script and will show in UI

Thanks for the script! Just a reminder that it’s not recommended to replace/modify default scripts, it’s recommended to modify copies to avoid conflicts after updates.