mirror of https://github.com/jimsalterjrs/sanoid
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:
parent
63dd819ec5
commit
ecd1400539
21
syncoid
21
syncoid
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue