#readwise # Using the SQLite Online Backup API ![rw-book-cover](https://readwise-assets.s3.amazonaws.com/static/images/article4.6bc1851654a0.png) ## Metadata - Author: [[sqlite.org]] - Full Title: Using the SQLite Online Backup API - URL: https://www.sqlite.org/backup.html ## Summary The SQLite Online Backup API copies one database to another using `sqlite3_backup_init`, `sqlite3_backup_step`, and `sqlite3_backup_finish`. You can copy the whole database at once (step -1) or copy in small chunks (e.g., 5 pages) with sleeps between steps to avoid locking problems. Register a busy handler or timeout to handle `SQLITE_BUSY`, and note that differing page sizes can cause errors. Progress comes from `sqlite3_backup_remaining` and `sqlite3_backup_pagecount`, but concurrent writes can restart the backup or make progress numbers temporarily wrong. ## Highlights **The online backup API allows the contents of one database to be copied into another database file, replacing any original contents of the target database. The copy operation may be done incrementally, in which case the source database does not need to be locked for the duration of the copy, only for the brief periods of time when it is actually being read from.** This allows other database users to continue without excessive delays while a backup of an online database is made. **The effect of completing the backup call sequence is to make the destination a bit-wise identical copy of the source database as it was when the copying commenced.** (The destination becomes a "snapshot.") ^aomsjt ([View Highlight](https://read.readwise.io/read/01k2vnjgwrrmexzg5vsfq0txdb)) ---