public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 2/9] cli: manager: add 'migrate-config default-notification-mode' command
Date: Mon, 23 Jun 2025 16:13:08 +0200	[thread overview]
Message-ID: <20250623141315.288681-4-l.wagner@proxmox.com> (raw)
In-Reply-To: <20250623141315.288681-1-l.wagner@proxmox.com>

This one migrates any datastore or tape backup job that relied on the
old default (legacy-sendmail) to an explicit setting of
legacy-sendmail. This allows us the change the default without changing
behavior for anybody.

This new command is intended to be called by d/postinst on upgrade to
the package version which introduces the new default value for
'notification-mode'.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 .../proxmox_backup_manager/migrate_config.rs  | 77 ++++++++++++++++++-
 1 file changed, 75 insertions(+), 2 deletions(-)

diff --git a/src/bin/proxmox_backup_manager/migrate_config.rs b/src/bin/proxmox_backup_manager/migrate_config.rs
index 214c8d71..9897218a 100644
--- a/src/bin/proxmox_backup_manager/migrate_config.rs
+++ b/src/bin/proxmox_backup_manager/migrate_config.rs
@@ -1,13 +1,20 @@
 use anyhow::{bail, Error};
 use serde::Deserialize;
 
-use pbs_api_types::{DataStoreConfig, PruneJobConfig, PruneJobOptions};
+use pbs_api_types::{
+    DataStoreConfig, NotificationMode, PruneJobConfig, PruneJobOptions, TapeBackupJobConfig,
+};
 use pbs_config::prune;
 
 /// Handle a 'migrate-config' command.
 pub fn handle_command(command: &str) -> Result<(), Error> {
     match command {
-        "update-to-prune-jobs-config" => return update_to_prune_jobs_config(),
+        "update-to-prune-jobs-config" => update_to_prune_jobs_config(),
+        "default-notification-mode" => {
+            migrate_tape_job_notification_mode()?;
+            migrate_datastore_notification_mode_default()?;
+            Ok(())
+        }
         _ => bail!("invalid fixup command: {command}"),
     }
 }
@@ -96,3 +103,69 @@ pub(crate) fn update_to_prune_jobs_config() -> Result<(), Error> {
 
     Ok(())
 }
+
+/// Explicitly set 'notification-mode' to 'legacy-sendmail' for any datastore which
+/// relied on the previous default of 'legacy-sendmail'.
+///
+/// This allows us to change the default to 'notification-system' without any noticeable
+/// change in behavior.
+fn migrate_datastore_notification_mode_default() -> Result<(), Error> {
+    let _lock = pbs_config::datastore::lock_config()?;
+
+    let (mut datastore_config, _digest) = pbs_config::datastore::config()?;
+
+    for (store, entry) in datastore_config.sections.iter_mut() {
+        let mut config = match DataStoreConfig::deserialize(&entry.1) {
+            Ok(c) => c,
+            Err(err) => {
+                eprintln!("failed to parse config of store {store}: {err}");
+                continue;
+            }
+        };
+
+        if config.notification_mode.is_none() {
+            config.notification_mode = Some(NotificationMode::LegacySendmail);
+            eprintln!("setting notification-mode of datastore '{store}' to 'legacy-sendmail' to presere previous default behavior.");
+        }
+
+        entry.1 = serde_json::to_value(config)?;
+    }
+
+    pbs_config::datastore::save_config(&datastore_config)?;
+
+    Ok(())
+}
+
+/// Explicitly set 'notification-mode' to 'legacy-sendmail' for any tape backup job which
+/// relied on the previous default of 'legacy-sendmail'.
+///
+/// This allows us to change the default to 'notification-system' without any noticeable
+/// change in behavior.
+fn migrate_tape_job_notification_mode() -> Result<(), Error> {
+    let _lock = pbs_config::tape_job::lock()?;
+
+    let (mut tapejob_config, _digest) = pbs_config::tape_job::config()?;
+
+    for (job_id, entry) in tapejob_config.sections.iter_mut() {
+        let mut config = match TapeBackupJobConfig::deserialize(&entry.1) {
+            Ok(c) => c,
+            Err(err) => {
+                eprintln!("failed to parse config of tape-backup job {job_id}: {err}");
+                continue;
+            }
+        };
+
+        if config.setup.notification_mode.is_none() {
+            config.setup.notification_mode = Some(NotificationMode::LegacySendmail);
+            eprintln!(
+                "setting notification-mode of tape backup job '{job_id}' to 'legacy-sendmail' to preserve previous default behavior."
+            );
+        }
+
+        entry.1 = serde_json::to_value(config)?;
+    }
+
+    pbs_config::tape_job::save_config(&tapejob_config)?;
+
+    Ok(())
+}
-- 
2.39.5



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


  parent reply	other threads:[~2025-06-23 14:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-23 14:13 [pbs-devel] [PATCH proxmox{,-backup} 00/10] change of default notification-mode; UX improvements Lukas Wagner
2025-06-23 14:13 ` [pbs-devel] [PATCH proxmox 1/1] pbs-api-types: change default notification mode to 'notification-system' Lukas Wagner
2025-07-15 22:47   ` [pbs-devel] applied: " Thomas Lamprecht
2025-06-23 14:13 ` [pbs-devel] [PATCH proxmox-backup 1/9] cli: manager: move update-to-prune-jobs command to new migrate-config sub-command Lukas Wagner
2025-07-15 23:09   ` Thomas Lamprecht
2025-07-15 23:10     ` Thomas Lamprecht
2025-06-23 14:13 ` Lukas Wagner [this message]
2025-06-23 14:13 ` [pbs-devel] [PATCH proxmox-backup 3/9] d/postinst: migrate notification mode default on update Lukas Wagner
2025-06-23 14:13 ` [pbs-devel] [PATCH proxmox-backup 4/9] ui: datastore options view: switch to new notification-mode default Lukas Wagner
2025-06-23 14:13 ` [pbs-devel] [PATCH proxmox-backup 5/9] ui: tape backup job: move notification settings to a separate tab Lukas Wagner
2025-06-23 14:13 ` [pbs-devel] [PATCH proxmox-backup 6/9] ui: one-shot tape backup: use same wording as tape-backup jobs Lukas Wagner
2025-06-23 14:13 ` [pbs-devel] [PATCH proxmox-backup 7/9] ui: datastore options: notifications: use same jargon as tape-jobs and PVE Lukas Wagner
2025-06-23 14:13 ` [pbs-devel] [PATCH proxmox-backup 8/9] ui: datastore options: drop notify and notify-user rows Lukas Wagner
2025-06-23 14:13 ` [pbs-devel] [PATCH proxmox-backup 9/9] ui: datastore options: notification: use radio controls to select mode Lukas Wagner
2025-07-15 23:13 ` [pbs-devel] [PATCH proxmox{,-backup} 00/10] change of default notification-mode; UX improvements Thomas Lamprecht

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=20250623141315.288681-4-l.wagner@proxmox.com \
    --to=l.wagner@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