Skip to main content

canic_backup/restore/persistence/
mod.rs

1//! Module: restore::persistence
2//!
3//! Responsibility: validate and durably persist restore recovery documents.
4//! Does not own: restore planning, journal transitions, or generic CLI output.
5//! Boundary: exposes typed plan/journal writes backed by backup-owned durable IO.
6
7use super::{RestoreApplyJournal, RestoreApplyJournalError, RestorePlan};
8use crate::persistence::{PersistenceError, write_json_durable};
9
10use std::path::Path;
11
12use thiserror::Error as ThisError;
13
14///
15/// RestorePersistenceError
16///
17/// Typed validation or durable-write failure for restore recovery documents.
18/// Owned by restore persistence and returned to CLI and runner callers.
19///
20
21#[derive(Debug, ThisError)]
22pub enum RestorePersistenceError {
23    #[error(transparent)]
24    InvalidJournal(#[from] RestoreApplyJournalError),
25
26    #[error(transparent)]
27    Persistence(#[from] PersistenceError),
28}
29
30/// Durably replace one serialized restore plan.
31pub fn write_restore_plan(path: &Path, plan: &RestorePlan) -> Result<(), RestorePersistenceError> {
32    write_json_durable(path, plan)?;
33    Ok(())
34}
35
36/// Validate and durably replace one restore apply journal.
37pub fn write_restore_apply_journal(
38    path: &Path,
39    journal: &RestoreApplyJournal,
40) -> Result<(), RestorePersistenceError> {
41    journal.validate()?;
42    write_json_durable(path, journal)?;
43    Ok(())
44}