src/backup/datastore.rs: split BackupDir
This commit is contained in:
parent
38b0dfa511
commit
dc4c09faae
@ -22,7 +22,7 @@ fn group_backups(backup_list: Vec<BackupInfo>) -> HashMap<String, Vec<BackupInfo
|
||||
let mut group_hash = HashMap::new();
|
||||
|
||||
for info in backup_list {
|
||||
let group_id = format!("{}/{}", info.backup_dir.backup_type, info.backup_dir.backup_id);
|
||||
let group_id = format!("{}/{}", info.backup_dir.group.backup_type, info.backup_dir.group.backup_id);
|
||||
let time_list = group_hash.entry(group_id).or_insert(vec![]);
|
||||
time_list.push(info);
|
||||
}
|
||||
@ -223,8 +223,8 @@ fn get_backup_list(
|
||||
|
||||
for info in datastore.list_backups()? {
|
||||
list.push(json!({
|
||||
"backup_type": info.backup_dir.backup_type,
|
||||
"backup_id": info.backup_dir.backup_id,
|
||||
"backup_type": info.backup_dir.group.backup_type,
|
||||
"backup_id": info.backup_dir.group.backup_id,
|
||||
"backup_time": info.backup_dir.backup_time.timestamp(),
|
||||
"files": info.files,
|
||||
}));
|
||||
|
@ -146,8 +146,10 @@ fn download_catar(
|
||||
let datastore = DataStore::lookup_datastore(store)?;
|
||||
|
||||
let backup_dir = BackupDir {
|
||||
group: BackupGroup {
|
||||
backup_type: backup_type.to_string(),
|
||||
backup_id: backup_id.to_string(),
|
||||
},
|
||||
backup_time,
|
||||
};
|
||||
|
||||
|
@ -26,13 +26,34 @@ pub struct DataStore {
|
||||
gc_mutex: Mutex<bool>,
|
||||
}
|
||||
|
||||
/// Uniquely identify backups (relative to data store)
|
||||
/// Group Backups
|
||||
#[derive(Debug)]
|
||||
pub struct BackupDir {
|
||||
pub struct BackupGroup {
|
||||
/// Type of backup
|
||||
pub backup_type: String,
|
||||
/// Unique (for this type) ID
|
||||
pub backup_id: String,
|
||||
}
|
||||
|
||||
impl BackupGroup {
|
||||
|
||||
pub fn group_path(&self) -> PathBuf {
|
||||
|
||||
let mut relative_path = PathBuf::new();
|
||||
|
||||
relative_path.push(&self.backup_type);
|
||||
|
||||
relative_path.push(&self.backup_id);
|
||||
|
||||
relative_path
|
||||
}
|
||||
}
|
||||
|
||||
/// Uniquely identify a Backup (relative to data store)
|
||||
#[derive(Debug)]
|
||||
pub struct BackupDir {
|
||||
/// Backup group
|
||||
pub group: BackupGroup,
|
||||
/// Backup timestamp
|
||||
pub backup_time: DateTime<Utc>,
|
||||
}
|
||||
@ -41,11 +62,7 @@ impl BackupDir {
|
||||
|
||||
pub fn relative_path(&self) -> PathBuf {
|
||||
|
||||
let mut relative_path = PathBuf::new();
|
||||
|
||||
relative_path.push(&self.backup_type);
|
||||
|
||||
relative_path.push(&self.backup_id);
|
||||
let mut relative_path = self.group.group_path();
|
||||
|
||||
let date_str = self.backup_time.format("%Y-%m-%dT%H:%M:%S").to_string();
|
||||
|
||||
@ -249,8 +266,10 @@ impl DataStore {
|
||||
|
||||
list.push(BackupInfo {
|
||||
backup_dir: BackupDir {
|
||||
group: BackupGroup {
|
||||
backup_type: backup_type.to_owned(),
|
||||
backup_id: backup_id.to_owned(),
|
||||
},
|
||||
backup_time: dt,
|
||||
},
|
||||
files,
|
||||
|
Loading…
Reference in New Issue
Block a user