Delete replication snapshots only if last_sync is not 0.

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.
This commit is contained in:
Wolfgang Link 2018-05-09 14:48:23 +02:00 committed by Wolfgang Bumiller
parent 4ea5167ef0
commit a1dfeff3a8

View File

@ -135,8 +135,8 @@ sub prepare {
(defined($parent_snapname) && ($snap eq $parent_snapname))) { (defined($parent_snapname) && ($snap eq $parent_snapname))) {
$last_snapshots->{$volid}->{$snap} = 1; $last_snapshots->{$volid}->{$snap} = 1;
} elsif ($snap =~ m/^\Q$prefix\E/) { } elsif ($snap =~ m/^\Q$prefix\E/) {
if ($last_sync != 0) {
$logfunc->("delete stale replication snapshot '$snap' on $volid"); $logfunc->("delete stale replication snapshot '$snap' on $volid");
eval { eval {
PVE::Storage::volume_snapshot_delete($storecfg, $volid, $snap); PVE::Storage::volume_snapshot_delete($storecfg, $volid, $snap);
$cleaned_replicated_volumes->{$volid} = 1; $cleaned_replicated_volumes->{$volid} = 1;
@ -152,6 +152,10 @@ sub prepare {
# logfunc will written in replication log. # logfunc will written in replication log.
$logfunc->("delete stale replication snapshot error: $err"); $logfunc->("delete stale replication snapshot error: $err");
} }
# Last_sync=0 and a replication snapshot only occur, if the VM was stolen
} else {
$last_snapshots->{$volid}->{$snap} = 1;
}
} }
} }
} }
@ -219,12 +223,11 @@ sub replicate {
my %hash = map { $_ => 1 } @store_list; my %hash = map { $_ => 1 } @store_list;
my $ssh_info = PVE::Cluster::get_ssh_info($jobcfg->{target}); my $ssh_info = PVE::Cluster::get_ssh_info($jobcfg->{target});
remote_prepare_local_job($ssh_info, $jobid, $vmid, [], [ keys %hash ], 1, undef, 1, $logfunc); remote_prepare_local_job($ssh_info, $jobid, $vmid, [], [ keys %hash ], 1, undef, 1, $logfunc);
} }
# remove all local replication snapshots (lastsync => 0) # 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 PVE::ReplicationConfig::delete_job($jobid); # update config
$logfunc->("job removed"); $logfunc->("job removed");