Export entire database to filesystem for backup

I would like to export all groups and files in a database to an external hard drive for archival purposes. Essentially, this would be a recursive process that creates a directory on the filesystem for each Group in the database, then executes a “File > Export > Files and Folders” process for all the files in that Group. I am a novice at scripting DT3… Does anyone have any suggestions for how to do this?

I’m not sure why you would need to script this – just do an Export > Files and Folders periodically. If you are looking to backup the database, then exporting is not needed – just back it up.

This works, but it requires going into each group (and all subgroups) and manually selecting all files and folders to export. Given all the groups in my database, this will take far too long. This the need for a means of automating it.

In addition to backing up the database, I need the data organized as directories and files for archival purposes.

Hi @timj -

It does not require selecting all groups manually. I have done this for a long time on DTPO, and I just checked and it works fine on DT3 also.

On DTPO you can select any group in a database, and then do Cmd-A, and it will expand the selection to all groups in that database (and all files and nested subgroups). Then you can do Opt-Cmd-E to export all those, and everything in the database is saved.

On DT3, the selection process is slight different, but the results are the same, groups, nested sub-groups to any level, and all files within are exported, and the exported structure matches your DB organization.

On DT3, you must go the sidebar to the name of the DB, and select that with your mouse, and the do Cmd-A, and that expands the selection to all groups and files. Then do Opt-Cmd-E, and select your output location.

Now all that being said, I have meant to script this, since I have 4 databases, and I do it manually for each of the 4 every couple weeks or so. It sounds like you have a single DB, so it would not be much of an issue either way.

(I do this as an adjunct to my normal disk backups which include my Devon databases, not as a replacement.)

1 Like

Not necessary.

Exactly. And again, no need to script if you have a macro or keyboard shortcut app such as KeyboardMaestro, Typinator, etc. Just turn the two DEVONthink shortcuts into one macro.

Anyway, if you really want a script then use this. Use at your own risk. Tested to work here, but I don’t have your data and no support will be provided:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application id "DNtp"
	set theDB to every record of the current database
	set theDestination to "~/Downloads/DBE"
	repeat with thisItem in theDB
		set theResult to export record thisItem to theDestination
	end repeat
end tell

If the destination folder does not exist, the folder will create it. If the destination folder does exist, the script will create a duplicate folder for everything exported. A more sophisticated script could catch that behavior.

I’m looking for something like this too.

I have an archive Database in an external “hard drive”
I put everything I don’t need anymore to this external hard drive.

Currently I do it manually.

Thanks @paul99! This works perfectly. I don’t know what I was doing wrong before, but the Export option in the menu item was greyed out when I selected multiple groups. Now it is functioning exactly as you described above. Much appreciated.

Thanks, @korm, I appreciate the help with the script.