src/api2/admin/datastore.rs - prune: log info about all snapshots
This commit is contained in:
parent
02d22dec4d
commit
8f0b4c1f90
@ -314,7 +314,7 @@ fn prune(
|
||||
|
||||
let list = group.list_backups(&datastore.base_path())?;
|
||||
|
||||
let remove_list = BackupGroup::compute_prune_list(
|
||||
let mut prune_info = BackupGroup::compute_prune_info(
|
||||
list,
|
||||
param["keep-last"].as_u64(),
|
||||
param["keep-daily"].as_u64(),
|
||||
@ -323,9 +323,15 @@ fn prune(
|
||||
param["keep-yearly"].as_u64(),
|
||||
)?;
|
||||
|
||||
for info in remove_list {
|
||||
worker.log(format!("remove {:?}", info.backup_dir));
|
||||
datastore.remove_backup_dir(&info.backup_dir)?;
|
||||
prune_info.reverse(); // delete older snapshots first
|
||||
|
||||
for (info, keep) in prune_info {
|
||||
if keep {
|
||||
worker.log(format!("keep {:?}", info.backup_dir.relative_path()));
|
||||
} else {
|
||||
worker.log(format!("remove {:?}", info.backup_dir.relative_path()));
|
||||
datastore.remove_backup_dir(&info.backup_dir)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -128,14 +128,14 @@ impl BackupGroup {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compute_prune_list(
|
||||
pub fn compute_prune_info(
|
||||
mut list: Vec<BackupInfo>,
|
||||
keep_last: Option<u64>,
|
||||
keep_daily: Option<u64>,
|
||||
keep_weekly: Option<u64>,
|
||||
keep_monthly: Option<u64>,
|
||||
keep_yearly: Option<u64>,
|
||||
) -> Result<Vec<BackupInfo>, Error> {
|
||||
) -> Result<Vec<(BackupInfo, bool)>, Error> {
|
||||
|
||||
let mut mark = HashMap::new();
|
||||
|
||||
@ -190,19 +190,18 @@ impl BackupGroup {
|
||||
});
|
||||
}
|
||||
|
||||
let mut remove_list: Vec<BackupInfo> = list.into_iter()
|
||||
.filter(|info| {
|
||||
let prune_info: Vec<(BackupInfo, bool)> = list.into_iter()
|
||||
.map(|info| {
|
||||
let backup_id = info.backup_dir.relative_path();
|
||||
match mark.get(&backup_id) {
|
||||
Some(PruneMark::Keep) => false,
|
||||
_ => true,
|
||||
}
|
||||
let keep = match mark.get(&backup_id) {
|
||||
Some(PruneMark::Keep) => true,
|
||||
_ => false,
|
||||
};
|
||||
(info, keep)
|
||||
})
|
||||
.collect();
|
||||
|
||||
BackupInfo::sort_list(&mut remove_list, true);
|
||||
|
||||
Ok(remove_list)
|
||||
Ok(prune_info)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,12 +14,20 @@ fn get_prune_list(
|
||||
keep_yearly: Option<u64>,
|
||||
) -> Vec<PathBuf> {
|
||||
|
||||
let remove_list = BackupGroup::compute_prune_list(
|
||||
let mut prune_info = BackupGroup::compute_prune_info(
|
||||
list, keep_last, keep_daily, keep_weekly, keep_monthly, keep_yearly).unwrap();
|
||||
|
||||
remove_list
|
||||
prune_info.reverse();
|
||||
|
||||
prune_info
|
||||
.iter()
|
||||
.map(|d| d.backup_dir.relative_path())
|
||||
.filter_map(|(info, keep)| {
|
||||
if *keep {
|
||||
None
|
||||
} else {
|
||||
Some(info.backup_dir.relative_path())
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user