Script to rebuild or restore a database nightly?

You didn’t mention if your users always upload to the same group in your database. For simplicity, let’s say they do. (If they don’t, then you could use a smart group to implement these suggestions.)

First - I strong advise you don’t use the cron job or any other means to remove or otherwise modify items from inside a DEVONthink database package (.dtBase2). That might work 9 times of out 10, and then destroy your database the 10th time. Let DEVONthink manage databases. By needing to rebuild the database daily, you’ve essentially recognized that the database is damaged and needs repair.

If instead you uploaded your documents to the same group, you could tie that group to an indexed folder in the file system, and do the following:

  1. Index the folder (say, call it “User Docs”) into your DEVONthink database
  2. Your remote users upload their stuff into the User Docs group in the database
  3. At this stage, you have documents in User Docs that are indexed and documents that are stored in the database. So, make everything indexed. This script can be modified to run on schedule – say, by using a cron job, Keyboard Maestro, etc.
  4. Now, after step 3, then another new cron job (or the other one, with a timer delay) can delete documents from the folder in the file system
  5. Then, all you need is a third, simple script, also launched by cron, that “synchronizes” the DEVONthink database User Docs group. Since because of step 4 the indexed folder will be empty, then the User Docs group will be empty, and you’re good to go for the next day.

As mentioned, all this can be accomplished with a smart group, in the case where you have multiple ingest points in your database for associate documents.