Available on crate feature
backup
only.Expand description
Online SQLite backup API.
To create a Backup
, you must have two distinct Connection
s - one
for the source (which can be used while the backup is running) and one for
the destination (which cannot). A Backup
handle exposes three methods:
step
will attempt to back up a specified number of pages,
progress
gets the current progress of the backup as of
the last call to step
, and
run_to_completion
will attempt to back up the
entire source database, allowing you to specify how many pages are backed up
at a time and how long the thread should sleep between chunks of pages.
The following example is equivalent to “Example 2: Online Backup of a Running Database” from SQLite’s Online Backup API documentation.
fn backup_db<P: AsRef<Path>>(
src: &Connection,
dst: P,
progress: fn(backup::Progress),
) -> Result<()> {
let mut dst = Connection::open(dst)?;
let backup = backup::Backup::new(src, &mut dst)?;
backup.run_to_completion(5, time::Duration::from_millis(250), Some(progress))
}
Structs
- A handle to an online backup.
- Struct specifying the progress of a backup. The percentage completion can be calculated as
(pagecount - remaining) / pagecount
. The progress of a backup is as of the last call tostep
- if the source database is modified after a call tostep
, the progress value will become outdated and potentially incorrect.
Enums
- Possible successful results of calling
Backup::step
.