src/backup/backup_info.rs - prune: improve algorythm

This commit is contained in:
Dietmar Maurer 2019-12-05 18:41:28 +01:00
parent 659da6c957
commit 6f47dd8a0f
2 changed files with 19 additions and 6 deletions

View File

@ -110,17 +110,29 @@ impl BackupGroup {
select_id: F,
) {
let mut hash = HashSet::new();
let mut include_hash = HashSet::new();
let mut already_included = HashSet::new();
for info in list {
let backup_id = info.backup_dir.relative_path();
if let Some(_) = mark.get(&backup_id) {
continue;
if let Some(PruneMark::Keep) = mark.get(&backup_id) {
let local_time = info.backup_dir.backup_time().with_timezone(&Local);
let sel_id: String = select_id(local_time, &info);
already_included.insert(sel_id);
}
}
for info in list {
let backup_id = info.backup_dir.relative_path();
if let Some(_) = mark.get(&backup_id) { continue; }
let local_time = info.backup_dir.backup_time().with_timezone(&Local);
let sel_id: String = select_id(local_time, &info);
if !hash.contains(&sel_id) {
if hash.len() >= keep { break; }
hash.insert(sel_id);
if already_included.contains(&sel_id) { continue; }
if !include_hash.contains(&sel_id) {
if include_hash.len() >= keep { break; }
include_hash.insert(sel_id);
mark.insert(backup_id, PruneMark::Keep);
} else {
mark.insert(backup_id, PruneMark::Remove);

View File

@ -134,6 +134,7 @@ fn test_prune_simple() -> Result<(), Error> {
let remove_list = get_prune_list(list, None, Some(1), Some(5), None, None);
let expect: Vec<PathBuf> = vec![
PathBuf::from("host/elsa/2019-12-02T11:59:15Z"),
PathBuf::from("host/elsa/2019-12-03T11:59:15Z"),
PathBuf::from("host/elsa/2019-12-04T11:59:15Z"),
];
assert_eq!(remove_list, expect);