Guide
Back up a SQLite database
A database backup should be a consistent copy that can actually be restored. SQLite provides backup facilities for copying a database while accounting for database state, which is more reliable than assuming an arbitrary copy of files during active writes is sufficient.
At a glance
- Programmatic facility
- SQLite Online Backup API
- Shell facility
- .backup command
Overview
A database backup should be a consistent copy that can actually be restored. SQLite provides backup facilities for copying a database while accounting for database state, which is more reliable than assuming an arbitrary copy of files during active writes is sufficient.
1. Choose a supported backup path
Use the SQLite backup API or the shell's documented backup command for the intended environment. Confirm the source database and choose a separate destination with enough space before starting the operation.
2. Handle completion and failure
Check the operation's result and preserve any reported error. A backup workflow should not overwrite its last known usable copy merely because a new attempt began.
3. Exercise restoration
Open the resulting backup separately and verify representative schema and data. A successful file creation is weaker evidence than a restore check that demonstrates the database can answer the queries your application needs.
Sources and review
MOOR's explanatory text is supported by the following source links.
- Online Backup API — SQLite
- Command-line shell — SQLite