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 B4D0F1FF13B for ; Wed, 11 Mar 2026 16:13:37 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E8DE31FF7E; Wed, 11 Mar 2026 16:13:32 +0100 (CET) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Subject: [PATCH proxmox-backup v4 4/7] api: add PUT endpoint for move_group Date: Wed, 11 Mar 2026 16:13:12 +0100 Message-ID: <20260311151315.133637-5-h.laimer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260311151315.133637-1-h.laimer@proxmox.com> References: <20260311151315.133637-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1773241974504 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.068 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: Y53ARMWXNDSK2PTAJH45R4G3BWYV4O36 X-Message-ID-Hash: Y53ARMWXNDSK2PTAJH45R4G3BWYV4O36 X-MailFrom: h.laimer@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: Requires DATASTORE_MODIFY on both the source and target namespaces. Signed-off-by: Hannes Laimer --- src/api2/admin/datastore.rs | 76 ++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index cca34055..77a88e51 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -69,7 +69,9 @@ use proxmox_rest_server::{formatter, worker_is_active, WorkerTask}; use crate::api2::backup::optional_ns_param; use crate::api2::node::rrd::create_value_from_rrd; -use crate::backup::{check_ns_privs_full, ListAccessibleBackupGroups, VerifyWorker, NS_PRIVS_OK}; +use crate::backup::{ + check_ns_privs, check_ns_privs_full, ListAccessibleBackupGroups, VerifyWorker, NS_PRIVS_OK, +}; use crate::server::jobstate::{compute_schedule_status, Job, JobState}; use crate::tools::{backup_info_to_snapshot_list_item, get_all_snapshot_files, read_backup_index}; @@ -278,6 +280,77 @@ pub async fn delete_group( .await? } +#[api( + input: { + properties: { + store: { schema: DATASTORE_SCHEMA }, + ns: { + type: BackupNamespace, + optional: true, + }, + group: { + type: pbs_api_types::BackupGroup, + flatten: true, + }, + "new-ns": { + type: BackupNamespace, + }, + }, + }, + returns: { + schema: UPID_SCHEMA, + }, + access: { + permission: &Permission::Anybody, + description: "Requires DATASTORE_MODIFY on both the source and target namespace.", + }, +)] +/// Move a backup group to a different namespace within the same datastore. +pub fn move_group( + store: String, + ns: Option, + group: pbs_api_types::BackupGroup, + new_ns: BackupNamespace, + rpcenv: &mut dyn RpcEnvironment, +) -> Result { + let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; + let ns = ns.unwrap_or_default(); + + check_ns_privs(&store, &ns, &auth_id, PRIV_DATASTORE_MODIFY)?; + check_ns_privs(&store, &new_ns, &auth_id, PRIV_DATASTORE_MODIFY)?; + + let datastore = DataStore::lookup_datastore(&store, Some(Operation::Write))?; + + // Best-effort pre-checks for a fast synchronous error before spawning a worker. + if ns == new_ns { + bail!("source and target namespace must be different"); + } + if !datastore.namespace_exists(&new_ns) { + bail!("target namespace '{new_ns}' does not exist"); + } + let source_group = datastore.backup_group(ns.clone(), group.clone()); + if !source_group.exists() { + bail!("group '{group}' does not exist in namespace '{ns}'"); + } + let target_group = datastore.backup_group(new_ns.clone(), group.clone()); + if target_group.exists() { + bail!("group '{group}' already exists in target namespace '{new_ns}'"); + } + + let worker_id = format!("{store}:{ns}:{group}"); + let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI; + + let upid_str = WorkerTask::new_thread( + "move-group", + Some(worker_id), + auth_id.to_string(), + to_stdout, + move |_worker| datastore.move_group(&ns, &group, &new_ns), + )?; + + Ok(json!(upid_str)) +} + #[api( input: { properties: { @@ -2828,6 +2901,7 @@ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[ "groups", &Router::new() .get(&API_METHOD_LIST_GROUPS) + .put(&API_METHOD_MOVE_GROUP) .delete(&API_METHOD_DELETE_GROUP), ), ("mount", &Router::new().post(&API_METHOD_MOUNT)), -- 2.47.3