From 1905d80969a9e7b410dc52c43b5c37bfaada30a4 Mon Sep 17 00:00:00 2001 From: Axel Burri Date: Wed, 30 Sep 2015 14:00:39 +0200 Subject: [PATCH] btrbk: return exit status 10 instead of 0 if one or more backup tasks aborted, and exit status 2 on parse errors --- ChangeLog | 2 ++ btrbk | 30 ++++++++++++++++++++---------- doc/btrbk.1 | 14 +++++++++++--- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index d0b7b15..40f1f47 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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). diff --git a/btrbk b/btrbk index c944565..39485b5 100755 --- a/btrbk +++ b/btrbk @@ -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")); + } + } + } } } diff --git a/doc/btrbk.1 b/doc/btrbk.1 index aa2dc37..47cdb78 100644 --- a/doc/btrbk.1 +++ b/doc/btrbk.1 @@ -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