Handle output/errors of those zfs destroy commands.

If there was an obsolete remote syncoid_hostname_* snapshot that did not
get removed at the correct time, for some reason, like, maybe, network
problems, it would have been cleaned up in pruneoldsyncsnaps just before
this code, and we would get a strange error message saying:

    could not find any snapshots to destroy; check snapshot names.

Also, when using --quiet, do not output anything, as failing to remove
an obsolete snapshot is not really a big problem.
This commit is contained in:
Mathieu Arnold 2020-08-17 16:36:14 +02:00
parent 63dd819ec5
commit ecd1400539
No known key found for this signature in database
GPG Key ID: 7F620E0A9E9D41BE
1 changed files with 12 additions and 9 deletions

21
syncoid
View File

@ -890,15 +890,18 @@ sub syncdataset {
}
if (defined $args{'delete-target-snapshots'}) {
foreach my $snap ( sort { $snaps{'target'}{$a}{'creation'}<=>$snaps{'target'}{$b}{'creation'} } keys %{ $snaps{'target'} }) {
if (!exists $snaps{'source'}{$snap}) {
if ($targethost ne '') {
if ($debug) { print "$sshcmd $targethost $targetsudocmd $zfscmd destroy $targetfsescaped\@$snap\n"; }
system ("$sshcmd $targethost " . escapeshellparam("$targetsudocmd $zfscmd destroy $targetfsescaped\@$snap"));
} else {
if ($debug) { print "$targetsudocmd $zfscmd destroy $targetfsescaped\@$snap\n"; }
system ("$targetsudocmd $zfscmd destroy $targetfsescaped\@$snap");
}
my $snaps = join ',', grep {!exists $snaps{'source'}{$_}} keys %{ $snaps{'target'} };
if ($snaps ne '') {
my $command;
if ($targethost ne '') {
$command = "$sshcmd $targethost " . escapeshellparam("$targetsudocmd $zfscmd destroy $targetfsescaped\@$snaps");
} else {
$command = "$targetsudocmd $zfscmd destroy $targetfsescaped\@$snaps";
}
if ($debug) { print "$command\n"; }
my ($stdout, $stderr, $result) = capture { system $command; };
if ($result != 0 && !$quiet) {
warn "$command failed: $stderr";
}
}
}