src/backup/datastore.rs: impl last_backup helper
This commit is contained in:
parent
c09775011a
commit
b02a52e3a5
@ -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();
|
||||
|
@ -27,6 +27,7 @@ pub struct BackupEnvironment {
|
||||
pub datastore: Arc<DataStore>,
|
||||
pub backup_dir: BackupDir,
|
||||
pub path: PathBuf,
|
||||
pub last_backup: Option<BackupInfo>,
|
||||
state: Arc<Mutex<SharedBackupState>>
|
||||
}
|
||||
|
||||
@ -54,6 +55,7 @@ impl BackupEnvironment {
|
||||
formatter: &JSON_FORMATTER,
|
||||
backup_dir,
|
||||
path,
|
||||
last_backup: None,
|
||||
state: Arc::new(Mutex::new(state)),
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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<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
Block a user