[pbs-devel] [PATCH v3 proxmox-backup 13/20] datastore: garbage collection: clean-up trashed snapshots and groups

Christian Ebner c.ebner at proxmox.com
Tue May 13 15:52:40 CEST 2025


Cleanup trashed items during phase 1 of garbage collection. If
encountered, index files located within trashed snapshots are still
touched.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
 pbs-datastore/src/backup_info.rs |  2 +-
 pbs-datastore/src/datastore.rs   | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/pbs-datastore/src/backup_info.rs b/pbs-datastore/src/backup_info.rs
index ca0c4bc55..f334600c7 100644
--- a/pbs-datastore/src/backup_info.rs
+++ b/pbs-datastore/src/backup_info.rs
@@ -277,7 +277,7 @@ impl BackupGroup {
     }
 
     /// Helper function, assumes that no more snapshots are present in the group.
-    fn remove_group_dir(&self) -> Result<(), Error> {
+    pub(crate) fn remove_group_dir(&self) -> Result<(), Error> {
         let trash_path = self.full_group_path().join(TRASH_MARKER_FILENAME);
         if let Err(err) = std::fs::remove_file(&trash_path) {
             if err.kind() != std::io::ErrorKind::NotFound {
diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
index 1bc096420..fd6eaadbb 100644
--- a/pbs-datastore/src/datastore.rs
+++ b/pbs-datastore/src/datastore.rs
@@ -1254,10 +1254,38 @@ impl DataStore {
                             }
                             processed_index_files += 1;
                         }
+
+                        // Only try to lock 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_trash() {
+                            if let Ok(_lock) = snapshot.backup_dir.lock() {
+                                if snapshot.backup_dir.is_trash() {
+                                    snapshot.backup_dir.destroy(true, true)?;
+                                }
+                            } else {
+                                let path = snapshot.backup_dir.full_path();
+                                warn!("failed to lock trashed backup snapshot {path:?}, ignore");
+                            }
+                        }
                     }
 
                     break;
                 }
+                if group.is_trash() {
+                    if let Ok(_lock) = group.lock() {
+                        if group.is_trash() {
+                            if let Err(err) = group.remove_group_dir() {
+                                let path = group.full_group_path();
+                                warn!("failed to remove trashed backup group {path:?} - {err}");
+                            }
+                        } else {
+                            let path = group.full_group_path();
+                            warn!("failed to lock trashed backup group {path:?}");
+                        }
+                    }
+                }
             }
         }
 
-- 
2.39.5





More information about the pbs-devel mailing list