public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH zsync 3/6] remove all old snapshots belonging to a job
Date: Tue, 11 May 2021 14:59:52 +0200	[thread overview]
Message-ID: <20210511125955.25105-4-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210511125955.25105-1-f.ebner@proxmox.com>

Changing maxsnap to something smaller can lead to left-over snaphsots otherwise,
as previously at most one snapshot would be removed, even if there are multiple
old snapshots according to the new setting.

Hopefully nobody relied on the fact that pve-zsync didn't clean up after itself
in such cases...

Negative values and 0 for 'maxsnap' should still be interpreted as infinity to
match the previous behavior.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
 pve-zsync | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/pve-zsync b/pve-zsync
index 6ca2da1..ff05f46 100755
--- a/pve-zsync
+++ b/pve-zsync
@@ -685,8 +685,9 @@ sub sync {
 
 	    send_image($source, $dest, $param);
 
-	    snapshot_destroy($source, $dest, $param->{method}, $dest->{old_snap}, $param->{source_user}, $param->{dest_user}) if ($source->{destroy} && $dest->{old_snap});
-
+	    for my $old_snap (@{$dest->{old_snap}}) {
+		snapshot_destroy($source, $dest, $param->{method}, $old_snap, $param->{source_user}, $param->{dest_user});
+	    }
 	};
 
 	eval{
@@ -763,7 +764,7 @@ sub snapshot_get{
     my $index = 0;
     my $line = "";
     my $last_snap = undef;
-    my $old_snap;
+    my $old_snap = [];
 
     while ($raw && $raw =~ s/^(.*?)(\n|$)//) {
 	$line = $1;
@@ -771,12 +772,15 @@ sub snapshot_get{
 	    $last_snap = $1 if (!$last_snap);
 	}
 	if ($line =~ m/(rep_\Q${name}\E_\d{4}-\d{2}-\d{2}_\d{2}:\d{2}:\d{2})$/) {
-	    $old_snap = $1;
+	    # interpreted as infinity
+	    last if $max_snap <= 0;
+
+	    my $snap = $1;
 	    $index++;
-	    if ($index == $max_snap) {
-		$source->{destroy} = 1;
-		last;
-	    };
+
+	    if ($index >= $max_snap) {
+		push @{$old_snap}, $snap;
+	    }
 	}
     }
 
@@ -1067,8 +1071,8 @@ sub send_config{
 	    run_cmd(['scp', '--', "$source_user\@[$source->{ip}]:$source_target", $dest_target_new]);
 	}
 
-	if ($source->{destroy}){
-	    my $dest_target_old ="${config_dir}/$source->{vmid}.conf.$source->{vm_type}.$dest->{old_snap}";
+	for my $old_snap (@{$dest->{old_snap}}) {
+	    my $dest_target_old ="${config_dir}/$source->{vmid}.conf.$source->{vm_type}.${old_snap}";
 	    if($dest->{ip}){
 		run_cmd(['ssh', "$dest_user\@$dest->{ip}", '--', 'rm', '-f', '--', $dest_target_old]);
 	    } else {
-- 
2.20.1





  parent reply	other threads:[~2021-05-11 13:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-11 12:59 [pve-devel] [PATCH-SERIES zsync] fix #3351: allow keeping a different number of snapshots on source and destination Fabian Ebner
2021-05-11 12:59 ` [pve-devel] [PATCH zsync 1/6] param_to_job: handle --maxsnap 0 on creation Fabian Ebner
2021-05-11 12:59 ` [pve-devel] [PATCH zsync 2/6] usage: improve maxsnap description Fabian Ebner
2021-05-11 12:59 ` Fabian Ebner [this message]
2021-05-11 12:59 ` [pve-devel] [PATCH zsync 4/6] snapshot_get: make interface agnostic to source/dest Fabian Ebner
2021-05-11 12:59 ` [pve-devel] [PATCH zsync 5/6] snapshot_destroy: " Fabian Ebner
2021-05-11 12:59 ` [pve-devel] [PATCH zsync 6/6] fix #3351: allow keeping a different number of snapshots on source and destination Fabian Ebner
2021-05-24 16:00   ` Bruce Wainer
2021-05-25  5:10     ` Thomas Lamprecht
2021-05-25 12:02 ` [pve-devel] applied-series: [PATCH-SERIES zsync] " Thomas Lamprecht

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=20210511125955.25105-4-f.ebner@proxmox.com \
    --to=f.ebner@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