diff --git a/src/api2/admin/datastore/backup.rs b/src/api2/admin/datastore/backup.rs index 365a9900..75724078 100644 --- a/src/api2/admin/datastore/backup.rs +++ b/src/api2/admin/datastore/backup.rs @@ -73,14 +73,19 @@ 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 (path, is_new) = datastore.create_backup_dir(&backup_dir)?; if !is_new { bail!("backup directorty already exists."); } WorkerTask::spawn("backup", Some(worker_id), &username.clone(), true, move |worker| { - let backup_env = BackupEnvironment::new( + let mut backup_env = BackupEnvironment::new( env_type, username.clone(), worker.clone(), datastore, backup_dir, path); + + backup_env.last_backup = last_backup; + let service = BackupService::new(backup_env, worker.clone()); let abort_future = worker.abort_future(); diff --git a/src/api2/admin/datastore/backup/environment.rs b/src/api2/admin/datastore/backup/environment.rs index 8efa7abe..04c5a209 100644 --- a/src/api2/admin/datastore/backup/environment.rs +++ b/src/api2/admin/datastore/backup/environment.rs @@ -27,6 +27,7 @@ pub struct BackupEnvironment { pub datastore: Arc, pub backup_dir: BackupDir, pub path: PathBuf, + pub last_backup: Option, state: Arc> } @@ -54,6 +55,7 @@ impl BackupEnvironment { formatter: &JSON_FORMATTER, backup_dir, path, + last_backup: None, state: Arc::new(Mutex::new(state)), } } diff --git a/src/backup/backup_info.rs b/src/backup/backup_info.rs index 85447e8c..a776440b 100644 --- a/src/backup/backup_info.rs +++ b/src/backup/backup_info.rs @@ -161,7 +161,7 @@ impl From<(BackupGroup, i64)> for BackupDir { } /// Detailed Backup Information, lists files inside a BackupDir -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct BackupInfo { /// the backup directory pub backup_dir: BackupDir, diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index 8696cc3a..4caef3bc 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -168,6 +168,16 @@ 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();