From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [RFC v2 proxmox-backup 14/21] datastore: GC: clean-up trashed snapshots, groups and namespaces
Date: Thu, 8 May 2025 15:05:48 +0200 [thread overview]
Message-ID: <20250508130555.494782-15-c.ebner@proxmox.com> (raw)
In-Reply-To: <20250508130555.494782-1-c.ebner@proxmox.com>
Cleanup trashed items during phase 1 of garbage collection. If
encountered, index files located within trashed snapshots are touched
as well, deferring chunk cleanup to the next run
Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
pbs-datastore/src/datastore.rs | 84 +++++++++++++++++++++++++++++++++-
1 file changed, 83 insertions(+), 1 deletion(-)
diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
index ca05e1bea..d88af4c68 100644
--- a/pbs-datastore/src/datastore.rs
+++ b/pbs-datastore/src/datastore.rs
@@ -574,6 +574,18 @@ impl DataStore {
!path.exists()
}
+ /// Checks if the namespace trash marker file exists,
+ /// does not imply that the namespace itself exists.
+ pub fn namespace_is_trashed(&self, namespace: &BackupNamespace) -> bool {
+ if namespace.is_root() {
+ return false;
+ }
+ let mut path = self.base_path();
+ path.push(namespace.path());
+ path.push(TRASH_MARKER_FILENAME);
+ path.exists()
+ }
+
/// Remove the namespace and all it's parent components from the trash by removing the trash or
/// trash-pending marker file for each namespace level from deepest to shallowest. Missing files
/// are ignored.
@@ -1322,7 +1334,7 @@ impl DataStore {
.context("creating namespace iterator failed")?
{
let namespace = namespace.context("iterating namespaces failed")?;
- for group in arc_self.iter_backup_groups(namespace)? {
+ for group in arc_self.iter_backup_groups(namespace.clone())? {
let group = group.context("iterating backup groups failed")?;
// Avoid race between listing/marking of snapshots by GC and pruning the last
@@ -1403,10 +1415,80 @@ impl DataStore {
}
processed_index_files += 1;
}
+
+ // Only try to lock a trashed snapshots and continue if that is not
+ // possible, as then most likely this is in the process of being untrashed.
+ // Check trash state before and after locking to avoid otherwise possible
+ // races.
+ if snapshot.backup_dir.is_trashed() {
+ if let Ok(_lock) = snapshot.backup_dir.lock() {
+ if snapshot.backup_dir.is_trashed() {
+ let path = snapshot.backup_dir.full_path();
+ log::info!("removing trashed backup snapshot {path:?}");
+ std::fs::remove_dir_all(&path).with_context(|| {
+ format!("removing trashed backup snapshot {path:?} failed")
+ })?;
+ }
+ } else {
+ let path = snapshot.backup_dir.full_path();
+ warn!("failed to lock trashed backup snapshot can {path:?}");
+ }
+ }
}
break;
}
+ if group.is_trashed() {
+ if let Ok(_lock) = group.lock() {
+ if group.is_trashed() {
+ let trash_path = group.full_group_path().join(".trashed");
+ std::fs::remove_file(&trash_path).map_err(|err| {
+ format_err!(
+ "removing the trash file '{trash_path:?}' failed - {err}"
+ )
+ })?;
+
+ let owner_path = group.full_group_path().join("owner");
+ std::fs::remove_file(&owner_path).map_err(|err| {
+ format_err!(
+ "removing the owner file '{owner_path:?}' failed - {err}"
+ )
+ })?;
+
+ let path = group.full_group_path();
+
+ std::fs::remove_dir(&path).map_err(|err| {
+ format_err!("removing group directory {path:?} failed - {err}")
+ })?;
+
+ // Remove any now empty backup type directory
+ let base_file = std::fs::File::open(self.base_path())?;
+ let base_fd = base_file.as_raw_fd();
+ for ty in BackupType::iter() {
+ let mut ty_dir = namespace.path();
+ ty_dir.push(ty.to_string());
+ match unlinkat(Some(base_fd), &ty_dir, UnlinkatFlags::RemoveDir) {
+ Ok(_) => (),
+ Err(nix::errno::Errno::ENOENT) |
+ Err(nix::errno::Errno::ENOTEMPTY) => (),
+ Err(err) => info!("failed to remove backup type directory for {namespace} - {err}"),
+ }
+ }
+ } else {
+ let path = group.full_group_path();
+ warn!("failed to lock trashed backup group {path:?}");
+ }
+ }
+ }
+ }
+ if self.namespace_is_trashed(&namespace) {
+ // Remove the namespace, but only if it was empty (as the GC already cleared child
+ // items and no new ones have been created since).
+ match arc_self.destroy_namespace_recursive(&namespace, false) {
+ Ok(true) => info!("removed trashed namespace {namespace}"),
+ Ok(false) => info!("failed to remove trashed namespace {namespace}, not empty"),
+ Err(err) => warn!("removing trashed namespace failed: {err:#}"),
+ }
}
}
--
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-08 13:06 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-08 13:05 [pbs-devel] [RFC v2 proxmox-backup 00/21] implement trash bin functionality Christian Ebner
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 01/21] datastore/api: mark snapshots as trash on destroy Christian Ebner
2025-05-09 12:27 ` Fabian Grünbichler
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 02/21] datastore: mark groups " Christian Ebner
2025-05-09 12:27 ` Fabian Grünbichler
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 03/21] datastore: allow filtering of backups by their trash status Christian Ebner
2025-05-09 12:27 ` Fabian Grünbichler
2025-05-12 9:32 ` Christian Ebner
2025-05-12 10:08 ` Fabian Grünbichler
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 04/21] datastore: ignore trashed snapshots for last successful backup Christian Ebner
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 05/21] sync: ignore trashed snapshots when reading from local source Christian Ebner
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 06/21] api: tape: check trash marker when trying to write snapshot Christian Ebner
2025-05-09 12:27 ` Fabian Grünbichler
2025-05-12 9:19 ` Christian Ebner
2025-05-12 9:38 ` Fabian Grünbichler
2025-05-12 9:46 ` Christian Ebner
2025-05-12 9:55 ` Christian Ebner
2025-05-12 10:09 ` Fabian Grünbichler
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 07/21] sync: ignore trashed groups in local source reader Christian Ebner
2025-05-09 12:27 ` Fabian Grünbichler
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 08/21] datastore: namespace: add filter for trash status Christian Ebner
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 09/21] datastore: refactor recursive namespace removal Christian Ebner
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 10/21] datastore: mark namespace as trash instead of deleting it Christian Ebner
2025-05-09 12:27 ` Fabian Grünbichler
2025-05-12 7:47 ` Christian Ebner
2025-05-12 9:46 ` Fabian Grünbichler
2025-05-12 10:35 ` Christian Ebner
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 11/21] datastore: check for trash marker in namespace exists check Christian Ebner
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 12/21] datastore: clear trashed snapshot dir if re-creation requested Christian Ebner
2025-05-09 12:27 ` Fabian Grünbichler
2025-05-12 8:31 ` Christian Ebner
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 13/21] datastore: recreate trashed backup groups if requested Christian Ebner
2025-05-09 12:27 ` Fabian Grünbichler
2025-05-12 8:05 ` Christian Ebner
2025-05-12 10:02 ` Fabian Grünbichler
2025-05-08 13:05 ` Christian Ebner [this message]
2025-05-09 12:27 ` [pbs-devel] [RFC v2 proxmox-backup 14/21] datastore: GC: clean-up trashed snapshots, groups and namespaces Fabian Grünbichler
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 15/21] client: expose skip trash flags for cli commands Christian Ebner
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 16/21] api: datastore: add flag to list trashed snapshots only Christian Ebner
2025-05-09 12:27 ` Fabian Grünbichler
2025-05-12 7:57 ` Christian Ebner
2025-05-12 10:01 ` Fabian Grünbichler
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 17/21] api: namespace: add option to list all namespaces, including trashed Christian Ebner
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 18/21] api: admin: implement endpoints to restore trashed contents Christian Ebner
2025-05-09 12:27 ` Fabian Grünbichler
2025-05-09 12:59 ` Christian Ebner
2025-05-12 10:03 ` Fabian Grünbichler
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 19/21] ui: add recover for trashed items tab to datastore panel Christian Ebner
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 20/21] ui: drop 'permanent' in group/snapshot forget, default is to trash Christian Ebner
2025-05-08 13:05 ` [pbs-devel] [RFC v2 proxmox-backup 21/21] ui: allow to skip trash on namespace deletion Christian Ebner
2025-05-13 13:54 ` [pbs-devel] superseded: [RFC v2 proxmox-backup 00/21] implement trash bin functionality 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=20250508130555.494782-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal