2 Keep the database and files in step
A record names its file by a stored name. Every name is new, and a stored file is never overwritten. A file only ever appears or goes away, so restores are simpler than they could be:
- Back up the database first, then the files.
deploy/backup.shdoes. A file uploaded between the two has no record, which harms nothing and shows up as an orphan. - The one gap: a file deleted between the two steps is named by the dump and missing from the archive. Keep the time between them short. On a store with versioning or soft delete, it can be brought back.
- Files from a later time than the database do no damage where they are, and may be all that is left of
that work. They have no record, so nothing in the application opens them, and each may be the only copy of
something uploaded since the backup. The daily comparison counts them. Review them before removing any: the
removal commands refuse for 90 days after
restore:finish, whatever age you give, and refuse outright when the store shows the database went back in time andrestore:finishhasn't run. The store keeps a small file,audit-high-water.json, for that: keep it with the files, and if a drill copy shared the store and left a false alarm on production, delete that one file. - A database from a later time than the files is the problem. Its records name files you do not have. Those records still open, and their downloads fail. So keep file protection at least as long as database backups: if you can restore the database to 35 days ago, deleted files must still be recoverable from 35 days ago.
- Deleted data comes back with an older backup. Files deleted for privacy reasons return when you restore an earlier archive or undelete from a store. Your privacy documentation should say how long backups last. After a restore, repeat any erasure carried out since the backup.