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] tape: include used tapes in tape notification e-mails
Date: Fri,  1 Jul 2022 14:11:04 +0200	[thread overview]
Message-ID: <20220701121104.3365493-1-d.csapak@proxmox.com> (raw)

by saving them in the pool-writer, and setting them in the
TapeBackupJobSummary

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 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<String>,
     /// 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<Vec<String>>,
 }
 
 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<Mutex<CatalogSet>>,
     notify_email: Option<String>,
     ns_magic: bool,
+    used_tapes: HashSet<Uuid>,
 }
 
 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<Vec<String>, 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





             reply	other threads:[~2022-07-01 12:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-01 12:11 Dominik Csapak [this message]
2022-07-05  6:58 ` [pbs-devel] applied: " Wolfgang Bumiller

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=20220701121104.3365493-1-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