Skip to content

Commit

Permalink
Merge pull request #249 from phreaker0/exit-with-error
Browse files Browse the repository at this point in the history
return a non zero exit code if there was a problem replicating datasets
  • Loading branch information
jimsalterjrs committed Aug 7, 2018
2 parents d1153a2 + 7c68ef5 commit 536fe96
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions syncoid
Expand Up @@ -97,6 +97,7 @@ my $targetsudocmd = $targetisroot ? '' : $sudocmd;
my %avail = checkcommands();

my %snaps;
my $exitcode = 0;

## break here to call replication individually so that we ##
## can loop across children separately, for recursive ##
Expand Down Expand Up @@ -127,7 +128,7 @@ if ($targethost ne '') {
close FH;
}

exit 0;
exit $exitcode;

##############################################################################
##############################################################################
Expand Down Expand Up @@ -186,6 +187,7 @@ sub syncdataset {
# make sure target is not currently in receive.
if (iszfsbusy($targethost,$targetfs,$targetisroot)) {
warn "Cannot sync now: $targetfs is already target of a zfs receive process.\n";
if ($exitcode < 1) { $exitcode = 1; }
return 0;
}

Expand Down Expand Up @@ -236,6 +238,7 @@ sub syncdataset {
$newsyncsnap = getnewestsnapshot($sourcehost,$sourcefs,$sourceisroot);
if ($newsyncsnap eq 0) {
warn "CRITICAL: no snapshots exist on source $sourcefs, and you asked for --no-sync-snap.\n";
if ($exitcode < 1) { $exitcode = 1; }
return 0;
}
}
Expand Down Expand Up @@ -292,6 +295,7 @@ sub syncdataset {
# make sure target is (still) not currently in receive.
if (iszfsbusy($targethost,$targetfs,$targetisroot)) {
warn "Cannot sync now: $targetfs is already target of a zfs receive process.\n";
if ($exitcode < 1) { $exitcode = 1; }
return 0;
}
system($synccmd) == 0
Expand All @@ -318,16 +322,20 @@ sub syncdataset {
# make sure target is (still) not currently in receive.
if (iszfsbusy($targethost,$targetfs,$targetisroot)) {
warn "Cannot sync now: $targetfs is already target of a zfs receive process.\n";
if ($exitcode < 1) { $exitcode = 1; }
return 0;
}

if (!$quiet) { print "INFO: Updating new target filesystem with incremental $sourcefs\@$oldestsnap ... $newsyncsnap (~ $disp_pvsize):\n"; }
if ($debug) { print "DEBUG: $synccmd\n"; }

if ($oldestsnap ne $newsyncsnap) {
system($synccmd) == 0
or warn "CRITICAL ERROR: $synccmd failed: $?";
my $ret = system($synccmd);
if ($ret != 0) {
warn "CRITICAL ERROR: $synccmd failed: $?";
if ($exitcode < 1) { $exitcode = 1; }
return 0;
}
} else {
if (!$quiet) { print "INFO: no incremental sync needed; $oldestsnap is already the newest available snapshot.\n"; }
}
Expand Down Expand Up @@ -380,6 +388,7 @@ sub syncdataset {
# make sure target is (still) not currently in receive.
if (iszfsbusy($targethost,$targetfs,$targetisroot)) {
warn "Cannot sync now: $targetfs is already target of a zfs receive process.\n";
if ($exitcode < 1) { $exitcode = 1; }
return 0;
}

Expand Down Expand Up @@ -910,6 +919,7 @@ sub getmatchingsnapshot {
}

# if we got this far, we failed to find a matching snapshot.
if ($exitcode < 2) { $exitcode = 2; }

print "\n";
print "CRITICAL ERROR: Target $targetfs exists but has no snapshots matching with $sourcefs!\n";
Expand Down

0 comments on commit 536fe96

Please sign in to comment.