[pve-devel] [pve-guest-common] PVE::Replication::prepare - allow to pass undefined $jobid

Dietmar Maurer dietmar at proxmox.com
Mon Jun 12 08:03:24 CEST 2017


And remove all replication snapshots in that case. This is useful
for snapshot rollback.

Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 PVE/Replication.pm | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/PVE/Replication.pm b/PVE/Replication.pm
index f978267..0fa0ffe 100644
--- a/PVE/Replication.pm
+++ b/PVE/Replication.pm
@@ -79,15 +79,21 @@ sub prepare {
 
     $last_sync //= 0;
 
-    my ($prefix, $snapname) =
-	PVE::ReplicationState::replication_snapshot_name($jobid, $last_sync);
+    my ($prefix, $snapname);
+
+    if (defined($jobid)) {
+	($prefix, $snapname) = PVE::ReplicationState::replication_snapshot_name($jobid, $last_sync);
+    } else {
+	$prefix = '__replicate_';
+    }
 
     my $last_snapshots = {};
     my $cleaned_replicated_volumes = {};
     foreach my $volid (@$volids) {
 	my $list = PVE::Storage::volume_snapshot_list($storecfg, $volid);
 	foreach my $snap (@$list) {
-	    if ($snap eq $snapname || (defined($parent_snapname) && ($snap eq $parent_snapname))) {
+	    if ((defined($snapname) && ($snap eq $snapname)) ||
+		(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");
-- 
2.11.0




More information about the pve-devel mailing list