backup_info: BackupDir shortcut
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
93b49ce38a
commit
391d310741
@ -98,7 +98,7 @@ fn delete_snapshots (
|
||||
let backup_id = tools::required_string_param(¶m, "backup-id")?;
|
||||
let backup_time = tools::required_integer_param(¶m, "backup-time")?;
|
||||
|
||||
let snapshot = BackupDir::new(BackupGroup::new(backup_type, backup_id), backup_time);
|
||||
let snapshot = BackupDir::new(backup_type, backup_id, backup_time);
|
||||
|
||||
let datastore = DataStore::lookup_datastore(store)?;
|
||||
|
||||
|
@ -80,7 +80,7 @@ fn upload_catar(
|
||||
verify_chunk_size(chunk_size)?;
|
||||
|
||||
let datastore = DataStore::lookup_datastore(store)?;
|
||||
let backup_dir = BackupDir::new(BackupGroup::new(backup_type, backup_id), backup_time);
|
||||
let backup_dir = BackupDir::new(backup_type, backup_id, backup_time);
|
||||
|
||||
let (mut path, _new) = datastore.create_backup_dir(&backup_dir)?;
|
||||
|
||||
@ -144,7 +144,7 @@ fn download_catar(
|
||||
|
||||
let datastore = DataStore::lookup_datastore(store)?;
|
||||
|
||||
let backup_dir = BackupDir::new(BackupGroup::new(backup_type, backup_id), backup_time);
|
||||
let backup_dir = BackupDir::new(backup_type, backup_id, backup_time);
|
||||
|
||||
let mut path = backup_dir.relative_path();
|
||||
|
||||
|
@ -92,9 +92,16 @@ pub struct BackupDir {
|
||||
|
||||
impl BackupDir {
|
||||
|
||||
pub fn new(group: BackupGroup, timestamp: i64) -> Self {
|
||||
pub fn new<T, U>(backup_type: T, backup_id: U, timestamp: i64) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
U: Into<String>,
|
||||
{
|
||||
// Note: makes sure that nanoseconds is 0
|
||||
Self { group, backup_time: Local.timestamp(timestamp, 0) }
|
||||
Self {
|
||||
group: BackupGroup::new(backup_type.into(), backup_id.into()),
|
||||
backup_time: Local.timestamp(timestamp, 0),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn group(&self) -> &BackupGroup {
|
||||
@ -112,7 +119,7 @@ impl BackupDir {
|
||||
|
||||
let group = BackupGroup::new(cap.get(1).unwrap().as_str(), cap.get(2).unwrap().as_str());
|
||||
let backup_time = cap.get(3).unwrap().as_str().parse::<DateTime<Local>>()?;
|
||||
Ok(BackupDir::new(group, backup_time.timestamp()))
|
||||
Ok(BackupDir::from((group, backup_time.timestamp())))
|
||||
}
|
||||
|
||||
pub fn relative_path(&self) -> PathBuf {
|
||||
@ -125,6 +132,12 @@ impl BackupDir {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(BackupGroup, i64)> for BackupDir {
|
||||
fn from((group, timestamp): (BackupGroup, i64)) -> Self {
|
||||
Self { group, backup_time: Local.timestamp(timestamp, 0) }
|
||||
}
|
||||
}
|
||||
|
||||
/// Detailed Backup Information, lists files inside a BackupDir
|
||||
#[derive(Debug)]
|
||||
pub struct BackupInfo {
|
||||
@ -165,7 +178,7 @@ impl BackupInfo {
|
||||
})?;
|
||||
|
||||
list.push(BackupInfo {
|
||||
backup_dir: BackupDir::new(BackupGroup::new(backup_type, backup_id), dt.timestamp()),
|
||||
backup_dir: BackupDir::new(backup_type, backup_id, dt.timestamp()),
|
||||
files,
|
||||
});
|
||||
|
||||
|
@ -111,7 +111,7 @@ fn list_backups(
|
||||
let btype = item["backup-type"].as_str().unwrap();
|
||||
let epoch = item["backup-time"].as_i64().unwrap();
|
||||
|
||||
let backup_dir = BackupDir::new(BackupGroup::new(btype, id), epoch);
|
||||
let backup_dir = BackupDir::new(btype, id, epoch);
|
||||
|
||||
let files = item["files"].as_array().unwrap().iter().map(|v| v.as_str().unwrap().to_owned()).collect();
|
||||
|
||||
@ -203,7 +203,7 @@ fn list_snapshots(
|
||||
let btype = item["backup-type"].as_str().unwrap();
|
||||
let epoch = item["backup-time"].as_i64().unwrap();
|
||||
|
||||
let snapshot = BackupDir::new(BackupGroup::new(btype, id), epoch);
|
||||
let snapshot = BackupDir::new(btype, id, epoch);
|
||||
|
||||
let path = snapshot.relative_path().to_str().unwrap().to_owned();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user