14 A restore across a storage move
A record names the store its file is in. Restore a database from before a storage move, and its records name the store the file used to be in, while the file is safely in the other. They show as files missing, or as records naming a store this instance doesn't read, and nothing is actually lost. Repair the records rather than recovering files:
docker compose run --rm --no-deps worker ./node_modules/.bin/tsx --tsconfig tsconfig.worker.json src/lib/jobs/storage-reconcile.ts --repair-rows --dry-run
docker compose run --rm --no-deps worker ./node_modules/.bin/tsx --tsconfig tsconfig.worker.json src/lib/jobs/storage-reconcile.ts --repair-rows
It searches the stores this instance reads for each file its record's own store doesn't hold. It changes a record only when the
file reads back with the record's SHA-256, or its size for a record with no hash. It copies, moves and deletes no file, and each
batch is named in the audit log as storage.rows_repaired before it changes. It exits 0 when every record's file was found, and
stops asking a store that has failed, so run it again once the store answers.
To see what a store this instance doesn't use holds, keep that store's address in .env and add --look-in s3 or --look-in azure-blob
to the dry run. To point records there, the instance has to read it, or they could not be opened: set STORAGE_READ_FROM to that store
and restart first, and move the files off with the storage command afterward. Never do this in a drill or a copy: with that setting,
deleting a record there deletes production's file. A file that isn't in any store searched really is
missing, so recover it from a backup, versioning or soft delete.