From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 381F71FF0AF for ; Fri, 06 Nov 2026 18:24:27 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id DB780216ED; Fri, 06 Nov 2026 18:23:38 +0100 (CET) From: Christian Ebner To: pbs-devel@lists.proxmox.com Subject: [PATCH proxmox-backup v2 31/43] api: admin: allow to modify snapshot retention for root user Date: Fri, 6 Nov 2026 18:22:23 +0100 Message-ID: <20261106172235.890542-32-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261106172235.890542-1-c.ebner@proxmox.com> References: <20261106172235.890542-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1793985779242 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.452 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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: CFG42Q4SMHCI6NGWJDTVW4IY5DFVCVA3 X-Message-ID-Hash: CFG42Q4SMHCI6NGWJDTVW4IY5DFVCVA3 X-MailFrom: c.ebner@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: Only root user is able to set or extend the retention setting previously set by the sync/backup api. Signed-off-by: Christian Ebner --- pbs-datastore/src/backup_info.rs | 4 +-- pbs-datastore/src/datastore.rs | 1 + src/api2/admin/datastore.rs | 52 ++++++++++++++++++++++++++++++++ src/backup/verify.rs | 1 + 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/pbs-datastore/src/backup_info.rs b/pbs-datastore/src/backup_info.rs index ac3ea8378..13dd52c3a 100644 --- a/pbs-datastore/src/backup_info.rs +++ b/pbs-datastore/src/backup_info.rs @@ -1048,12 +1048,12 @@ impl BackupDir { pub fn update_manifest( &self, backend: &DatastoreBackend, - update_fn: impl FnOnce(&mut BackupManifest), + update_fn: impl FnOnce(&mut BackupManifest) -> Result<(), Error>, ) -> Result<(), Error> { let _guard = self.lock_manifest()?; let (mut manifest, _) = self.load_manifest()?; - update_fn(&mut manifest); + update_fn(&mut manifest)?; // keep existing signature let blob = manifest.to_data_blob(None)?; diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs index c8f14c5d0..9b0c14979 100644 --- a/pbs-datastore/src/datastore.rs +++ b/pbs-datastore/src/datastore.rs @@ -3462,6 +3462,7 @@ impl DataStore { snapshot .update_manifest(&backend, |manifest| { manifest.unprotected["notes"] = notes.into(); + Ok(()) }) .map_err(|err| format_err!("unable to update manifest blob - {err}"))?; Ok(()) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index 80a39cc8a..097d74dc1 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -2315,6 +2315,54 @@ pub async fn set_protection( .await? } +#[api( + input: { + properties: { + store: { schema: DATASTORE_SCHEMA }, + ns: { + type: BackupNamespace, + optional: true, + }, + backup_dir: { + type: pbs_api_types::BackupDir, + flatten: true, + }, + "retain-until": { + type: Integer, + description: "Set or extend retention to given timestamp", + }, + }, + }, + access: { + permission: &Permission::Superuser, + description: "Only root@pam is allowed to modify retention timespans", + }, +)] +/// Set or extend retention timespan of given backup snapshot +pub fn modify_retention( + store: String, + ns: Option, + backup_dir: pbs_api_types::BackupDir, + retain_until: i64, + _rpcenv: &mut dyn RpcEnvironment, +) -> Result<(), Error> { + let datastore = DataStore::lookup_datastore(lookup_with(&store, Operation::Write))?; + + datastore.check_max_retention(retain_until)?; + + let backend = datastore.backend()?; + let ns = ns.unwrap_or_default(); + let backup_dir = datastore.backup_dir(ns, backup_dir)?; + backup_dir + .update_manifest(&backend, |manifest| { + manifest.modify_retention_timestamp(retain_until)?; + Ok(()) + }) + .map_err(|err| format_err!("failed to modify retention timestamp on manifest: {err}"))?; + + Ok(()) +} + #[api( input: { properties: { @@ -2990,6 +3038,10 @@ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[ "pxar-file-download", &Router::new().download(&API_METHOD_PXAR_FILE_DOWNLOAD), ), + ( + "retention", + &Router::new().put(&API_METHOD_MODIFY_RETENTION), + ), ("rrd", &Router::new().get(&API_METHOD_GET_RRD_STATS)), ("s3-refresh", &Router::new().put(&API_METHOD_S3_REFRESH)), ( diff --git a/src/backup/verify.rs b/src/backup/verify.rs index aeb78c032..f3df70240 100644 --- a/src/backup/verify.rs +++ b/src/backup/verify.rs @@ -471,6 +471,7 @@ impl VerifyWorker { let verify_state = serde_json::to_value(verify_state)?; backup_dir.update_manifest(&self.datastore.backend()?, |manifest| { manifest.unprotected["verify_state"] = verify_state; + Ok(()) }) } { info!("verify {datastore_name}:{backup_dir_name} - manifest update error: {err}"); -- 2.47.3