src/backup/datastore.rs: move last_backup to BackupInfo
This commit is contained in:
parent
b02a52e3a5
commit
51a4f63ff7
|
@ -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."); }
|
||||
|
|
|
@ -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<Option<BackupInfo>, 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<BackupInfo>, ascendending: bool) {
|
||||
if ascendending { // oldest first
|
||||
list.sort_unstable_by(|a, b| a.backup_dir.backup_time.cmp(&b.backup_dir.backup_time));
|
||||
|
|
|
@ -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<Option<BackupInfo>, 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<Vec<PathBuf>, Error> {
|
||||
let base = self.base_path();
|
||||
|
||||
|
|
Loading…
Reference in New Issue