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, RestorePlanError};
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    InvalidPlan(#[from] RestorePlanError),
25
26    #[error(transparent)]
27    InvalidJournal(#[from] RestoreApplyJournalError),
28
29    #[error(transparent)]
30    Persistence(#[from] PersistenceError),
31}
32
33/// Durably replace one serialized restore plan.
34pub fn write_restore_plan(path: &Path, plan: &RestorePlan) -> Result<(), RestorePersistenceError> {
35    plan.validate()?;
36    write_json_durable(path, plan)?;
37    Ok(())
38}
39
40/// Validate and durably replace one restore apply journal.
41pub fn write_restore_apply_journal(
42    path: &Path,
43    journal: &RestoreApplyJournal,
44) -> Result<(), RestorePersistenceError> {
45    journal.validate()?;
46    write_json_durable(path, journal)?;
47    Ok(())
48}