Skip to content

Commit

Permalink
Assert that all subdirs have the same number of incremental backups
Browse files Browse the repository at this point in the history
  • Loading branch information
jfldde committed Feb 6, 2025
1 parent 19e8c40 commit 7090674
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions crates/common/src/backup/manager.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};
use std::sync::{Arc, RwLock};
use std::time::{Instant, SystemTime, UNIX_EPOCH};
Expand Down Expand Up @@ -345,6 +345,7 @@ impl BackupManager {
bail!("Backup directory does not exist: {:?}", backup_path);
}

let mut sizes = HashSet::new();
for dir in &self.config.backup_dirs {
let path = backup_path.join(dir);
if !path.exists() {
Expand All @@ -355,7 +356,12 @@ impl BackupManager {
bail!("Directory '{}' is empty ", dir);
}

validate_backup(&path)?;
let backup_size = validate_backup(&path)?;
sizes.insert(backup_size);
}

if sizes.len() != 1 {
bail!("Backup is corrupted. Each sub-dir should have the same number of incremental backups")
}

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/backup/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(super) fn restore_from_backup(
Ok(())
}

pub(super) fn validate_backup(backup_path: impl AsRef<Path>) -> anyhow::Result<()> {
pub(super) fn validate_backup(backup_path: impl AsRef<Path>) -> anyhow::Result<usize> {
let backup_path = backup_path.as_ref();
if !backup_path.exists() {
bail!("Backup directory does not exist at {:?}", backup_path);
Expand Down Expand Up @@ -75,7 +75,7 @@ pub(super) fn validate_backup(backup_path: impl AsRef<Path>) -> anyhow::Result<(

backup_engine.verify_backup(backup_id)?;
}
Ok(())
Ok(backups.len())
}

pub(super) fn get_backup_engine(backup_path: impl AsRef<Path>) -> anyhow::Result<BackupEngine> {
Expand Down

0 comments on commit 7090674

Please sign in to comment.