Koskamo

Online backup with the Backup API

Document v1 · published by Koskamo editorial · updated 2026-10-04

Original source

The SQLite Online Backup API copies the contents of one database into another while the source is running, replacing the historical approach of taking a shared lock on the database file, copying it with an external tool such as the unix cp utility, and releasing the lock — a method that works well in many scenarios and is usually very fast but has documented shortcomings. The pattern is three calls: sqlite3_backup_init() creates an sqlite3_backup object to copy data between two databases, from a file into an in-memory database or vice-versa; sqlite3_backup_step() copies pages, and a parameter of -1 copies the entire source database to the destination; sqlite3_backup_finish() releases the object, with errors read via sqlite3_errcode() on the destination connection. For progress reporting, sqlite3_backup_remaining() and sqlite3_backup_pagecount() return the pages left to copy and the total pages, as stored by the previous step call. Step in small batches on busy databases so concurrent readers are not held off (Koskamo editorial guidance). Scope: SQLite. Reviewed October 4, 2026.

Source and provenance

Original source
sqlite.org
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.