diff --git a/src/backup/backup_info.rs b/src/backup/backup_info.rs index 1d42d79d..4dcf897a 100644 --- a/src/backup/backup_info.rs +++ b/src/backup/backup_info.rs @@ -45,6 +45,31 @@ pub struct BackupGroup { backup_id: String, } +impl std::cmp::Ord for BackupGroup { + + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + let type_order = self.backup_type.cmp(&other.backup_type); + if type_order != std::cmp::Ordering::Equal { + return type_order; + } + // try to compare IDs numerically + let id_self = self.backup_id.parse::(); + let id_other = other.backup_id.parse::(); + match (id_self, id_other) { + (Ok(id_self), Ok(id_other)) => id_self.cmp(&id_other), + (Ok(_), Err(_)) => std::cmp::Ordering::Less, + (Err(_), Ok(_)) => std::cmp::Ordering::Greater, + _ => self.backup_id.cmp(&other.backup_id), + } + } +} + +impl std::cmp::PartialOrd for BackupGroup { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + impl BackupGroup { pub fn new, U: Into>(backup_type: T, backup_id: U) -> Self { diff --git a/src/backup/verify.rs b/src/backup/verify.rs index fa2f0aa5..77706dfd 100644 --- a/src/backup/verify.rs +++ b/src/backup/verify.rs @@ -267,7 +267,7 @@ pub fn verify_all_backups(datastore: &DataStore, worker: &WorkerTask) -> Result< let mut errors = Vec::new(); - let list = match BackupGroup::list_groups(&datastore.base_path()) { + let mut list = match BackupGroup::list_groups(&datastore.base_path()) { Ok(list) => list, Err(err) => { worker.log(format!("verify datastore {} - unable to list backups: {}", datastore.name(), err)); @@ -275,6 +275,8 @@ pub fn verify_all_backups(datastore: &DataStore, worker: &WorkerTask) -> Result< } }; + list.sort_unstable(); + worker.log(format!("verify datastore {}", datastore.name())); for group in list {