diff --git a/src/api2/admin/datastore/backup.rs b/src/api2/admin/datastore/backup.rs index 75724078..2255df15 100644 --- a/src/api2/admin/datastore/backup.rs +++ b/src/api2/admin/datastore/backup.rs @@ -73,9 +73,9 @@ fn upgrade_to_backup_protocol( let username = rpcenv.get_user().unwrap(); let env_type = rpcenv.env_type(); - let last_backup = datastore.last_backup(backup_type, backup_id)?; - - let backup_dir = BackupDir::new(backup_type, backup_id, backup_time.timestamp()); + let backup_group = BackupGroup::new(backup_type, backup_id); + let last_backup = BackupInfo::last_backup(&datastore.base_path(), &backup_group)?; + let backup_dir = BackupDir::new_with_group(backup_group, backup_time.timestamp()); let (path, is_new) = datastore.create_backup_dir(&backup_dir)?; if !is_new { bail!("backup directorty already exists."); } diff --git a/src/backup/backup_info.rs b/src/backup/backup_info.rs index a776440b..4d80d06b 100644 --- a/src/backup/backup_info.rs +++ b/src/backup/backup_info.rs @@ -125,6 +125,9 @@ impl BackupDir { backup_time: Local.timestamp(timestamp, 0), } } + pub fn new_with_group(group: BackupGroup, timestamp: i64) -> Self { + Self { group, backup_time: Local.timestamp(timestamp, 0) } + } pub fn group(&self) -> &BackupGroup { &self.group @@ -171,6 +174,12 @@ pub struct BackupInfo { impl BackupInfo { + /// Finds the latest backup inside a backup group + pub fn last_backup(base_path: &Path, group: &BackupGroup) -> Result, Error> { + let backups = group.list_backups(base_path)?; + Ok(backups.into_iter().max_by_key(|item| item.backup_dir.backup_time())) + } + pub fn sort_list(list: &mut Vec, ascendending: bool) { if ascendending { // oldest first list.sort_unstable_by(|a, b| a.backup_dir.backup_time.cmp(&b.backup_dir.backup_time)); diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index 4caef3bc..8696cc3a 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -168,16 +168,6 @@ impl DataStore { } } - /// Finds the latest backup inside a backup group - pub fn last_backup(&self, backup_type: &str, backup_id: &str) -> Result, Error> { - let group = BackupGroup::new(backup_type, backup_id); - - let backups = group.list_backups(&self.base_path())?; - - Ok(backups.into_iter().max_by_key(|item| item.backup_dir.backup_time())) - } - - pub fn list_images(&self) -> Result, Error> { let base = self.base_path();