Backing up SQLite while it runs
28 Oct 2026 · sqlite
Copying the file with cp while a writer is active gives you a
torn database. The supported way is the online backup API, available from
the shell:
sqlite3 app.db ".backup '/backup/app-$(date +%F).db'"
It takes a read lock for the duration, so the writer keeps working and the copy is consistent. For large files I run it from a timer unit a few times a day and rotate weekly.