From e4f1094569eda0110e6eeb315da42f03fd6746e3 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Fri, 20 Dec 2019 14:04:49 -0800 Subject: [PATCH 1/7] Bump version for release. --- NEWS | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 275dcf3b..8e8adce4 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -1.4.21.dev0 +1.4.21 * #268: Override particular configuration options from the command-line via "--override" flag. See the documentation for more information: https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/#configuration-overrides diff --git a/setup.py b/setup.py index 0d87bc59..d3ae2168 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.4.21.dev0' +VERSION = '1.4.21' setup( From 5b1beda82b50ebff55d9bdad05e489ee1f1a4032 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 31 Dec 2019 15:06:53 -0800 Subject: [PATCH 2/7] Add logrotate documentation suggestion. --- docs/how-to/inspect-your-backups.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/how-to/inspect-your-backups.md b/docs/how-to/inspect-your-backups.md index cb528080..d960303c 100644 --- a/docs/how-to/inspect-your-backups.md +++ b/docs/how-to/inspect-your-backups.md @@ -95,7 +95,8 @@ borgmatic --log-file /path/to/file.log ``` Note that if you use the `--log-file` flag, you are responsible for rotating -the log file so it doesn't grow too large. Also, there is a +the log file so it doesn't grow too large, for example with +[logrotate](https://wiki.archlinux.org/index.php/Logrotate). Also, there is a `--log-file-verbosity` flag to customize the log file's log level. From 24e1516ec50b73df7612862f95f4bff956268445 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Wed, 1 Jan 2020 17:14:55 -0800 Subject: [PATCH 3/7] Use absolute paths in systemd commands. --- sample/systemd/borgmatic.service | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sample/systemd/borgmatic.service b/sample/systemd/borgmatic.service index 0bbf5b44..a4ec7f09 100644 --- a/sample/systemd/borgmatic.service +++ b/sample/systemd/borgmatic.service @@ -18,5 +18,5 @@ Restart=no LogRateLimitIntervalSec=0 # Delay start to prevent backups running during boot. -ExecStartPre=sleep 1m -ExecStart=systemd-inhibit --who="borgmatic" --why="Prevent interrupting scheduled backup" /root/.local/bin/borgmatic --syslog-verbosity 1 +ExecStartPre=/usr/bin/sleep 1m +ExecStart=/usr/bin/systemd-inhibit --who="borgmatic" --why="Prevent interrupting scheduled backup" /root/.local/bin/borgmatic --syslog-verbosity 1 From 1995c80e60077f2798e9236f0a8f2158a3b056e5 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Thu, 2 Jan 2020 10:05:32 -0800 Subject: [PATCH 4/7] Add comment about old versions of systemd and option compatibility (#275). --- sample/systemd/borgmatic.service | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sample/systemd/borgmatic.service b/sample/systemd/borgmatic.service index a4ec7f09..11725e6e 100644 --- a/sample/systemd/borgmatic.service +++ b/sample/systemd/borgmatic.service @@ -15,6 +15,8 @@ IOSchedulingPriority=7 IOWeight=100 Restart=no +# Prevent rate limiting of borgmatic log events. If you are using an older version of systemd that +# doesn't support this (pre-240 or so), you may have to remove this option. LogRateLimitIntervalSec=0 # Delay start to prevent backups running during boot. From d0c533555e39dd938c6b5bd45436a4c030d0b6d6 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Thu, 2 Jan 2020 10:37:31 -0800 Subject: [PATCH 5/7] In "borgmatic --help", don't expand $HOME in listing of default "--config" paths. --- NEWS | 3 +++ borgmatic/commands/arguments.py | 5 +++-- borgmatic/config/collect.py | 10 ++++++---- setup.py | 2 +- tests/unit/config/test_collect.py | 8 ++++++++ 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 8e8adce4..6ed814d2 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +1.4.22.dev0 + * In "borgmatic --help", don't expand $HOME in listing of default "--config" paths. + 1.4.21 * #268: Override particular configuration options from the command-line via "--override" flag. See the documentation for more information: diff --git a/borgmatic/commands/arguments.py b/borgmatic/commands/arguments.py index 63030066..142c3a7e 100644 --- a/borgmatic/commands/arguments.py +++ b/borgmatic/commands/arguments.py @@ -106,7 +106,8 @@ def parse_arguments(*unparsed_arguments): Given command-line arguments with which this script was invoked, parse the arguments and return them as a dict mapping from subparser name (or "global") to an argparse.Namespace instance. ''' - config_paths = collect.get_default_config_paths() + config_paths = collect.get_default_config_paths(expand_home=True) + unexpanded_config_paths = collect.get_default_config_paths(expand_home=False) global_parser = ArgumentParser(add_help=False) global_group = global_parser.add_argument_group('global arguments') @@ -118,7 +119,7 @@ def parse_arguments(*unparsed_arguments): dest='config_paths', default=config_paths, help='Configuration filenames or directories, defaults to: {}'.format( - ' '.join(config_paths) + ' '.join(unexpanded_config_paths) ), ) global_group.add_argument( diff --git a/borgmatic/config/collect.py b/borgmatic/config/collect.py index 59d7dfe5..ef04bd49 100644 --- a/borgmatic/config/collect.py +++ b/borgmatic/config/collect.py @@ -1,15 +1,17 @@ import os -def get_default_config_paths(): +def get_default_config_paths(expand_home=True): ''' Based on the value of the XDG_CONFIG_HOME and HOME environment variables, return a list of default configuration paths. This includes both system-wide configuration and configuration in the current user's home directory. + + Don't expand the home directory ($HOME) if the expand home flag is False. ''' - user_config_directory = os.getenv('XDG_CONFIG_HOME') or os.path.expandvars( - os.path.join('$HOME', '.config') - ) + user_config_directory = os.getenv('XDG_CONFIG_HOME') or os.path.join('$HOME', '.config') + if expand_home: + user_config_directory = os.path.expandvars(user_config_directory) return [ '/etc/borgmatic/config.yaml', diff --git a/setup.py b/setup.py index d3ae2168..15dfed55 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.4.21' +VERSION = '1.4.22.dev0' setup( diff --git a/tests/unit/config/test_collect.py b/tests/unit/config/test_collect.py index 2cb5b584..4c4420a4 100644 --- a/tests/unit/config/test_collect.py +++ b/tests/unit/config/test_collect.py @@ -21,6 +21,14 @@ def test_get_default_config_paths_prefers_xdg_config_home_for_user_config_path() assert '/home/user/.etc/borgmatic/config.yaml' in config_paths +def test_get_default_config_paths_does_not_expand_home_when_false(): + flexmock(module.os, environ={'HOME': '/home/user'}) + + config_paths = module.get_default_config_paths(expand_home=False) + + assert '$HOME/.config/borgmatic/config.yaml' in config_paths + + def test_collect_config_filenames_collects_given_files(): config_paths = ('config.yaml', 'other.yaml') flexmock(module.os.path).should_receive('isdir').and_return(False) From c52f82f9cedc019a064d567ca4407b885fbe3789 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 4 Jan 2020 13:37:56 -0800 Subject: [PATCH 6/7] Documentation: Enable and start borgmatic with a single systemctl command. --- docs/how-to/set-up-backups.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/how-to/set-up-backups.md b/docs/how-to/set-up-backups.md index bc78237c..b87b8058 100644 --- a/docs/how-to/set-up-backups.md +++ b/docs/how-to/set-up-backups.md @@ -204,8 +204,7 @@ Then, from the directory where you downloaded them: ```bash sudo mv borgmatic.service borgmatic.timer /etc/systemd/system/ -sudo systemctl enable borgmatic.timer -sudo systemctl start borgmatic.timer +sudo systemctl enable --now borgmatic.timer ``` Feel free to modify the timer file based on how frequently you'd like From 5afe0e3d6394b1bb81daf62ba1a42f6682c83452 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 4 Jan 2020 15:50:41 -0800 Subject: [PATCH 7/7] Disable colored output when "--json" flag is used, so as to produce valid JSON ouput (#276). --- NEWS | 1 + borgmatic/commands/borgmatic.py | 8 +++++++- docs/how-to/set-up-backups.md | 8 ++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 6ed814d2..0e76bf01 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,5 @@ 1.4.22.dev0 + * #276: Disable colored output when "--json" flag is used, so as to produce valid JSON ouput. * In "borgmatic --help", don't expand $HOME in listing of default "--config" paths. 1.4.21 diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index b39668ad..5ad1431d 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -587,7 +587,13 @@ def main(): # pragma: no cover config_filenames = tuple(collect.collect_config_filenames(global_arguments.config_paths)) configs, parse_logs = load_configurations(config_filenames, global_arguments.overrides) - colorama.init(autoreset=True, strip=not should_do_markup(global_arguments.no_color, configs)) + any_json_flags = any( + getattr(sub_arguments, 'json', False) for sub_arguments in arguments.values() + ) + colorama.init( + autoreset=True, + strip=not should_do_markup(global_arguments.no_color or any_json_flags, configs), + ) try: configure_logging( verbosity_to_log_level(global_arguments.verbosity), diff --git a/docs/how-to/set-up-backups.md b/docs/how-to/set-up-backups.md index b87b8058..2d288372 100644 --- a/docs/how-to/set-up-backups.md +++ b/docs/how-to/set-up-backups.md @@ -213,10 +213,10 @@ borgmatic to run. ## Colored output Borgmatic produces colored terminal output by default. It is disabled when a -non-interactive terminal is detected (like a cron job). Otherwise, you can -disable it by passing the `--no-color` flag, setting the environment variable -`PY_COLORS=False`, or setting the `color` option to `false` in the `output` -section of configuration. +non-interactive terminal is detected (like a cron job), or when you use the +`--json` flag. Otherwise, you can disable it by passing the `--no-color` flag, +setting the environment variable `PY_COLORS=False`, or setting the `color` +option to `false` in the `output` section of configuration. ## Troubleshooting