Browse Source

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

Dan Helfman 5 years ago
parent
commit
2cc743cf47

+ 5 - 0
NEWS

@@ -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.

+ 1 - 1
borgmatic/borg/check.py

@@ -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)

+ 3 - 1
borgmatic/commands/borgmatic.py

@@ -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)

+ 8 - 7
docs/how-to/monitor-your-backups.md

@@ -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.
 

+ 1 - 1
setup.py

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

+ 3 - 1
tests/unit/borg/test_check.py

@@ -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():

+ 1 - 0
tests/unit/commands/test_borgmatic.py

@@ -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(