From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pbs-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 3363D1FF16F
	for <inbox@lore.proxmox.com>; Tue, 13 May 2025 15:52:58 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id A217A3325A;
	Tue, 13 May 2025 15:53:12 +0200 (CEST)
From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Tue, 13 May 2025 15:52:41 +0200
Message-Id: <20250513135247.644260-15-c.ebner@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250513135247.644260-1-c.ebner@proxmox.com>
References: <20250513135247.644260-1-c.ebner@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.029 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
Subject: [pbs-devel] [PATCH v3 proxmox-backup 14/20] client: expose skip
 trash flags for cli commands
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Backup Server development discussion
 <pbs-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pbs-devel-bounces@lists.proxmox.com
Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com>

Allows to explicitly set/clear the `skip-trash` flag when pruning
groups or snapshots via the client cli command.

Set defaults for `skip-trash` to false in order to use the trash.

Further, never add the flag to the api call parameters in the client
if not explicitly set, in order to keep backwards compatibility to
older PBS instances.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
 pbs-datastore/src/datastore.rs        |  6 ++++--
 proxmox-backup-client/src/group.rs    | 14 +++++++++++++-
 proxmox-backup-client/src/snapshot.rs | 16 ++++++++++++----
 src/api2/admin/datastore.rs           | 11 +++++++++--
 src/api2/backup/environment.rs        |  1 +
 src/server/prune_job.rs               |  4 +++-
 src/server/pull.rs                    | 12 +++++++-----
 7 files changed, 49 insertions(+), 15 deletions(-)

diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
index fd6eaadbb..574d6ec26 100644
--- a/pbs-datastore/src/datastore.rs
+++ b/pbs-datastore/src/datastore.rs
@@ -671,10 +671,11 @@ impl DataStore {
         self: &Arc<Self>,
         ns: &BackupNamespace,
         backup_group: &pbs_api_types::BackupGroup,
+        skip_trash: bool,
     ) -> Result<BackupGroupDeleteStats, Error> {
         let backup_group = self.backup_group(ns.clone(), backup_group.clone());
 
-        backup_group.destroy(true)
+        backup_group.destroy(skip_trash)
     }
 
     /// Remove a backup directory including all content
@@ -683,10 +684,11 @@ impl DataStore {
         ns: &BackupNamespace,
         backup_dir: &pbs_api_types::BackupDir,
         force: bool,
+        skip_trash: bool,
     ) -> Result<(), Error> {
         let backup_dir = self.backup_dir(ns.clone(), backup_dir.clone())?;
 
-        backup_dir.destroy(force, true)
+        backup_dir.destroy(force, skip_trash)
     }
 
     /// Returns the time of the last successful backup
diff --git a/proxmox-backup-client/src/group.rs b/proxmox-backup-client/src/group.rs
index 67f26e261..42f8e1e61 100644
--- a/proxmox-backup-client/src/group.rs
+++ b/proxmox-backup-client/src/group.rs
@@ -37,11 +37,20 @@ pub fn group_mgmt_cli() -> CliCommandMap {
                 type: BackupNamespace,
                 optional: true,
             },
+            "skip-trash": {
+                type: bool,
+                optional: true,
+                description: "Immediately remove the group, not marking contents as trash.",
+            },
         }
     }
 )]
 /// Forget (remove) backup snapshots.
-async fn forget_group(group: String, mut param: Value) -> Result<(), Error> {
+async fn forget_group(
+    group: String,
+    skip_trash: Option<bool>,
+    mut param: Value,
+) -> Result<(), Error> {
     let backup_group: BackupGroup = group.parse()?;
     let repo = remove_repository_from_value(&mut param)?;
     let client = connect(&repo)?;
@@ -63,6 +72,9 @@ async fn forget_group(group: String, mut param: Value) -> Result<(), Error> {
     )?;
     if confirmation.is_yes() {
         let path = format!("api2/json/admin/datastore/{}/groups", repo.store());
+        if let Some(skip_trash) = skip_trash {
+            api_param["skip-trash"] = Value::from(skip_trash);
+        }
         if let Err(err) = client.delete(&path, Some(api_param)).await {
             // "ENOENT: No such file or directory" is part of the error returned when the group
             // has not been found. The full error contains the full datastore path and we would
diff --git a/proxmox-backup-client/src/snapshot.rs b/proxmox-backup-client/src/snapshot.rs
index f195c23b7..a9b46726a 100644
--- a/proxmox-backup-client/src/snapshot.rs
+++ b/proxmox-backup-client/src/snapshot.rs
@@ -173,11 +173,16 @@ async fn list_snapshot_files(param: Value) -> Result<Value, Error> {
                 type: String,
                 description: "Snapshot path.",
             },
+            "skip-trash": {
+                type: bool,
+                optional: true,
+                description: "Immediately remove the snapshot, not marking it as trash.",
+            },
         }
     }
 )]
 /// Forget (remove) backup snapshots.
-async fn forget_snapshots(param: Value) -> Result<(), Error> {
+async fn forget_snapshots(skip_trash: Option<bool>, param: Value) -> Result<(), Error> {
     let repo = extract_repository_from_value(&param)?;
 
     let backup_ns = optional_ns_param(&param)?;
@@ -188,9 +193,12 @@ async fn forget_snapshots(param: Value) -> Result<(), Error> {
 
     let path = format!("api2/json/admin/datastore/{}/snapshots", repo.store());
 
-    client
-        .delete(&path, Some(snapshot_args(&backup_ns, &snapshot)?))
-        .await?;
+    let mut args = snapshot_args(&backup_ns, &snapshot)?;
+    if let Some(skip_trash) = skip_trash {
+        args["skip-trash"] = Value::from(skip_trash);
+    }
+
+    client.delete(&path, Some(args)).await?;
 
     record_repository(&repo);
 
diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index d371a46b0..3f68edf24 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -277,7 +277,13 @@ pub fn list_groups(
                 optional: true,
                 default: true,
                 description: "Return error when group cannot be deleted because of protected snapshots",
-            }
+            },
+            "skip-trash": {
+                type: bool,
+                optional: true,
+                default: false,
+                description: "Immediately remove the group including all snapshots, not marking it as trash.",
+            },
         },
     },
     returns: {
@@ -295,6 +301,7 @@ pub async fn delete_group(
     ns: Option<BackupNamespace>,
     error_on_protected: bool,
     group: pbs_api_types::BackupGroup,
+    skip_trash: bool,
     rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<BackupGroupDeleteStats, Error> {
     let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
@@ -312,7 +319,7 @@ pub async fn delete_group(
             &group,
         )?;
 
-        let delete_stats = datastore.remove_backup_group(&ns, &group)?;
+        let delete_stats = datastore.remove_backup_group(&ns, &group, skip_trash)?;
 
         let error_msg = if datastore.old_locking() {
             "could not remove empty groups directories due to old locking mechanism.\n\
diff --git a/src/api2/backup/environment.rs b/src/api2/backup/environment.rs
index 3d541b461..b5619eb8c 100644
--- a/src/api2/backup/environment.rs
+++ b/src/api2/backup/environment.rs
@@ -730,6 +730,7 @@ impl BackupEnvironment {
             self.backup_dir.backup_ns(),
             self.backup_dir.as_ref(),
             true,
+            true,
         )?;
 
         Ok(())
diff --git a/src/server/prune_job.rs b/src/server/prune_job.rs
index 24359efc7..3b6e168d3 100644
--- a/src/server/prune_job.rs
+++ b/src/server/prune_job.rs
@@ -75,7 +75,9 @@ pub fn prune_datastore(
                 info.backup_dir.backup_time_string()
             );
             if !keep && !dry_run {
-                if let Err(err) = datastore.remove_backup_dir(ns, info.backup_dir.as_ref(), false) {
+                if let Err(err) =
+                    datastore.remove_backup_dir(ns, info.backup_dir.as_ref(), false, true)
+                {
                     let path = info.backup_dir.relative_path();
                     warn!("failed to remove dir {path:?}: {err}");
                 }
diff --git a/src/server/pull.rs b/src/server/pull.rs
index 7aeb2bd56..623419884 100644
--- a/src/server/pull.rs
+++ b/src/server/pull.rs
@@ -503,6 +503,7 @@ async fn pull_snapshot_from<'a>(
                     snapshot.backup_ns(),
                     snapshot.as_ref(),
                     true,
+                    true,
                 ) {
                     info!("cleanup error - {cleanup_err}");
                 }
@@ -677,7 +678,7 @@ async fn pull_group(
             params
                 .target
                 .store
-                .remove_backup_dir(&target_ns, snapshot.as_ref(), false)?;
+                .remove_backup_dir(&target_ns, snapshot.as_ref(), false, true)?;
             sync_stats.add(SyncStats::from(RemovedVanishedStats {
                 snapshots: 1,
                 groups: 0,
@@ -992,10 +993,11 @@ pub(crate) async fn pull_ns(
                     continue;
                 }
                 info!("delete vanished group '{local_group}'");
-                let delete_stats_result = params
-                    .target
-                    .store
-                    .remove_backup_group(&target_ns, local_group);
+                let delete_stats_result =
+                    params
+                        .target
+                        .store
+                        .remove_backup_group(&target_ns, local_group, false);
 
                 match delete_stats_result {
                     Ok(stats) => {
-- 
2.39.5



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