From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 165757684D for ; Fri, 16 Jul 2021 10:53:35 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 17D4FE2A5 for ; Fri, 16 Jul 2021 10:53:34 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id D2711E1AF for ; Fri, 16 Jul 2021 10:53:29 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id AC6CE42150 for ; Fri, 16 Jul 2021 10:53:29 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Fri, 16 Jul 2021 10:53:23 +0200 Message-Id: <20210716085328.3731574-7-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210716085328.3731574-1-d.csapak@proxmox.com> References: <20210716085328.3731574-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.578 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 06/11] server/prune_job: factor out 'prune_datastore' X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Jul 2021 08:53:35 -0000 we want to use that outside of a prune job Signed-off-by: Dominik Csapak --- 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, + prune_options: PruneOptions, + store: &str, + datastore: Arc, +) -> 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