Progrider

Programming discussion

Board index
Help✓ Resolved

Copying a live sqlite file, is that safe?

My backup script just does cp readings.db /mnt/backup/. The app is in WAL mode and writes every few seconds. Restoring from one of these backups gave me a database that was missing the last hour or so. Is cp the wrong tool here?

2 replies

cp on a live WAL database can give you a file with the WAL half-applied. Use sqlite3 readings.db ".backup /mnt/backup/readings.db" or the VACUUM INTO command. Both produce a consistent snapshot.
Switched the script to .backup, restore test came back with everything. Thanks.

Discussion resolved

This discussion is resolved. Its creator can reopen it to accept more replies.