* [pbs-devel] [PATCH proxmox-backup 1/3] tape/backup: add success/error notifications
@ 2021-03-08 13:10 Dominik Csapak
2021-03-08 13:10 ` [pbs-devel] [PATCH proxmox-backup 2/3] tape/linux_tape: remove debug prints Dominik Csapak
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Dominik Csapak @ 2021-03-08 13:10 UTC (permalink / raw)
To: pbs-devel
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/api2/tape/backup.rs | 40 ++++++++++++--
src/server/email_notifications.rs | 92 +++++++++++++++++++++++++++++++
2 files changed, 126 insertions(+), 6 deletions(-)
diff --git a/src/api2/tape/backup.rs b/src/api2/tape/backup.rs
index 06f75f92..e8ae887c 100644
--- a/src/api2/tape/backup.rs
+++ b/src/api2/tape/backup.rs
@@ -193,15 +193,30 @@ pub fn do_tape_backup_job(
task_log!(worker,"task triggered by schedule '{}'", event_str);
}
+ let notify_user = setup.notify_user.as_ref().unwrap_or_else(|| &Userid::root_userid());
+ let email = lookup_user_email(notify_user);
+
let job_result = backup_worker(
&worker,
datastore,
&pool_config,
&setup,
+ email.clone(),
);
let status = worker.create_state(&job_result);
+ if let Some(email) = email {
+ if let Err(err) = crate::server::send_tape_backup_status(
+ &email,
+ Some(job.jobname()),
+ &setup,
+ &job_result,
+ ) {
+ eprintln!("send tape backup notification failed: {}", err);
+ }
+ }
+
if let Err(err) = job.finish(status) {
eprintln!(
"could not finish job state for {}: {}",
@@ -312,6 +327,9 @@ pub fn backup(
let job_id = format!("{}:{}:{}", setup.store, setup.pool, setup.drive);
+ let notify_user = setup.notify_user.as_ref().unwrap_or_else(|| &Userid::root_userid());
+ let email = lookup_user_email(notify_user);
+
let upid_str = WorkerTask::new_thread(
"tape-backup",
Some(job_id),
@@ -320,16 +338,28 @@ pub fn backup(
move |worker| {
let _drive_lock = drive_lock; // keep lock guard
set_tape_device_state(&setup.drive, &worker.upid().to_string())?;
- backup_worker(
+ let job_result = backup_worker(
&worker,
datastore,
&pool_config,
&setup,
- )?;
+ email.clone(),
+ );
+
+ if let Some(email) = email {
+ if let Err(err) = crate::server::send_tape_backup_status(
+ &email,
+ None,
+ &setup,
+ &job_result,
+ ) {
+ eprintln!("send tape backup notification failed: {}", err);
+ }
+ }
// ignore errors
let _ = set_tape_device_state(&setup.drive, "");
- Ok(())
+ job_result
}
)?;
@@ -341,6 +371,7 @@ fn backup_worker(
datastore: Arc<DataStore>,
pool_config: &MediaPoolConfig,
setup: &TapeBackupJobSetup,
+ email: Option<String>,
) -> Result<(), Error> {
let status_path = Path::new(TAPE_STATUS_DIR);
@@ -352,9 +383,6 @@ fn backup_worker(
let pool = MediaPool::with_config(status_path, &pool_config, changer_name)?;
- let notify_user = setup.notify_user.as_ref().unwrap_or_else(|| &Userid::root_userid());
- let email = lookup_user_email(notify_user);
-
let mut pool_writer = PoolWriter::new(pool, &setup.drive, worker, email)?;
let mut group_list = BackupInfo::list_backup_groups(&datastore.base_path())?;
diff --git a/src/server/email_notifications.rs b/src/server/email_notifications.rs
index 3ff1be7c..f09a8931 100644
--- a/src/server/email_notifications.rs
+++ b/src/server/email_notifications.rs
@@ -10,6 +10,7 @@ use crate::{
config::datastore::DataStoreConfig,
config::verify::VerificationJobConfig,
config::sync::SyncJobConfig,
+ config::tape_job::TapeBackupJobSetup,
api2::types::{
APTUpdateInfo,
GarbageCollectionStatus,
@@ -138,6 +139,43 @@ To upgrade visit the web interface:
"###;
+const TAPE_BACKUP_OK_TEMPLATE: &str = r###"
+
+{{#if id ~}}
+Job ID: {{id}}
+{{/if~}}
+Datastore: {{job.store}}
+Tape Pool: {{job.pool}}
+Tape Drive: {{job.drive}}
+
+
+Tape Backup successful.
+
+
+Please visit the web interface for futher details:
+
+<https://{{fqdn}}:{{port}}/#DataStore-{{job.store}}>
+
+"###;
+
+const TAPE_BACKUP_ERR_TEMPLATE: &str = r###"
+
+{{#if id ~}}
+Job ID: {{id}}
+{{/if~}}
+Datastore: {{job.store}}
+Tape Pool: {{job.pool}}
+Tape Drive: {{job.drive}}
+
+
+Tape Backup failed: {{error}}
+
+
+Please visit the web interface for futher details:
+
+<https://{{fqdn}}:{{port}}/#pbsServerAdministration:tasks>
+
+"###;
lazy_static::lazy_static!{
@@ -158,6 +196,9 @@ lazy_static::lazy_static!{
hb.register_template_string("sync_ok_template", SYNC_OK_TEMPLATE).unwrap();
hb.register_template_string("sync_err_template", SYNC_ERR_TEMPLATE).unwrap();
+ hb.register_template_string("tape_backup_ok_template", TAPE_BACKUP_OK_TEMPLATE).unwrap();
+ hb.register_template_string("tape_backup_err_template", TAPE_BACKUP_ERR_TEMPLATE).unwrap();
+
hb.register_template_string("package_update_template", PACKAGE_UPDATES_TEMPLATE).unwrap();
hb
@@ -356,6 +397,57 @@ pub fn send_sync_status(
Ok(())
}
+pub fn send_tape_backup_status(
+ email: &str,
+ id: Option<&str>,
+ job: &TapeBackupJobSetup,
+ result: &Result<(), Error>,
+) -> Result<(), Error> {
+
+ let (fqdn, port) = get_server_url();
+ let mut data = json!({
+ "job": job,
+ "fqdn": fqdn,
+ "port": port,
+ "id": id,
+ });
+
+ let text = match result {
+ Ok(()) => {
+ HANDLEBARS.render("tape_backup_ok_template", &data)?
+ }
+ Err(err) => {
+ data["error"] = err.to_string().into();
+ HANDLEBARS.render("tape_backup_err_template", &data)?
+ }
+ };
+
+ let subject = match (result, id) {
+ (Ok(()), Some(id)) => format!(
+ "Tape Backup '{}' datastore '{}' successful",
+ id,
+ job.store,
+ ),
+ (Ok(()), None) => format!(
+ "Tape Backup datastore '{}' successful",
+ job.store,
+ ),
+ (Err(_), Some(id)) => format!(
+ "Tape Backup '{}' datastore '{}' failed",
+ id,
+ job.store,
+ ),
+ (Err(_), None) => format!(
+ "Tape Backup datastore '{}' failed",
+ job.store,
+ ),
+ };
+
+ send_job_status_mail(email, &subject, &text)?;
+
+ Ok(())
+}
+
fn get_server_url() -> (String, usize) {
// user will surely request that they can change this
--
2.20.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pbs-devel] [PATCH proxmox-backup 2/3] tape/linux_tape: remove debug prints
2021-03-08 13:10 [pbs-devel] [PATCH proxmox-backup 1/3] tape/backup: add success/error notifications Dominik Csapak
@ 2021-03-08 13:10 ` Dominik Csapak
2021-03-08 13:10 ` [pbs-devel] [PATCH proxmox-backup 3/3] ui: tape/window/Tape{Backup, Restore}: allow empty notify user field Dominik Csapak
2021-03-08 13:30 ` [pbs-devel] applied: [PATCH proxmox-backup 1/3] tape/backup: add success/error notifications Dietmar Maurer
2 siblings, 0 replies; 4+ messages in thread
From: Dominik Csapak @ 2021-03-08 13:10 UTC (permalink / raw)
To: pbs-devel
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
maybe we want to have them but behind a 'verbose' parameter for the cli?
src/tape/drive/linux_tape.rs | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/tape/drive/linux_tape.rs b/src/tape/drive/linux_tape.rs
index ad8c5e98..b5cded05 100644
--- a/src/tape/drive/linux_tape.rs
+++ b/src/tape/drive/linux_tape.rs
@@ -444,7 +444,6 @@ impl TapeDriver for LinuxTapeHandle {
fn sync(&mut self) -> Result<(), Error> {
- println!("SYNC/FLUSH TAPE");
// MTWEOF with count 0 => flush
let cmd = mtop { mt_op: MTCmd::MTWEOF, mt_count: 0 };
@@ -654,7 +653,6 @@ impl TapeDriver for LinuxTapeHandle {
/// Write a single EOF mark without flushing buffers
fn tape_write_eof_mark(file: &File) -> Result<(), std::io::Error> {
- println!("WRITE EOF MARK");
let cmd = mtop { mt_op: MTCmd::MTWEOFI, mt_count: 1 };
unsafe {
@@ -759,7 +757,6 @@ impl TapeWrite for TapeWriterHandle<'_> {
}
fn finish(&mut self, incomplete: bool) -> Result<bool, std::io::Error> {
- println!("FINISH TAPE HANDLE");
let leof = self.writer.finish(incomplete)?;
tape_write_eof_mark(self.writer.writer_ref_mut())?;
Ok(leof)
--
2.20.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pbs-devel] [PATCH proxmox-backup 3/3] ui: tape/window/Tape{Backup, Restore}: allow empty notify user field
2021-03-08 13:10 [pbs-devel] [PATCH proxmox-backup 1/3] tape/backup: add success/error notifications Dominik Csapak
2021-03-08 13:10 ` [pbs-devel] [PATCH proxmox-backup 2/3] tape/linux_tape: remove debug prints Dominik Csapak
@ 2021-03-08 13:10 ` Dominik Csapak
2021-03-08 13:30 ` [pbs-devel] applied: [PATCH proxmox-backup 1/3] tape/backup: add success/error notifications Dietmar Maurer
2 siblings, 0 replies; 4+ messages in thread
From: Dominik Csapak @ 2021-03-08 13:10 UTC (permalink / raw)
To: pbs-devel
we have to set skipEmptyText on comboGrids
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
www/tape/window/TapeBackup.js | 1 +
www/tape/window/TapeRestore.js | 1 +
2 files changed, 2 insertions(+)
diff --git a/www/tape/window/TapeBackup.js b/www/tape/window/TapeBackup.js
index ca9d3b5f..b6a08bb5 100644
--- a/www/tape/window/TapeBackup.js
+++ b/www/tape/window/TapeBackup.js
@@ -56,6 +56,7 @@ Ext.define('PBS.TapeManagement.TapeBackupWindow', {
emptyText: 'root@pam',
value: null,
allowBlank: true,
+ skipEmptyText: true,
renderer: Ext.String.htmlEncode,
},
],
diff --git a/www/tape/window/TapeRestore.js b/www/tape/window/TapeRestore.js
index 8d26e81e..abf3cf68 100644
--- a/www/tape/window/TapeRestore.js
+++ b/www/tape/window/TapeRestore.js
@@ -48,6 +48,7 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
emptyText: gettext('Current User'),
value: null,
allowBlank: true,
+ skipEmptyText: true,
renderer: Ext.String.htmlEncode,
},
],
--
2.20.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pbs-devel] applied: [PATCH proxmox-backup 1/3] tape/backup: add success/error notifications
2021-03-08 13:10 [pbs-devel] [PATCH proxmox-backup 1/3] tape/backup: add success/error notifications Dominik Csapak
2021-03-08 13:10 ` [pbs-devel] [PATCH proxmox-backup 2/3] tape/linux_tape: remove debug prints Dominik Csapak
2021-03-08 13:10 ` [pbs-devel] [PATCH proxmox-backup 3/3] ui: tape/window/Tape{Backup, Restore}: allow empty notify user field Dominik Csapak
@ 2021-03-08 13:30 ` Dietmar Maurer
2 siblings, 0 replies; 4+ messages in thread
From: Dietmar Maurer @ 2021-03-08 13:30 UTC (permalink / raw)
To: Proxmox Backup Server development discussion, Dominik Csapak
applied all 3 patches
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-03-08 13:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-08 13:10 [pbs-devel] [PATCH proxmox-backup 1/3] tape/backup: add success/error notifications Dominik Csapak
2021-03-08 13:10 ` [pbs-devel] [PATCH proxmox-backup 2/3] tape/linux_tape: remove debug prints Dominik Csapak
2021-03-08 13:10 ` [pbs-devel] [PATCH proxmox-backup 3/3] ui: tape/window/Tape{Backup, Restore}: allow empty notify user field Dominik Csapak
2021-03-08 13:30 ` [pbs-devel] applied: [PATCH proxmox-backup 1/3] tape/backup: add success/error notifications Dietmar Maurer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox