[pbs-devel] [PATCH proxmox-backup] tape: include used tapes in tape notification e-mails

Dominik Csapak d.csapak at proxmox.com
Fri Jul 1 14:11:04 CEST 2022


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

Signed-off-by: Dominik Csapak <d.csapak at 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






More information about the pbs-devel mailing list