[pbs-devel] [PATCH proxmox-backup v2 5/7] use new PruneJob struct in Prune Jobs implementation

Stefan Hanreich s.hanreich at proxmox.com
Wed Nov 30 16:01:00 CET 2022


Refactor Prune Jobs to utilize the newly created PruneJob struct
instead of manually computing the prune_info and executing the prune
task.

Signed-off-by: Stefan Hanreich <s.hanreich at proxmox.com>
---
 src/server/prune_job.rs | 27 +++++----------------------
 1 file changed, 5 insertions(+), 22 deletions(-)

diff --git a/src/server/prune_job.rs b/src/server/prune_job.rs
index b9f7ebdf..0999ea6c 100644
--- a/src/server/prune_job.rs
+++ b/src/server/prune_job.rs
@@ -2,7 +2,7 @@ use std::sync::Arc;
 
 use anyhow::Error;
 
-use proxmox_sys::{task_log, task_warn};
+use proxmox_sys::task_log;
 
 use pbs_api_types::{
     print_store_and_ns, Authid, KeepOptions, Operation, PruneJobOptions, MAX_NAMESPACE_DEPTH,
@@ -58,9 +58,6 @@ pub fn prune_datastore(
         let ns = group.backup_ns();
         let list = group.list_backups()?;
 
-        let mut prune_info = PruneJob::compute_prune_info(list, &prune_options.keep)?;
-        prune_info.reverse(); // delete older snapshots first
-
         task_log!(
             worker,
             "Pruning group {ns}:\"{}/{}\"",
@@ -68,24 +65,10 @@ pub fn prune_datastore(
             group.backup_id()
         );
 
-        for (info, mark) in prune_info {
-            let keep = keep_all || mark.keep();
-            task_log!(
-                worker,
-                "{}{} {}/{}/{}",
-                if dry_run { "would " } else { "" },
-                mark,
-                group.backup_type(),
-                group.backup_id(),
-                info.backup_dir.backup_time_string()
-            );
-            if !keep && !dry_run {
-                if let Err(err) = datastore.remove_backup_dir(ns, info.backup_dir.as_ref(), false) {
-                    let path = info.backup_dir.relative_path();
-                    task_warn!(worker, "failed to remove dir {path:?}: {err}");
-                }
-            }
-        }
+        PruneJob::new(list, &prune_options.keep)?
+            .dry_run(dry_run)
+            .logging(worker.clone())
+            .run();
     }
 
     Ok(())
-- 
2.30.2





More information about the pbs-devel mailing list