return a non zero exit code if there was a problem replicating datasets

This commit is contained in:
Christoph Klaffl 2018-07-29 13:16:53 +02:00
parent d1153a244f
commit 7c68ef5e8f
No known key found for this signature in database
GPG Key ID: FC1C525C2A47CC28
1 changed files with 13 additions and 3 deletions

16
syncoid
View File

@ -97,6 +97,7 @@ my $targetsudocmd = $targetisroot ? '' : $sudocmd;
my %avail = checkcommands(); my %avail = checkcommands();
my %snaps; my %snaps;
my $exitcode = 0;
## break here to call replication individually so that we ## ## break here to call replication individually so that we ##
## can loop across children separately, for recursive ## ## can loop across children separately, for recursive ##
@ -127,7 +128,7 @@ if ($targethost ne '') {
close FH; close FH;
} }
exit 0; exit $exitcode;
############################################################################## ##############################################################################
############################################################################## ##############################################################################
@ -186,6 +187,7 @@ sub syncdataset {
# make sure target is not currently in receive. # make sure target is not currently in receive.
if (iszfsbusy($targethost,$targetfs,$targetisroot)) { if (iszfsbusy($targethost,$targetfs,$targetisroot)) {
warn "Cannot sync now: $targetfs is already target of a zfs receive process.\n"; warn "Cannot sync now: $targetfs is already target of a zfs receive process.\n";
if ($exitcode < 1) { $exitcode = 1; }
return 0; return 0;
} }
@ -236,6 +238,7 @@ sub syncdataset {
$newsyncsnap = getnewestsnapshot($sourcehost,$sourcefs,$sourceisroot); $newsyncsnap = getnewestsnapshot($sourcehost,$sourcefs,$sourceisroot);
if ($newsyncsnap eq 0) { if ($newsyncsnap eq 0) {
warn "CRITICAL: no snapshots exist on source $sourcefs, and you asked for --no-sync-snap.\n"; warn "CRITICAL: no snapshots exist on source $sourcefs, and you asked for --no-sync-snap.\n";
if ($exitcode < 1) { $exitcode = 1; }
return 0; return 0;
} }
} }
@ -292,6 +295,7 @@ sub syncdataset {
# make sure target is (still) not currently in receive. # make sure target is (still) not currently in receive.
if (iszfsbusy($targethost,$targetfs,$targetisroot)) { if (iszfsbusy($targethost,$targetfs,$targetisroot)) {
warn "Cannot sync now: $targetfs is already target of a zfs receive process.\n"; warn "Cannot sync now: $targetfs is already target of a zfs receive process.\n";
if ($exitcode < 1) { $exitcode = 1; }
return 0; return 0;
} }
system($synccmd) == 0 system($synccmd) == 0
@ -318,6 +322,7 @@ sub syncdataset {
# make sure target is (still) not currently in receive. # make sure target is (still) not currently in receive.
if (iszfsbusy($targethost,$targetfs,$targetisroot)) { if (iszfsbusy($targethost,$targetfs,$targetisroot)) {
warn "Cannot sync now: $targetfs is already target of a zfs receive process.\n"; warn "Cannot sync now: $targetfs is already target of a zfs receive process.\n";
if ($exitcode < 1) { $exitcode = 1; }
return 0; return 0;
} }
@ -325,9 +330,12 @@ sub syncdataset {
if ($debug) { print "DEBUG: $synccmd\n"; } if ($debug) { print "DEBUG: $synccmd\n"; }
if ($oldestsnap ne $newsyncsnap) { if ($oldestsnap ne $newsyncsnap) {
system($synccmd) == 0 my $ret = system($synccmd);
or warn "CRITICAL ERROR: $synccmd failed: $?"; if ($ret != 0) {
warn "CRITICAL ERROR: $synccmd failed: $?";
if ($exitcode < 1) { $exitcode = 1; }
return 0; return 0;
}
} else { } else {
if (!$quiet) { print "INFO: no incremental sync needed; $oldestsnap is already the newest available snapshot.\n"; } if (!$quiet) { print "INFO: no incremental sync needed; $oldestsnap is already the newest available snapshot.\n"; }
} }
@ -380,6 +388,7 @@ sub syncdataset {
# make sure target is (still) not currently in receive. # make sure target is (still) not currently in receive.
if (iszfsbusy($targethost,$targetfs,$targetisroot)) { if (iszfsbusy($targethost,$targetfs,$targetisroot)) {
warn "Cannot sync now: $targetfs is already target of a zfs receive process.\n"; warn "Cannot sync now: $targetfs is already target of a zfs receive process.\n";
if ($exitcode < 1) { $exitcode = 1; }
return 0; return 0;
} }
@ -910,6 +919,7 @@ sub getmatchingsnapshot {
} }
# if we got this far, we failed to find a matching snapshot. # if we got this far, we failed to find a matching snapshot.
if ($exitcode < 2) { $exitcode = 2; }
print "\n"; print "\n";
print "CRITICAL ERROR: Target $targetfs exists but has no snapshots matching with $sourcefs!\n"; print "CRITICAL ERROR: Target $targetfs exists but has no snapshots matching with $sourcefs!\n";