From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 0DBDD1FF140 for ; Fri, 10 Apr 2026 17:43:44 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E18DA220A1; Fri, 10 Apr 2026 17:44:28 +0200 (CEST) From: Thomas Lamprecht To: pbs-devel@lists.proxmox.com Subject: [PATCH v4 5/5] fix #5340: client: repository: add PBS_NAMESPACE environment variable Date: Fri, 10 Apr 2026 16:09:06 +0200 Message-ID: <20260410154327.4133440-6-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260410154327.4133440-1-t.lamprecht@proxmox.com> References: <20260410154327.4133440-1-t.lamprecht@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1775835763864 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.002 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: KJPNYTBFCMHYI3PH2UGGNXKRDLWNUXFT X-Message-ID-Hash: KJPNYTBFCMHYI3PH2UGGNXKRDLWNUXFT X-MailFrom: t.lamprecht@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Add PBS_NAMESPACE as a fallback when --ns is not given on the CLI, addressing the request in bug #5340. The env var is supported uniformly across all client tools (proxmox-backup-client, proxmox-file-restore, proxmox-backup-debug). Like the other PBS_* atom env vars, it provides a default that can be overridden by the corresponding CLI option. Signed-off-by: Thomas Lamprecht --- changes v3 -> v4: - env var fallback now lives in the shared optional_ns_param() in pbs-client tools (moved in patch 3), so this patch only upgrades that single function instead of touching all three binaries - made ENV_VAR_PBS_NAMESPACE private (consistent with other ENV_VAR_PBS_* constants, no external users after the move) docs/backup-client.rst | 3 +++ pbs-client/src/tools/mod.rs | 16 +++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/backup-client.rst b/docs/backup-client.rst index 1d464a007..e2a05d4fc 100644 --- a/docs/backup-client.rst +++ b/docs/backup-client.rst @@ -131,6 +131,9 @@ Environment Variables Authentication identity (``user@realm`` or ``user@realm!tokenname``). Defaults to ``root@pam`` if unset. +``PBS_NAMESPACE`` + Backup namespace. Used as a fallback when ``--ns`` is not given. + ``PBS_PASSWORD`` When set, this value is used as the password for the backup server. You can also set this to an API token secret. diff --git a/pbs-client/src/tools/mod.rs b/pbs-client/src/tools/mod.rs index fa708a8b5..e034b9a31 100644 --- a/pbs-client/src/tools/mod.rs +++ b/pbs-client/src/tools/mod.rs @@ -36,6 +36,7 @@ const ENV_VAR_PBS_SERVER: &str = "PBS_SERVER"; const ENV_VAR_PBS_PORT: &str = "PBS_PORT"; const ENV_VAR_PBS_DATASTORE: &str = "PBS_DATASTORE"; const ENV_VAR_PBS_AUTH_ID: &str = "PBS_AUTH_ID"; +const ENV_VAR_PBS_NAMESPACE: &str = "PBS_NAMESPACE"; /// Directory with system [credential]s. See systemd-creds(1). /// @@ -339,13 +340,17 @@ pub fn extract_repository_from_map(param: &HashMap) -> Option Result { - Ok(match param.get("ns") { - Some(Value::String(ns)) => ns.parse()?, + match param.get("ns") { + Some(Value::String(ns)) => return ns.parse().map_err(Error::from), Some(_) => bail!("invalid namespace parameter"), - None => BackupNamespace::root(), - }) + None => {} + } + if let Ok(ns) = std::env::var(ENV_VAR_PBS_NAMESPACE) { + return ns.parse().map_err(Error::from); + } + Ok(BackupNamespace::root()) } pub fn connect(repo: &BackupRepository) -> Result { @@ -849,6 +854,7 @@ mod tests { ENV_VAR_PBS_PORT, ENV_VAR_PBS_DATASTORE, ENV_VAR_PBS_AUTH_ID, + ENV_VAR_PBS_NAMESPACE, ENV_VAR_CREDENTIALS_DIRECTORY, ]; -- 2.47.3