[pve-devel] [PATCH V2 guest-common 3/6] Delete replication snapshots only if last_sync is not 0.

Wolfgang Link w.link at proxmox.com
Tue Dec 19 15:53:40 CET 2017


If last_sync is 0, the VM configuration has been stolen
(either manually or by HA restoration).
Under this condition, the replication snapshot should not be deleted.
This snapshot is used to restore replication state.
If the last_snap is greater than 0 and does not match the snap name
it must be a remnant of an earlier sync and should be deleted.
---
 PVE/Replication.pm | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/PVE/Replication.pm b/PVE/Replication.pm
index 6a20ba2..5f82dda 100644
--- a/PVE/Replication.pm
+++ b/PVE/Replication.pm
@@ -135,9 +135,14 @@ sub prepare {
 		(defined($parent_snapname) && ($snap eq $parent_snapname))) {
 		$last_snapshots->{$volid}->{$snap} = 1;
 	    } elsif ($snap =~ m/^\Q$prefix\E/) {
-		$logfunc->("delete stale replication snapshot '$snap' on $volid");
-		PVE::Storage::volume_snapshot_delete($storecfg, $volid, $snap);
-		$cleaned_replicated_volumes->{$volid} = 1;
+		if ($last_sync != 0) {
+		    $logfunc->("delete stale replication snapshot '$snap' on $volid");
+		    PVE::Storage::volume_snapshot_delete($storecfg, $volid, $snap);
+		    $cleaned_replicated_volumes->{$volid} = 1;
+		# Last_sync=0 and a replication snapshot only occur, if the VM was stolen
+		} else {
+		    $last_snapshots->{$volid}->{$snap} = 1;
+		}
 	    }
 	}
     }
@@ -203,11 +208,11 @@ sub replicate {
 	    my $store_list = [ map { (PVE::Storage::parse_volume_id($_))[0] } @$sorted_volids ];
 
 	    my $ssh_info = PVE::Cluster::get_ssh_info($jobcfg->{target});
-	    remote_prepare_local_job($ssh_info, $jobid, $vmid, [], $store_list, 0, undef, 1, $logfunc);
+	    remote_prepare_local_job($ssh_info, $jobid, $vmid, [], $store_list, 1, undef, 1, $logfunc);
 
 	}
 	# remove all local replication snapshots (lastsync => 0)
-	prepare($storecfg, $sorted_volids, $jobid, 0, undef, $logfunc);
+	prepare($storecfg, $sorted_volids, $jobid, 1, undef, $logfunc);
 
 	PVE::ReplicationConfig::delete_job($jobid); # update config
 	$logfunc->("job removed");
-- 
2.11.0





More information about the pve-devel mailing list