From 4444219e1775c862c18c2ac71e8c6a776aff1909 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 25 Jun 2019 11:30:55 -0700 Subject: [PATCH] Support for Borg --noatime, --noctime, and --nobirthtime flags (mentioned in #193). --- NEWS | 4 +++- borgmatic/borg/create.py | 3 +++ borgmatic/config/schema.yaml | 12 ++++++++++++ setup.py | 2 +- tests/unit/borg/test_create.py | 13 ++++++++----- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 5b4044f..cdc0d8f 100644 --- a/NEWS +++ b/NEWS @@ -1,8 +1,10 @@ -1.3.11.dev0 +1.3.11 * #193: Pass through several "borg list" and "borg info" flags like --short, --format, --sort-by, --first, --last, etc. via borgmatic command-line flags. * Add borgmatic info --repository and --archive command-line flags to display info for individual repositories or archives. + * Support for Borg --noatime, --noctime, and --nobirthtime flags via corresponding options in + borgmatic configuration location section. 1.3.10 * #198: Fix for Borg create error output not showing up at borgmatic verbosity level zero. diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index bb0a138..ab042d5 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -142,6 +142,9 @@ def create_archive( + (('--remote-ratelimit', str(remote_rate_limit)) if remote_rate_limit else ()) + (('--one-file-system',) if location_config.get('one_file_system') else ()) + (('--numeric-owner',) if location_config.get('numeric_owner') else ()) + + (('--noatime',) if location_config.get('atime') is False else ()) + + (('--noctime',) if location_config.get('ctime') is False else ()) + + (('--nobirthtime',) if location_config.get('birthtime') is False else ()) + (('--read-special',) if location_config.get('read_special') else ()) + (('--nobsdflags',) if location_config.get('bsd_flags') is False else ()) + (('--files-cache', files_cache) if files_cache else ()) diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index 0c5c62e..d2de356 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -36,6 +36,18 @@ map: type: bool desc: Only store/extract numeric user and group identifiers. Defaults to false. example: true + atime: + type: bool + desc: Store atime into archive. Defaults to true. + example: false + ctime: + type: bool + desc: Store ctime into archive. Defaults to true. + example: false + birthtime: + type: bool + desc: Store birthtime (creation date) into archive. Defaults to true. + example: false read_special: type: bool desc: | diff --git a/setup.py b/setup.py index eb45bcc..5fd5dab 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.3.11.dev0' +VERSION = '1.3.11' setup( diff --git a/tests/unit/borg/test_create.py b/tests/unit/borg/test_create.py index 8aed05d..604419f 100644 --- a/tests/unit/borg/test_create.py +++ b/tests/unit/borg/test_create.py @@ -1,5 +1,6 @@ import logging +import pytest from flexmock import flexmock from borgmatic.borg import create as module @@ -563,7 +564,8 @@ def test_create_archive_with_read_special_calls_borg_with_read_special_parameter ) -def test_create_archive_with_bsd_flags_true_calls_borg_without_nobsdflags_parameter(): +@pytest.mark.parametrize('option_name', ('atime', 'ctime', 'birthtime', 'bsd_flags')) +def test_create_archive_with_option_true_calls_borg_without_corresponding_parameter(option_name): flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')) flexmock(module).should_receive('_expand_home_directories').and_return(()) flexmock(module).should_receive('_write_pattern_file').and_return(None) @@ -579,21 +581,22 @@ def test_create_archive_with_bsd_flags_true_calls_borg_without_nobsdflags_parame location_config={ 'source_directories': ['foo', 'bar'], 'repositories': ['repo'], - 'bsd_flags': True, + option_name: True, 'exclude_patterns': None, }, storage_config={}, ) -def test_create_archive_with_bsd_flags_false_calls_borg_with_nobsdflags_parameter(): +@pytest.mark.parametrize('option_name', ('atime', 'ctime', 'birthtime', 'bsd_flags')) +def test_create_archive_with_option_false_calls_borg_with_corresponding_parameter(option_name): flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')) flexmock(module).should_receive('_expand_home_directories').and_return(()) flexmock(module).should_receive('_write_pattern_file').and_return(None) flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('execute_command').with_args( - CREATE_COMMAND + ('--nobsdflags',), output_log_level=logging.INFO + CREATE_COMMAND + ('--no' + option_name.replace('_', ''),), output_log_level=logging.INFO ) module.create_archive( @@ -602,7 +605,7 @@ def test_create_archive_with_bsd_flags_false_calls_borg_with_nobsdflags_paramete location_config={ 'source_directories': ['foo', 'bar'], 'repositories': ['repo'], - 'bsd_flags': False, + option_name: False, 'exclude_patterns': None, }, storage_config={},