5
0
mirror of git://git.proxmox.com/git/pve-zsync.git synced 2025-03-10 16:58:41 +03:00

snapshot_destroy: make interface agnostic to source/dest

Also drop the 'method' parameter which is not used consistently (e.g. ignored
in the later half of the very same function, in snapshot_exist, vm_exists,...),
and not documented. Simply rely on the presence of the IP address as is done in
many other places already.

In snapshot_add, there is no need to try and destroy the snapshot on the
destination (did happen previously, because $dest was passed along), because we
just failed to create the snapshot on the source side.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
Fabian Ebner 2021-05-11 14:59:54 +02:00 committed by Thomas Lamprecht
parent 3b115c2845
commit 103f89134f

View File

@ -694,7 +694,8 @@ sub sync {
send_image($source, $dest, $param);
for my $old_snap (@{$dest->{old_snap}}) {
snapshot_destroy($source, $dest, $param->{method}, $old_snap, $param->{source_user}, $param->{dest_user});
snapshot_destroy($source->{all}, $old_snap, $source->{ip}, $param->{source_user});
snapshot_destroy($dest_dataset, $old_snap, $dest->{ip}, $param->{dest_user});
}
};
@ -812,7 +813,7 @@ sub snapshot_add {
};
if (my $err = $@) {
snapshot_destroy($source, $dest, 'ssh', $snap_name, $source_user, $dest_user);
snapshot_destroy($source->{all}, $snap_name, $source->{ip}, $source_user);
die "$err\n";
}
}
@ -967,14 +968,14 @@ sub prepare_prepended_target {
}
sub snapshot_destroy {
my ($source, $dest, $method, $snap, $source_user, $dest_user) = @_;
my ($dataset, $snap, $ip, $user) = @_;
my @zfscmd = ('zfs', 'destroy');
my $snapshot = "$source->{all}\@$snap";
my $snapshot = "$dataset\@$snap";
eval {
if($source->{ip} && $method eq 'ssh'){
run_cmd(['ssh', "$source_user\@$source->{ip}", '--', @zfscmd, $snapshot]);
if ($ip) {
run_cmd(['ssh', "$user\@$ip", '--', @zfscmd, $snapshot]);
} else {
run_cmd([@zfscmd, $snapshot]);
}
@ -982,18 +983,6 @@ sub snapshot_destroy {
if (my $erro = $@) {
warn "WARN: $erro";
}
if ($dest) {
my @ssh = $dest->{ip} ? ('ssh', "$dest_user\@$dest->{ip}", '--') : ();
my $path = target_dataset($source, $dest);
eval {
run_cmd([@ssh, @zfscmd, "$path\@$snap"]);
};
if (my $erro = $@) {
warn "WARN: $erro";
}
}
}
# check if snapshot for incremental sync exist on source side
@ -1048,7 +1037,7 @@ sub send_image {
};
if (my $erro = $@) {
snapshot_destroy($source, undef, $param->{method}, $source->{new_snap}, $param->{source_user}, $param->{dest_user});
snapshot_destroy($source->{all}, $source->{new_snap}, $source->{ip}, $param->{source_user});
die $erro;
};
}