SQLite Online Backup API
The SQLite Online Backup API copies one named database between distinct connections using an explicit initialization, page-copy and cleanup sequence.
A step returning SQLITE_OK leaves pages to copy; SQLITE_DONE marks completion. Finishing early rolls back an active destination transaction, yet finish can return SQLITE_OK. Cleanup is not completion. [1]
On SQLite 3.45.1, no-step and partial-copy cancellation preserved old destination rows. All four reopened copies passed integrity_check with equal row counts; only completion matched the source. Lock abandonment returned BUSY from step and finish. This matches the pinned code but differs from the API prose. [4] [3]
In 21 controlled runs, other-connection writes repeatedly reset copying without BUSY; same-handle writes preserved progress. A pinned WAL view also preserved progress but copied generation 10 while the latest was 16. Copies completed after writers stopped. Six rounds are not an infinite-run measurement. [6] [7]
In 84 synthetic runs on two builds, complete and cancelled backups left a caller-owned read active. BEGIN alone did not retain a read between steps; BEGIN plus SELECT did. Per-schema transaction state separates them. [8] [10]
With that read retained, journal_size_limit=0 did not cap the live WAL. Ending it allowed truncation without closing the connection. Clean up only transactions owned by the operation, not unrelated pooled work. [9] [11]
Completed copies can preserve an existing semantic inconsistency. In two tested builds, backups retained historical stale generated values and indexes; STORED cases still passed integrity_check. Check derivation, consumer queries and completeness separately from SQLITE_DONE. The newer build rejects the older BLOB mutation used to prepare these inputs. [12]
Relations
- related
- Backup, Backup verification, Restore test, SQLite WAL end mark, Rollback journal, Storage snapshot, SQLite rowid, SQLite AUTOINCREMENT, Checkpoint starvation, SQLite transaction state, SQLite serialization, SQLite snapshot handle
Limitations
- Serialization can retain a writer's uncommitted rows; it is a different export path. [13]
- A writable WAL or initialized-memory destination can reject a page-size mismatch with SQLITE_READONLY; read back effective settings before copying. [1] [14]
- On the tested mismatch paths, zero remaining pages and integrity_check=ok coexisted with valid old target rows. Neither check proves that the intended copy completed. [15]
Citations
- SQLite C API: Online Backup API.
- SQLite version-3.45.1: backup.c, step status and finish return.
- Hesela: SQLite lock-abandonment experiment and controls.
- Hesela: native API experiment receipt and runtime identity.
- Hesela: backup progress, writer identity and retained source views.
- Hesela: 21 native backup-progress observations, build identity and hashes.
- Hesela: two-build source-read retention experiment, derived summary and receipt hashes
- SQLite: PRAGMA journal_size_limit, retained file size and reset
- SQLite: per-schema transaction state
- Hesela: source-read ownership after backup cleanup, method and limitations
- Hesela: native recovery-copy controls, exact build scope and source synthesis
- Hesela: controlled SQLite serialization and source-commit provenance
- SQLite: PRAGMA page_size and deferred conversion
- Hesela: native SQLite destination-compatibility observations, method and reproduction
Further reading
Sources & caveats
- Constructed data; native C API calls through Python ctypes. Full build identity and hashes are in the receipt. [5]
- The experiment tests controlled abandonment, not process crashes, power failures, whole-application recovery or source freshness.
- 160 synthetic recovery configurations on recorded SQLite 3.45.1 and 3.54.1 builds; old-build seeds, closed files, two source journal settings. Not an incidence estimate or new vulnerability. Exact captures and reproduction package linked from the analysis.
- Destination compatibility: 240 constructed observations, 15 target profiles, 4096/8192-byte pages, DELETE/WAL sources, two repeats and recorded SQLite 3.45.1/3.54.1 builds. Ordinary-write and full-row controls; not a crash or field-rate study. [15]