]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/backup/backup_info.rs - prune: improve algorythm
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 5 Dec 2019 17:41:28 +0000 (18:41 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 5 Dec 2019 17:41:28 +0000 (18:41 +0100)
src/backup/backup_info.rs
tests/prune.rs

index f17d4646d1468423de85d8a779512ae26d1ac6d0..866977614e9b2284910f56fa2bba88b44d235a6b 100644 (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);
index 2648930f26a22e39444075a86010b3d04bf25745..9430746f7c15d5464504fc614bfb852d5bb34984 100644 (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);