From f48f52079d5954cd0b75bf6c6c81db8370ea6315 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Fri, 1 Nov 2019 15:50:59 -0700 Subject: [PATCH] Support for Borg --keep-exclude-tags and --exclude-nodump options (#234). --- NEWS | 3 +++ borgmatic/borg/create.py | 12 +++++++++++- borgmatic/config/schema.yaml | 11 +++++++++++ setup.py | 2 +- tests/unit/borg/test_create.py | 24 ++++++++++++++++++++++++ 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 6516b09..51861ef 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +1.4.4 + * #234: Support for Borg --keep-exclude-tags and --exclude-nodump options. + 1.4.3 * Monitor backups with Cronitor hook integration. See the documentation for more information: https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#cronitor-hook diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index 86cf953..f3e8c2a 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -90,8 +90,18 @@ def _make_exclude_flags(location_config, exclude_filename=None): caches_flag = ('--exclude-caches',) if location_config.get('exclude_caches') else () if_present = location_config.get('exclude_if_present') if_present_flags = ('--exclude-if-present', if_present) if if_present else () + keep_exclude_tags_flags = ( + ('--keep-exclude-tags',) if location_config.get('keep_exclude_tags') else () + ) + exclude_nodump_flags = ('--exclude-nodump',) if location_config.get('exclude_nodump') else () - return exclude_from_flags + caches_flag + if_present_flags + return ( + exclude_from_flags + + caches_flag + + if_present_flags + + keep_exclude_tags_flags + + exclude_nodump_flags + ) BORGMATIC_SOURCE_DIRECTORY = '~/.borgmatic' diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index 1af9334..d97eba6 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -126,6 +126,17 @@ map: Exclude directories that contain a file with the given filename. Defaults to not set. example: .nobackup + keep_exclude_tags: + type: bool + desc: | + If true, the exclude_if_present filename is included in backups. Defaults to + false, meaning that the exclude_if_present filename is omitted from backups. + example: true + exclude_nodump: + type: bool + desc: | + Exclude files with the NODUMP flag. Defaults to false. + example: true storage: desc: | Repository storage options. See diff --git a/setup.py b/setup.py index 849de4b..81e3910 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.4.3' +VERSION = '1.4.4' setup( diff --git a/tests/unit/borg/test_create.py b/tests/unit/borg/test_create.py index b54e64b..156be57 100644 --- a/tests/unit/borg/test_create.py +++ b/tests/unit/borg/test_create.py @@ -150,6 +150,30 @@ def test_make_exclude_flags_includes_exclude_if_present_when_in_config(): assert exclude_flags == ('--exclude-if-present', 'exclude_me') +def test_make_exclude_flags_includes_keep_exclude_tags_when_true_in_config(): + exclude_flags = module._make_exclude_flags(location_config={'keep_exclude_tags': True}) + + assert exclude_flags == ('--keep-exclude-tags',) + + +def test_make_exclude_flags_does_not_include_keep_exclude_tags_when_false_in_config(): + exclude_flags = module._make_exclude_flags(location_config={'keep_exclude_tags': False}) + + assert exclude_flags == () + + +def test_make_exclude_flags_includes_exclude_nodump_when_true_in_config(): + exclude_flags = module._make_exclude_flags(location_config={'exclude_nodump': True}) + + assert exclude_flags == ('--exclude-nodump',) + + +def test_make_exclude_flags_does_not_include_exclude_nodump_when_false_in_config(): + exclude_flags = module._make_exclude_flags(location_config={'exclude_nodump': False}) + + assert exclude_flags == () + + def test_make_exclude_flags_is_empty_when_config_has_no_excludes(): exclude_flags = module._make_exclude_flags(location_config={})