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 E3A3F791C7 for ; Fri, 1 Jul 2022 14:11:09 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D8A8496A1 for ; Fri, 1 Jul 2022 14:11:09 +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 for ; Fri, 1 Jul 2022 14:11:06 +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 3417B40994 for ; Fri, 1 Jul 2022 14:11:06 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Fri, 1 Jul 2022 14:11:04 +0200 Message-Id: <20220701121104.3365493-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.099 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 T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [PATCH proxmox-backup] tape: include used tapes in tape notification e-mails 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, 01 Jul 2022 12:11:09 -0000 by saving them in the pool-writer, and setting them in the TapeBackupJobSummary Signed-off-by: Dominik Csapak --- src/api2/tape/backup.rs | 8 ++++++++ src/server/email_notifications.rs | 16 +++++++++++++++- src/tape/pool_writer/mod.rs | 15 +++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/api2/tape/backup.rs b/src/api2/tape/backup.rs index 8f7ee5cb..a1c84b55 100644 --- a/src/api2/tape/backup.rs +++ b/src/api2/tape/backup.rs @@ -564,6 +564,14 @@ fn backup_worker( bail!("Tape backup finished with some errors. Please check the task log."); } + summary.used_tapes = match pool_writer.get_used_media_labels() { + Ok(tapes) => Some(tapes), + Err(err) => { + task_warn!(worker, "could not collect list of used tapes: {err}"); + None + } + }; + summary.duration = start.elapsed(); Ok(()) diff --git a/src/server/email_notifications.rs b/src/server/email_notifications.rs index 44a2ecf1..6fca4133 100644 --- a/src/server/email_notifications.rs +++ b/src/server/email_notifications.rs @@ -148,7 +148,12 @@ Snapshots included: {{/each~}} {{/if}} Duration: {{duration}} - +{{#if used-tapes }} +Used Tapes: +{{#each used-tapes~}} +{{this}} +{{/each~}} +{{/if}} Tape Backup successful. @@ -174,6 +179,12 @@ Snapshots included: {{this}} {{/each~}} {{/if}} +{{#if used-tapes }} +Used Tapes: +{{#each used-tapes~}} +{{this}} +{{/each~}} +{{/if}} Tape Backup failed: {{error}} @@ -241,6 +252,8 @@ pub struct TapeBackupJobSummary { pub snapshot_list: Vec, /// The total time of the backup job pub duration: std::time::Duration, + /// The labels of the used tapes of the backup job + pub used_tapes: Option>, } fn send_job_status_mail(email: &str, subject: &str, text: &str) -> Result<(), Error> { @@ -432,6 +445,7 @@ pub fn send_tape_backup_status( "port": port, "id": id, "snapshot-list": summary.snapshot_list, + "used-tapes": summary.used_tapes, "duration": duration.to_string(), }); diff --git a/src/tape/pool_writer/mod.rs b/src/tape/pool_writer/mod.rs index 0a2e45fb..d87f7dec 100644 --- a/src/tape/pool_writer/mod.rs +++ b/src/tape/pool_writer/mod.rs @@ -4,6 +4,7 @@ pub use catalog_set::*; mod new_chunks_iterator; pub use new_chunks_iterator::*; +use std::collections::HashSet; use std::fs::File; use std::path::Path; use std::sync::{Arc, Mutex}; @@ -49,6 +50,7 @@ pub struct PoolWriter { catalog_set: Arc>, notify_email: Option, ns_magic: bool, + used_tapes: HashSet, } impl PoolWriter { @@ -87,6 +89,7 @@ impl PoolWriter { catalog_set: Arc::new(Mutex::new(catalog_set)), notify_email, ns_magic, + used_tapes: HashSet::new(), }) } @@ -100,6 +103,16 @@ impl PoolWriter { Ok(()) } + pub fn get_used_media_labels(&self) -> Result, Error> { + let mut res = Vec::with_capacity(self.used_tapes.len()); + for media_uuid in &self.used_tapes { + let media_info = self.pool.lookup_media(&media_uuid)?; + res.push(media_info.label_text().to_string()); + } + + Ok(res) + } + pub fn contains_snapshot( &self, store: &str, @@ -208,6 +221,7 @@ impl PoolWriter { }; if !media_changed { + self.used_tapes.insert(media_uuid.clone()); return Ok(media_uuid); } @@ -278,6 +292,7 @@ impl PoolWriter { self.append_media_set_catalogs(worker)?; } + self.used_tapes.insert(media_uuid.clone()); Ok(media_uuid) } -- 2.30.2