Script to rebuild or restore a database nightly?

I share a DTPO database online. My users upload documents to my database using its web interface. A file they upload named filename.txt will appear in DTOP as C:\fakepath\filename.txt. I would like to clear these files out, automatically, at midnight every night.

I made a crontab command to run a perl script that deletes any file with fakepath in its name. However, the DTPO database continues to remember these files, and shows them as missing files, until I rebuild the database.

I would like this to get cleaned up automatically, but I can’t figure out how to rebuild a database from the command line or using Applescript or Automator.

I also thought of just running the “Restore Backup” command every night using an archived (clean) backup, but I can’t figure out a way to do that automatically either.

Any ideas? I don’t care how this gets done.

Thanks in advance!

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.

Korn, I really appreciate your prompt reply. I am struggling with this and may write back with a coherent question if I can come up with one. In the meantime I didn’t want you to think I wasn’t grateful for your assistance.