canic_backup/restore/persistence/
mod.rs1use 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#[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
33pub fn write_restore_plan(path: &Path, plan: &RestorePlan) -> Result<(), RestorePersistenceError> {
35 plan.validate()?;
36 write_json_durable(path, plan)?;
37 Ok(())
38}
39
40pub 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}