From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH v3 proxmox-backup 14/20] client: expose skip trash flags for cli commands
Date: Tue, 13 May 2025 15:52:41 +0200 [thread overview]
Message-ID: <20250513135247.644260-15-c.ebner@proxmox.com> (raw)
In-Reply-To: <20250513135247.644260-1-c.ebner@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(¶m)?;
let backup_ns = optional_ns_param(¶m)?;
@@ -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
next prev parent reply other threads:[~2025-05-13 13:52 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-13 13:52 [pbs-devel] [PATCH v3 proxmox proxmox-backup 00/20] implement trash bin functionality Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox 1/20] pbs api types: add type for snapshot list filtering based on trash state Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox 2/20] pbs api types: datastore: add trash marker to snapshot list item Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 03/20] datastore/api: mark snapshots as trash on destroy Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 04/20] datastore: mark groups " Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 05/20] datastore: add helpers to check if snapshot/group is trash Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 06/20] datastore: allow filtering of backups by their trash state Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 07/20] api: datastore: add trash state filtering for snapshot listing Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 08/20] datastore: ignore trashed snapshots for last successful backup Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 09/20] sync: ignore trashed snapshots/groups when reading from local source Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 10/20] api: tape: check trash marker when trying to write snapshot Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 11/20] datastore: clear trashed snapshot dir if re-creation requested Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 12/20] datastore: recover backup group from trash for new backups Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 13/20] datastore: garbage collection: clean-up trashed snapshots and groups Christian Ebner
2025-05-13 13:52 ` Christian Ebner [this message]
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 15/20] api: admin: implement endpoints to recover trashed contents Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 16/20] api: admin: move backup group list generation into helper Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 17/20] api: admin: add endpoint to clear trashed items from group Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 18/20] ui: add recover for trashed items tab to datastore panel Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 19/20] ui: drop 'permanent' in group/snapshot forget, default is to trash Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 20/20] ui: mention trash items will be cleared on namespace deletion Christian Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250513135247.644260-15-c.ebner@proxmox.com \
--to=c.ebner@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal