public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox-offline-mirror 2/2] medium: remove snapshot link directories not present in source mirror
Date: Mon, 24 Jun 2024 21:57:12 +0200	[thread overview]
Message-ID: <20240624195712.962468-3-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20240624195712.962468-1-s.ivanov@proxmox.com>

Currently a medium sync takes care to remove all files and the links
in the individual snapshot directories, but leaves the empty snapshot
hierarchy in place. This causes a medium sync to take longer than
necessary, as we walk through the complete mirror on the medium,
including all empty link directories.

The status output is misleading as well, still showing more snapshots
than actually present (in the sense of containing any files).

Noticed on a system, which creates snapshots on a daily basis, after a
cleanup removing many snapshots and running garbage collection on the
mirror and the medium, still caused the medium sync to be quite slow.

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
 src/medium.rs | 18 +++++++++++++++++-
 src/types.rs  |  2 +-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/medium.rs b/src/medium.rs
index 53df50d..2c2d24e 100644
--- a/src/medium.rs
+++ b/src/medium.rs
@@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize};
 
 use crate::{
     config::{self, ConfigLockGuard, MediaConfig, MirrorConfig},
-    generate_repo_file_line,
+    generate_repo_file_line, mirror,
     mirror::pool,
     pool::Pool,
     types::{Diff, Snapshot, SNAPSHOT_REGEX},
@@ -404,6 +404,22 @@ pub fn sync(
             Pool::create(&mirror_base, &mirror_pool)?
         };
 
+        let source_snapshots: HashSet<Snapshot> =
+            mirror::list_snapshots(&mirror)?.iter().cloned().collect();
+        let target_snapshots: HashSet<Snapshot> = list_snapshots(medium_base, &mirror.id)?
+            .iter()
+            .cloned()
+            .collect();
+        let target_only_snapshots = target_snapshots.difference(&source_snapshots);
+        for snapshot in target_only_snapshots.into_iter() {
+            let path = target_pool.get_path(Path::new(&snapshot.to_string()))?;
+            println!(
+                "Removing snapshot no longer present on mirror: {:?}",
+                &snapshot.to_string()
+            );
+            target_pool.lock()?.remove_dir(&path)?;
+        }
+
         let source_pool: Pool = pool(&mirror)?;
         source_pool.lock()?.sync_pool(&target_pool, medium.verify)?;
 
diff --git a/src/types.rs b/src/types.rs
index 7544d5e..94eee79 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -71,7 +71,7 @@ const_regex! {
     type: String,
     format: &ApiStringFormat::Pattern(&SNAPSHOT_REGEX),
 )]
-#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord)]
+#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
 /// Mirror snapshot
 pub struct Snapshot(i64);
 
-- 
2.39.2



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


  parent reply	other threads:[~2024-06-24 19:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-24 19:57 [pve-devel] [PATCH proxmox-offline-mirror 0/2] remove snapshot directories vanished on source also on medium Stoiko Ivanov
2024-06-24 19:57 ` [pve-devel] [PATCH proxmox-offline-mirror 1/2] bump proxmox-time to 2.0 Stoiko Ivanov
2024-06-26  6:40   ` [pve-devel] applied: " Fabian Grünbichler
2024-06-24 19:57 ` Stoiko Ivanov [this message]
2024-06-26 10:24   ` [pve-devel] [PATCH proxmox-offline-mirror 2/2] medium: remove snapshot link directories not present in source mirror Fabian Grünbichler
2024-07-09 10:50 ` [pve-devel] [PATCH proxmox-offline-mirror 0/2] remove snapshot directories vanished on source also on medium Stoiko Ivanov

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=20240624195712.962468-3-s.ivanov@proxmox.com \
    --to=s.ivanov@proxmox.com \
    --cc=pve-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