Skip to main content

backup_pager_to_path

Function backup_pager_to_path 

Source
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

  1. Refuse to overwrite an existing dest (create_new).
  2. Copy main-file pages 0..source.page_count() byte-for-byte.
  3. Overlay every frame in the snapshot’s frozen WAL view onto the destination at its page-id offset.
  4. If the snapshot’s frozen view carries a page-0 header frame, overlay that on top of the main-file copy of page 0.
  5. Patch the destination header: zero wal_salt, recompute the header CRC32C.
  6. 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