[pbs-devel] [PATCH proxmox-backup 2/9] cli: manager: add 'migrate-config default-notification-mode' command
Lukas Wagner
l.wagner at proxmox.com
Mon Jun 23 16:13:08 CEST 2025
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 at 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
More information about the pbs-devel
mailing list