With "borgmatic check", consider Borg warnings as errors (#247).

This commit is contained in:
Dan Helfman 2019-11-17 19:06:28 -08:00
parent d99e6d1994
commit 2cc743cf47
7 changed files with 22 additions and 11 deletions

5
NEWS
View File

@ -1,3 +1,8 @@
1.4.12
* #247: With "borgmatic check", consider Borg warnings as errors.
* Dial back the display of inline error logs a bit, so failed command output doesn't appear
multiple times in the logs (well, except for the summary).
1.4.11
* #241: When using the Healthchecks monitoring hook, include borgmatic logs in the payloads for
completion and failure pings.

View File

@ -126,7 +126,7 @@ def check_archives(
+ (repository,)
)
execute_command(full_command)
execute_command(full_command, error_on_warnings=True)
if 'extract' in checks:
extract.extract_last_archive_dry_run(repository, lock_wait, local_path, remote_path)

View File

@ -390,7 +390,9 @@ def make_error_log_records(message, error=None):
except CalledProcessError as error:
yield log_record(levelno=logging.CRITICAL, levelname='CRITICAL', msg=message)
if error.output:
yield log_record(levelno=logging.CRITICAL, levelname='CRITICAL', msg=error.output)
yield logging.makeLogRecord(
dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg=error.output)
)
yield log_record(levelno=logging.CRITICAL, levelname='CRITICAL', msg=error)
except (ValueError, OSError) as error:
yield log_record(levelno=logging.CRITICAL, levelname='CRITICAL', msg=message)

View File

@ -57,10 +57,10 @@ tests](https://torsion.org/borgmatic/docs/how-to/extract-a-backup/).
## Error hooks
When an error occurs during a backup, borgmatic can run configurable shell
commands to fire off custom error notifications or take other actions, so you
can get alerted as soon as something goes wrong. Here's a not-so-useful
example:
When an error occurs during a backup or another action, borgmatic can run
configurable shell commands to fire off custom error notifications or take
other actions, so you can get alerted as soon as something goes wrong. Here's
a not-so-useful example:
```yaml
hooks:
@ -91,9 +91,10 @@ here:
* `output`: output of the command that failed (may be blank if an error
occurred without running a command)
Note that borgmatic does not run `on_error` hooks if an error occurs within a
`before_everything` or `after_everything` hook. For more about hooks, see the
[borgmatic hooks
Note that borgmatic runs the `on_error` hooks for any action in which an error
occurs, not just the `create` action. But borgmatic does not run `on_error`
hooks if an error occurs within a `before_everything` or `after_everything`
hook. For more about hooks, see the [borgmatic hooks
documentation](https://torsion.org/borgmatic/docs/how-to/add-preparation-and-cleanup-steps-to-backups/),
especially the security information.

View File

@ -1,6 +1,6 @@
from setuptools import find_packages, setup
VERSION = '1.4.11'
VERSION = '1.4.12'
setup(

View File

@ -9,7 +9,9 @@ from ..test_verbosity import insert_logging_mock
def insert_execute_command_mock(command):
flexmock(module).should_receive('execute_command').with_args(command).once()
flexmock(module).should_receive('execute_command').with_args(
command, error_on_warnings=True
).once()
def insert_execute_command_never():

View File

@ -129,6 +129,7 @@ def test_make_error_log_records_generates_output_logs_for_message_only():
def test_make_error_log_records_generates_output_logs_for_called_process_error():
flexmock(module).should_receive('log_record').replace_with(dict)
flexmock(module.logging).should_receive('makeLogRecord').replace_with(dict)
logs = tuple(
module.make_error_log_records(