|
|
|
|
|
by rmunn
11 days ago
|
|
Have you read https://www.sqlite.org/howtocorrupt.html? Section 1.2 addresses the exact scenario you wrote about in "Backups are a file copy". You got lucky with your testing, and didn't manage to copy the database in the middle of writing a transaction to the WAL file. Backing up an SQLite database with `cp` can produce corrupt backups if you lose the race condition, an unlikely but possible scenario, Your later advice about "VACUUM INTO (backupfile)" is good, though: the SQLite manual guarantees that that's safe. But it's not safe to back up with `cp` if there are transactions currently writing to the DB: that has a chance of copying files in an inconsistent state, resulting in a corrupt DB and data loss you don't realize has happened until you restore the backup and find out there are some rows missing, or some rows have an invalid mix of old and new data. |
|