pub fn backup_pager_to_path<F: FileBackend>(
source: &Pager<F>,
snapshot: &ReaderSnapshot<F>,
dest: impl AsRef<Path>,
) -> Result<()>Expand description
Build a self-contained .obj file at dest carrying the state
of source as of snapshot.pinned_lsn().
snapshot MUST have been taken against source and not yet
dropped; the pin keeps the source’s WAL frames at-or-below the
pinned LSN from being reclaimed while the backup runs.
§Algorithm
- Refuse to overwrite an existing
dest(create_new). - Copy main-file pages
0..source.page_count()byte-for-byte. - Overlay every frame in the snapshot’s frozen WAL view onto the destination at its page-id offset.
- If the snapshot’s frozen view carries a page-0 header frame, overlay that on top of the main-file copy of page 0.
- Patch the destination header: zero
wal_salt, recompute the header CRC32C. sync_data(SyncMode::Full)on the destination.
On any mid-backup error the destination file is removed best- effort so a half-written backup does not linger.
§Errors
Error::BackupDestinationExistsifdestalready exists.Error::BackupNotSupportedForMemoryPagerifsourceis an in-memory pager.Error::Ioon any syscall failure during the copy.Error::InvalidFormat/Error::Corruptionpropagated from the source header decode (the source’s header bytes are re-encoded with the WAL-staged values applied).