public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 06/11] server/prune_job: factor out 'prune_datastore'
Date: Fri, 16 Jul 2021 10:53:23 +0200	[thread overview]
Message-ID: <20210716085328.3731574-7-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210716085328.3731574-1-d.csapak@proxmox.com>

we want to use that outside of a prune job

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/server/prune_job.rs | 114 +++++++++++++++++++++-------------------
 1 file changed, 61 insertions(+), 53 deletions(-)

diff --git a/src/server/prune_job.rs b/src/server/prune_job.rs
index 248068ea..7ea42fcb 100644
--- a/src/server/prune_job.rs
+++ b/src/server/prune_job.rs
@@ -1,6 +1,6 @@
-use anyhow::Error;
+use std::sync::Arc;
 
-use proxmox::try_block;
+use anyhow::Error;
 
 use pbs_datastore::{task_log, task_warn};
 
@@ -11,6 +11,61 @@ use crate::{
     server::WorkerTask,
 };
 
+pub fn prune_datastore(
+    worker: Arc<WorkerTask>,
+    prune_options: PruneOptions,
+    store: &str,
+    datastore: Arc<DataStore>,
+) -> Result<(), Error> {
+    task_log!(worker, "Starting datastore prune on store \"{}\"", store);
+
+    task_log!(
+        worker,
+        "retention options: {}",
+        prune_options.cli_options_string()
+    );
+
+    let base_path = datastore.base_path();
+
+    let groups = BackupInfo::list_backup_groups(&base_path)?;
+    for group in groups {
+        let list = group.list_backups(&base_path)?;
+        let mut prune_info = compute_prune_info(list, &prune_options)?;
+        prune_info.reverse(); // delete older snapshots first
+
+        task_log!(
+            worker,
+            "Starting prune on store \"{}\" group \"{}/{}\"",
+            store,
+            group.backup_type(),
+            group.backup_id()
+        );
+
+        for (info, keep) in prune_info {
+            task_log!(
+                worker,
+                "{} {}/{}/{}",
+                if keep { "keep" } else { "remove" },
+                group.backup_type(),
+                group.backup_id(),
+                info.backup_dir.backup_time_string()
+            );
+            if !keep {
+                if let Err(err) = datastore.remove_backup_dir(&info.backup_dir, false) {
+                    task_warn!(
+                        worker,
+                        "failed to remove dir {:?}: {}",
+                        info.backup_dir.relative_path(),
+                        err,
+                    );
+                }
+            }
+        }
+    }
+
+    Ok(())
+}
+
 pub fn do_prune_job(
     mut job: Job,
     prune_options: PruneOptions,
@@ -29,58 +84,11 @@ pub fn do_prune_job(
         move |worker| {
             job.start(&worker.upid().to_string())?;
 
-            let result = try_block!({
-                task_log!(worker, "Starting datastore prune on store \"{}\"", store);
-
-                if let Some(event_str) = schedule {
-                    task_log!(worker, "task triggered by schedule '{}'", event_str);
-                }
-
-                task_log!(
-                    worker,
-                    "retention options: {}",
-                    prune_options.cli_options_string()
-                );
-
-                let base_path = datastore.base_path();
-
-                let groups = BackupInfo::list_backup_groups(&base_path)?;
-                for group in groups {
-                    let list = group.list_backups(&base_path)?;
-                    let mut prune_info = compute_prune_info(list, &prune_options)?;
-                    prune_info.reverse(); // delete older snapshots first
-
-                    task_log!(
-                        worker,
-                        "Starting prune on store \"{}\" group \"{}/{}\"",
-                        store,
-                        group.backup_type(),
-                        group.backup_id()
-                    );
+            if let Some(event_str) = schedule {
+                task_log!(worker, "task triggered by schedule '{}'", event_str);
+            }
 
-                    for (info, keep) in prune_info {
-                        task_log!(
-                            worker,
-                            "{} {}/{}/{}",
-                            if keep { "keep" } else { "remove" },
-                            group.backup_type(),
-                            group.backup_id(),
-                            info.backup_dir.backup_time_string()
-                        );
-                        if !keep {
-                            if let Err(err) = datastore.remove_backup_dir(&info.backup_dir, false) {
-                                task_warn!(
-                                    worker,
-                                    "failed to remove dir {:?}: {}",
-                                    info.backup_dir.relative_path(),
-                                    err,
-                                );
-                            }
-                        }
-                    }
-                }
-                Ok(())
-            });
+            let result = prune_datastore(worker.clone(), prune_options, &store, datastore);
 
             let status = worker.create_state(&result);
 
-- 
2.30.2





  parent reply	other threads:[~2021-07-16  8:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-16  8:53 [pbs-devel] [PATCH proxmox-backup 00/11] add 'prune all' button to datastore content Dominik Csapak
2021-07-16  8:53 ` [pbs-devel] [PATCH proxmox-backup 01/11] api-types: move PRUNE_SCHEMA_KEEP_* to pbs-api-types Dominik Csapak
2021-07-16  8:53 ` [pbs-devel] [PATCH proxmox-backup 02/11] pbs-datastore/prune: make PruneOptions an api type Dominik Csapak
2021-07-16  8:53 ` [pbs-devel] [PATCH proxmox-backup 03/11] client: simplify prune api method Dominik Csapak
2021-07-16  8:53 ` [pbs-devel] [PATCH proxmox-backup 04/11] api: admin/datastore: simplify prune api call Dominik Csapak
2021-07-16  8:53 ` [pbs-devel] [PATCH proxmox-backup 05/11] backup/datastore: refactor check_backup_owner there Dominik Csapak
2021-07-16  8:53 ` Dominik Csapak [this message]
2021-07-16  8:53 ` [pbs-devel] [PATCH proxmox-backup 07/11] server/prune_job: add 'keep_all' logic to 'prune_datastore' Dominik Csapak
2021-07-16  8:53 ` [pbs-devel] [PATCH proxmox-backup 08/11] server/prune_job: add proper permission checks " Dominik Csapak
2021-07-16  8:53 ` [pbs-devel] [PATCH proxmox-backup 09/11] api: admin/datastore: add new 'prune-datastore' api call Dominik Csapak
2021-07-16  8:53 ` [pbs-devel] [PATCH proxmox-backup 10/11] ui: datastore/Content: add 'Prune All' button Dominik Csapak
2021-07-16  8:53 ` [pbs-devel] [PATCH proxmox-backup 11/11] ui: datastore/Prune: improve title of group prune window Dominik Csapak
2021-07-16  9:48 ` [pbs-devel] applied: [PATCH proxmox-backup 00/11] add 'prune all' button to datastore content Dietmar Maurer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210716085328.3731574-7-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal