btrbk: return exit status 10 instead of 0 if one or more backup tasks aborted, and exit status 2 on parse errors

pull/57/head
Axel Burri 2015-09-30 14:00:39 +02:00
parent e177ae1c87
commit 1905d80969
3 changed files with 33 additions and 13 deletions

View File

@ -10,6 +10,8 @@ btrbk-current
(experimental).
* Added configuration option "timestamp_format short|long".
* Bugfix: correctly handle "incremental no" option.
* Bugfix: return exit status 10 instead of 0 if one or more backup
tasks aborted.
* Hardened ssh_filter_btrbk.sh script: fine-grained access control,
restrict-path option, sudo option (close: #45).

30
btrbk
View File

@ -1642,7 +1642,7 @@ MAIN:
my ($config_cmdline, $quiet, $verbose, $preserve_backups, $resume_only);
unless(GetOptions(
'help|h' => sub { VERSION_MESSAGE(); HELP_MESSAGE(0); exit 0; },
'version' => sub { VERSION_MESSAGE(); exit 0; },,
'version' => sub { VERSION_MESSAGE(); exit 0; },
'config|c=s' => \$config_cmdline,
'preserve|p' => \$preserve_backups,
'resume-only|r' => \$resume_only,
@ -1655,13 +1655,13 @@ MAIN:
{
VERSION_MESSAGE();
HELP_MESSAGE(0);
exit 1;
exit 2;
}
my $command = shift @ARGV;
unless($command) {
VERSION_MESSAGE();
HELP_MESSAGE(0);
exit 0;
exit 2;
}
# assign command line options
@ -1723,7 +1723,7 @@ MAIN:
{
ERROR "unknown subcommand for \"config\" command: $action_config";
HELP_MESSAGE(0);
exit 1;
exit 2;
}
$args_expected_min = 0;
$args_expected_max = 9999;
@ -1733,12 +1733,12 @@ MAIN:
else {
ERROR "Unrecognized command: $command";
HELP_MESSAGE(0);
exit 1;
exit 2;
}
if(($args_expected_min > scalar(@ARGV)) || ($args_expected_max < scalar(@ARGV))) {
ERROR "Incorrect number of arguments";
HELP_MESSAGE(0);
exit 1;
exit 2;
}
# input validation
@ -1759,7 +1759,7 @@ MAIN:
else {
ERROR "Bad argument: not a subvolume" . ($args_allow_group ? "/group" : "") . " declaration: $_";
HELP_MESSAGE(0);
exit 1;
exit 2;
}
}
@ -1871,11 +1871,11 @@ MAIN:
my $config = parse_config(@config_src);
unless($config) {
ERROR "Failed to parse configuration file";
exit 1;
exit 2;
}
unless(ref($config->{VOLUME}) eq "ARRAY") {
ERROR "No volumes defined in configuration file";
exit 1;
exit 2;
}
@ -1950,7 +1950,7 @@ MAIN:
foreach(@nomatch) {
ERROR "Command line argument does not match any volume, subvolume, target or group declaration: $_";
}
exit 1;
exit 2;
}
$config->{CMDLINE_FILTER_LIST} = [ values %match ];
}
@ -2825,6 +2825,16 @@ MAIN:
}
}
}
foreach my $config_vol (@{$config->{VOLUME}}) {
exit 10 if($config_vol->{ABORTED} && ($config_vol->{ABORTED} ne "USER_SKIP"));
foreach my $config_subvol (@{$config_vol->{SUBVOLUME}}) {
exit 10 if($config_subvol->{ABORTED} && ($config_subvol->{ABORTED} ne "USER_SKIP"));
foreach my $config_target (@{$config_subvol->{TARGET}}) {
exit 10 if($config_target->{ABORTED} && ($config_target->{ABORTED} ne "USER_SKIP"));
}
}
}
}
}

View File

@ -238,9 +238,17 @@ are described in
.RE
.PD
.SH EXIT STATUS
.sp
\fBbtrbk\fR returns a zero exit status if it succeeds. Non-zero is
returned in case of failure.
\fBbtrbk\fR returns the following error codes:
.IP "0" 4
No problems occurred.
.IP "1" 4
Generic error code.
.IP "2" 4
Parse error: when parsing command-line options or configuration file.
.IP "10" 4
Backup abort: At least one backup task aborted.
.IP "255" 4
Script error.
.SH AVAILABILITY
Please refer to the btrbk project page
\fBhttp://www.digint.ch/btrbk/\fR for further