src/backup/prune.rs: add new helper keeps_something()

This commit is contained in:
Dietmar Maurer 2019-12-06 12:28:31 +01:00
parent 4bf0cc3b41
commit 9e3f008804
2 changed files with 18 additions and 17 deletions

View File

@ -294,18 +294,17 @@ fn prune(
let datastore = DataStore::lookup_datastore(store)?;
let mut keep_all = true;
for opt in &["keep-last", "keep-daily", "keep-weekly", "keep-weekly", "keep-yearly"] {
if !param[opt].is_null() {
keep_all = false;
break;
}
}
let prune_options = PruneOptions {
keep_last: param["keep-last"].as_u64(),
keep_daily: param["keep-daily"].as_u64(),
keep_weekly: param["keep-weekly"].as_u64(),
keep_monthly: param["keep-monthly"].as_u64(),
keep_yearly: param["keep-yearly"].as_u64(),
};
let worker = WorkerTask::new("prune", Some(store.to_owned()), "root@pam", true)?;
let result = try_block! {
if keep_all {
if !prune_options.keeps_something() {
worker.log("No prune selection - keeping all files.");
return Ok(());
} else {
@ -314,14 +313,6 @@ fn prune(
let list = group.list_backups(&datastore.base_path())?;
let prune_options = PruneOptions {
keep_last: param["keep-last"].as_u64(),
keep_daily: param["keep-daily"].as_u64(),
keep_weekly: param["keep-weekly"].as_u64(),
keep_monthly: param["keep-monthly"].as_u64(),
keep_yearly: param["keep-yearly"].as_u64(),
};
let mut prune_info = compute_prune_info(list, &prune_options)?;
prune_info.reverse(); // delete older snapshots first

View File

@ -113,6 +113,16 @@ impl PruneOptions {
self.keep_yearly = value;
self
}
pub fn keeps_something(&self) -> bool {
let mut keep_something = false;
if let Some(count) = self.keep_last { if count > 0 { keep_something = true; } }
if let Some(count) = self.keep_daily { if count > 0 { keep_something = true; } }
if let Some(count) = self.keep_weekly { if count > 0 { keep_something = true; } }
if let Some(count) = self.keep_monthly { if count > 0 { keep_something = true; } }
if let Some(count) = self.keep_yearly { if count > 0 { keep_something = true; } }
keep_something
}
}
pub fn compute_prune_info(