mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-07-22 18:13:02 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da459d95b8 | ||
|
|
b3aa6af859 | ||
|
|
b816af1b13 | ||
|
|
276aeb9875 | ||
|
|
de94001508 | ||
|
|
7cfab3620b | ||
|
|
6c136ebbf1 | ||
|
|
eaa5eb4174 | ||
|
|
acc2a39454 | ||
|
|
a10c7a8496 |
@@ -0,0 +1,31 @@
|
||||
#### What I'm trying to do and why
|
||||
|
||||
#### Steps to reproduce (if a bug)
|
||||
|
||||
Include (sanitized) borgmatic configuration files if applicable.
|
||||
|
||||
#### Actual behavior (if a bug)
|
||||
|
||||
Include (sanitized) `--verbosity 2` output if applicable.
|
||||
|
||||
#### Expected behavior (if a bug)
|
||||
|
||||
#### Other notes / implementation ideas
|
||||
|
||||
#### Environment
|
||||
|
||||
**borgmatic version:** [version here]
|
||||
|
||||
Use `sudo borgmatic --version` or `sudo pip show borgmatic | grep ^Version`
|
||||
|
||||
**borgmatic installation method:** [e.g., Debian package, Docker container, etc.]
|
||||
|
||||
**Borg version:** [version here]
|
||||
|
||||
Use `sudo borg --version`
|
||||
|
||||
**Python version:** [version here]
|
||||
|
||||
Use `python --version`
|
||||
|
||||
**operating system and version:** [OS here]
|
||||
@@ -1,3 +1,8 @@
|
||||
1.3.7
|
||||
* #196: Fix for unclear error message for invalid YAML merge include.
|
||||
* #197: Don't color syslog output.
|
||||
* Change default syslog verbosity to show errors only.
|
||||
|
||||
1.3.6
|
||||
* #53: Log to syslog in addition to existing console logging. Add --syslog-verbosity flag to
|
||||
customize the log level. See the documentation for more information:
|
||||
|
||||
@@ -2,13 +2,12 @@ import logging
|
||||
|
||||
from borgmatic.borg import extract
|
||||
from borgmatic.execute import execute_command
|
||||
from borgmatic.logger import get_logger
|
||||
|
||||
DEFAULT_CHECKS = ('repository', 'archives')
|
||||
DEFAULT_PREFIX = '{hostname}-'
|
||||
|
||||
|
||||
logger = get_logger(__name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _parse_checks(consistency_config):
|
||||
|
||||
@@ -5,9 +5,8 @@ import os
|
||||
import tempfile
|
||||
|
||||
from borgmatic.execute import execute_command
|
||||
from borgmatic.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _expand_directory(directory):
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import logging
|
||||
|
||||
from borgmatic.execute import execute_command
|
||||
from borgmatic.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def extract_last_archive_dry_run(repository, lock_wait=None, local_path='borg', remote_path=None):
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import logging
|
||||
|
||||
from borgmatic.execute import execute_command
|
||||
from borgmatic.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def display_archives_info(
|
||||
|
||||
@@ -2,9 +2,8 @@ import logging
|
||||
import subprocess
|
||||
|
||||
from borgmatic.execute import execute_command
|
||||
from borgmatic.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
INFO_REPOSITORY_NOT_FOUND_EXIT_CODE = 2
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import logging
|
||||
|
||||
from borgmatic.execute import execute_command
|
||||
from borgmatic.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def list_archives(
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import logging
|
||||
|
||||
from borgmatic.execute import execute_command
|
||||
from borgmatic.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _make_prune_flags(retention_config):
|
||||
|
||||
@@ -19,11 +19,11 @@ from borgmatic.borg import init as borg_init
|
||||
from borgmatic.borg import list as borg_list
|
||||
from borgmatic.borg import prune as borg_prune
|
||||
from borgmatic.config import checks, collect, convert, validate
|
||||
from borgmatic.logger import configure_logging, get_logger, should_do_markup
|
||||
from borgmatic.logger import configure_logging, should_do_markup
|
||||
from borgmatic.signals import configure_signals
|
||||
from borgmatic.verbosity import verbosity_to_log_level
|
||||
|
||||
logger = get_logger(__name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
LEGACY_CONFIG_PATH = '/etc/borgmatic/config'
|
||||
|
||||
@@ -182,7 +182,7 @@ def parse_arguments(*arguments):
|
||||
'--syslog-verbosity',
|
||||
type=int,
|
||||
choices=range(0, 3),
|
||||
default=1,
|
||||
default=0,
|
||||
help='Display verbose progress to syslog (from none to lots: 0, 1, or 2)',
|
||||
)
|
||||
common_group.add_argument(
|
||||
|
||||
@@ -3,9 +3,8 @@ import sys
|
||||
from argparse import ArgumentParser
|
||||
|
||||
from borgmatic.config import collect, validate
|
||||
from borgmatic.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def parse_arguments(*arguments):
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
import ruamel.yaml
|
||||
|
||||
from borgmatic.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def load_configuration(filename):
|
||||
@@ -54,9 +53,7 @@ class Include_constructor(ruamel.yaml.SafeConstructor):
|
||||
|
||||
for index, (key_node, value_node) in enumerate(node.value):
|
||||
if key_node.tag == u'tag:yaml.org,2002:merge' and value_node.tag == '!include':
|
||||
included_value = representer.represent_mapping(
|
||||
tag='tag:yaml.org,2002:map', mapping=self.construct_object(value_node)
|
||||
)
|
||||
included_value = representer.represent_data(self.construct_object(value_node))
|
||||
node.value[index] = (key_node, included_value)
|
||||
|
||||
super(Include_constructor, self).flatten_mapping(node)
|
||||
|
||||
@@ -6,9 +6,8 @@ import pykwalify.errors
|
||||
import ruamel.yaml
|
||||
|
||||
from borgmatic.config import load
|
||||
from borgmatic.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def schema_filename():
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
from borgmatic.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def execute_and_log_output(full_command, output_log_level, shell):
|
||||
|
||||
+1
-2
@@ -2,9 +2,8 @@ import logging
|
||||
import os
|
||||
|
||||
from borgmatic import execute
|
||||
from borgmatic.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def execute_hook(commands, umask, config_filename, description, dry_run):
|
||||
|
||||
+4
-46
@@ -45,52 +45,10 @@ LOG_LEVEL_TO_COLOR = {
|
||||
}
|
||||
|
||||
|
||||
class Borgmatic_logger(logging.Logger):
|
||||
def critical(self, msg, *args, **kwargs):
|
||||
color = LOG_LEVEL_TO_COLOR.get(logging.CRITICAL)
|
||||
|
||||
return super(Borgmatic_logger, self).critical(color_text(color, msg), *args, **kwargs)
|
||||
|
||||
def error(self, msg, *args, **kwargs):
|
||||
color = LOG_LEVEL_TO_COLOR.get(logging.ERROR)
|
||||
|
||||
return super(Borgmatic_logger, self).error(color_text(color, msg), *args, **kwargs)
|
||||
|
||||
def warn(self, msg, *args, **kwargs):
|
||||
color = LOG_LEVEL_TO_COLOR.get(logging.WARN)
|
||||
|
||||
return super(Borgmatic_logger, self).warn(color_text(color, msg), *args, **kwargs)
|
||||
|
||||
def info(self, msg, *args, **kwargs):
|
||||
color = LOG_LEVEL_TO_COLOR.get(logging.INFO)
|
||||
|
||||
return super(Borgmatic_logger, self).info(color_text(color, msg), *args, **kwargs)
|
||||
|
||||
def debug(self, msg, *args, **kwargs):
|
||||
color = LOG_LEVEL_TO_COLOR.get(logging.DEBUG)
|
||||
|
||||
return super(Borgmatic_logger, self).debug(color_text(color, msg), *args, **kwargs)
|
||||
|
||||
def handle(self, record):
|
||||
class Console_color_formatter(logging.Formatter):
|
||||
def format(self, record):
|
||||
color = LOG_LEVEL_TO_COLOR.get(record.levelno)
|
||||
colored_record = logging.makeLogRecord(
|
||||
dict(
|
||||
levelno=record.levelno,
|
||||
levelname=record.levelname,
|
||||
msg=color_text(color, record.msg),
|
||||
)
|
||||
)
|
||||
|
||||
return super(Borgmatic_logger, self).handle(colored_record)
|
||||
|
||||
|
||||
def get_logger(name=None):
|
||||
'''
|
||||
Build a logger with the given name.
|
||||
'''
|
||||
logging.setLoggerClass(Borgmatic_logger)
|
||||
logger = logging.getLogger(name)
|
||||
return logger
|
||||
return color_text(color, record.msg)
|
||||
|
||||
|
||||
def color_text(color, message):
|
||||
@@ -111,7 +69,7 @@ def configure_logging(console_log_level, syslog_log_level=None):
|
||||
syslog_log_level = console_log_level
|
||||
|
||||
console_handler = logging.StreamHandler()
|
||||
console_handler.setFormatter(logging.Formatter('%(message)s'))
|
||||
console_handler.setFormatter(Console_color_formatter())
|
||||
console_handler.setLevel(console_log_level)
|
||||
|
||||
syslog_path = None
|
||||
|
||||
@@ -42,11 +42,11 @@ using systemd, try running `journalctl -xe`. Otherwise, try viewing
|
||||
|
||||
You can customize the log level used for syslog logging with the
|
||||
`--syslog-verbosity` flag, and this is independent from the console logging
|
||||
`--verbosity` flag described above. For instance, to disable syslog logging
|
||||
except for errors:
|
||||
`--verbosity` flag described above. For instance, to get additional
|
||||
information about the progress of the backup as it proceeds:
|
||||
|
||||
```bash
|
||||
borgmatic --syslog-verbosity 0
|
||||
borgmatic --syslog-verbosity 1
|
||||
```
|
||||
|
||||
Or to increase syslog logging to include debug spew:
|
||||
|
||||
@@ -105,6 +105,10 @@ include, the local file's option takes precedent. And note that this is a
|
||||
shallow merge rather than a deep merge, so the merging does not descend into
|
||||
nested values.
|
||||
|
||||
Note that this `<<` include merging syntax is only for merging in mappings
|
||||
(keys/values). If you'd like to include other types like scalars or lists
|
||||
directly, please see the section above about standard includes.
|
||||
|
||||
|
||||
## Related documentation
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from setuptools import find_packages, setup
|
||||
|
||||
VERSION = '1.3.6'
|
||||
VERSION = '1.3.7'
|
||||
|
||||
|
||||
setup(
|
||||
|
||||
@@ -15,7 +15,7 @@ def test_parse_arguments_with_no_arguments_uses_defaults():
|
||||
assert parser.config_paths == config_paths
|
||||
assert parser.excludes_filename is None
|
||||
assert parser.verbosity == 0
|
||||
assert parser.syslog_verbosity == 1
|
||||
assert parser.syslog_verbosity == 0
|
||||
assert parser.json is False
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ def test_parse_arguments_with_multiple_config_paths_parses_as_list():
|
||||
|
||||
assert parser.config_paths == ['myconfig', 'otherconfig']
|
||||
assert parser.verbosity == 0
|
||||
assert parser.syslog_verbosity == 1
|
||||
assert parser.syslog_verbosity == 0
|
||||
|
||||
|
||||
def test_parse_arguments_with_verbosity_overrides_default():
|
||||
@@ -38,7 +38,7 @@ def test_parse_arguments_with_verbosity_overrides_default():
|
||||
assert parser.config_paths == config_paths
|
||||
assert parser.excludes_filename is None
|
||||
assert parser.verbosity == 1
|
||||
assert parser.syslog_verbosity == 1
|
||||
assert parser.syslog_verbosity == 0
|
||||
|
||||
|
||||
def test_parse_arguments_with_syslog_verbosity_overrides_default():
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
import ruamel.yaml
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.config import load as module
|
||||
@@ -38,3 +40,23 @@ def test_load_configuration_merges_include():
|
||||
)
|
||||
|
||||
assert module.load_configuration('config.yaml') == {'foo': 'override', 'baz': 'quux'}
|
||||
|
||||
|
||||
def test_load_configuration_does_not_merge_include_list():
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
builtins.should_receive('open').with_args('include.yaml').and_return(
|
||||
'''
|
||||
- one
|
||||
- two
|
||||
'''
|
||||
)
|
||||
builtins.should_receive('open').with_args('config.yaml').and_return(
|
||||
'''
|
||||
foo: bar
|
||||
repositories:
|
||||
<<: !include include.yaml
|
||||
'''
|
||||
)
|
||||
|
||||
with pytest.raises(ruamel.yaml.error.YAMLError):
|
||||
assert module.load_configuration('config.yaml')
|
||||
|
||||
+10
-13
@@ -51,21 +51,14 @@ def test_should_do_markup_prefers_PY_COLORS_to_stdout_tty_value():
|
||||
assert module.should_do_markup(no_color=False) is True
|
||||
|
||||
|
||||
@pytest.mark.parametrize('method_name', ('critical', 'error', 'warn', 'info', 'debug'))
|
||||
def test_borgmatic_logger_log_method_does_not_raise(method_name):
|
||||
flexmock(module).should_receive('color_text')
|
||||
flexmock(module.logging.Logger).should_receive(method_name)
|
||||
def test_console_color_formatter_format_includes_log_message():
|
||||
plain_message = 'uh oh'
|
||||
record = flexmock(levelno=logging.CRITICAL, msg=plain_message)
|
||||
|
||||
getattr(module.Borgmatic_logger('test'), method_name)(msg='hi')
|
||||
colored_message = module.Console_color_formatter().format(record)
|
||||
|
||||
|
||||
def test_borgmatic_logger_handle_does_not_raise():
|
||||
flexmock(module).should_receive('color_text')
|
||||
flexmock(module.logging.Logger).should_receive('handle')
|
||||
|
||||
module.Borgmatic_logger('test').handle(
|
||||
module.logging.makeLogRecord(dict(levelno=module.logging.CRITICAL, msg='hi'))
|
||||
)
|
||||
assert colored_message != plain_message
|
||||
assert plain_message in colored_message
|
||||
|
||||
|
||||
def test_color_text_does_not_raise():
|
||||
@@ -77,6 +70,7 @@ def test_color_text_without_color_does_not_raise():
|
||||
|
||||
|
||||
def test_configure_logging_probes_for_log_socket_on_linux():
|
||||
flexmock(module).should_receive('Console_color_formatter')
|
||||
flexmock(module.logging).should_receive('basicConfig').with_args(
|
||||
level=logging.INFO, handlers=tuple
|
||||
)
|
||||
@@ -91,6 +85,7 @@ def test_configure_logging_probes_for_log_socket_on_linux():
|
||||
|
||||
|
||||
def test_configure_logging_probes_for_log_socket_on_macos():
|
||||
flexmock(module).should_receive('Console_color_formatter')
|
||||
flexmock(module.logging).should_receive('basicConfig').with_args(
|
||||
level=logging.INFO, handlers=tuple
|
||||
)
|
||||
@@ -105,6 +100,7 @@ def test_configure_logging_probes_for_log_socket_on_macos():
|
||||
|
||||
|
||||
def test_configure_logging_sets_global_logger_to_most_verbose_log_level():
|
||||
flexmock(module).should_receive('Console_color_formatter')
|
||||
flexmock(module.logging).should_receive('basicConfig').with_args(
|
||||
level=logging.DEBUG, handlers=tuple
|
||||
).once()
|
||||
@@ -114,6 +110,7 @@ def test_configure_logging_sets_global_logger_to_most_verbose_log_level():
|
||||
|
||||
|
||||
def test_configure_logging_skips_syslog_if_not_found():
|
||||
flexmock(module).should_receive('Console_color_formatter')
|
||||
flexmock(module.logging).should_receive('basicConfig').with_args(
|
||||
level=logging.INFO, handlers=tuple
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user