From fc3b1fccbaa8b609e09551aedbdc79a95b4808cb Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 2 Nov 2017 22:03:11 -0700 Subject: [PATCH] Support for Borg --files-cache option for setting the files cache operation mode. --- NEWS | 1 + borgmatic/borg/create.py | 4 +++- borgmatic/config/schema.yaml | 6 ++++++ borgmatic/tests/unit/borg/test_create.py | 19 +++++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index d64e283..bd5998a 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ * Pass several Unix signals through to child processes like Borg. This means that Borg now properly shuts down if borgmatic is terminated (e.g. due to a system suspend). * #29: Support for using tilde in repository paths to reference home directory. + * #42: Support for Borg --files-cache option for setting the files cache operation mode. 1.1.9 * #16, #38: Support for user-defined hooks before/after backup, or on error. diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index 47315dd..cdabd56 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -84,6 +84,8 @@ def create_archive( umask = storage_config.get('umask', None) umask_flags = ('--umask', str(umask)) if umask else () one_file_system_flags = ('--one-file-system',) if location_config.get('one_file_system') else () + files_cache = location_config.get('files_cache') + files_cache_flags = ('--files-cache', files_cache) if files_cache else () remote_path = location_config.get('remote_path') remote_path_flags = ('--remote-path', remote_path) if remote_path else () verbosity_flags = { @@ -99,7 +101,7 @@ def create_archive( repository=repository, archive_name_format=archive_name_format, ), - ) + sources + exclude_flags + compression_flags + one_file_system_flags + \ + ) + sources + exclude_flags + compression_flags + one_file_system_flags + files_cache_flags + \ remote_path_flags + umask_flags + verbosity_flags subprocess.check_call(full_command) diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index 8cfa32f..4918f77 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -22,6 +22,12 @@ map: type: bool desc: Stay in same file system (do not cross mount points). example: true + files_cache: + type: scalar + desc: Mode in which to operate the files cache. See + https://borgbackup.readthedocs.io/en/stable/usage/create.html#description for + details. + example: ctime,size,inode remote_path: type: scalar desc: Alternate Borg remote executable. Defaults to "borg". diff --git a/borgmatic/tests/unit/borg/test_create.py b/borgmatic/tests/unit/borg/test_create.py index ebbee97..c53e2bd 100644 --- a/borgmatic/tests/unit/borg/test_create.py +++ b/borgmatic/tests/unit/borg/test_create.py @@ -250,6 +250,25 @@ def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_par ) +def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters(): + flexmock(module).should_receive('_expand_directory').and_return(['foo']).and_return(['bar']) + flexmock(module).should_receive('_write_exclude_file').and_return(None) + flexmock(module).should_receive('_make_exclude_flags').and_return(()) + insert_subprocess_mock(CREATE_COMMAND + ('--files-cache', 'ctime,size')) + + module.create_archive( + verbosity=None, + repository='repo', + location_config={ + 'source_directories': ['foo', 'bar'], + 'repositories': ['repo'], + 'files_cache': 'ctime,size', + 'exclude_patterns': None, + }, + storage_config={}, + ) + + def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters(): flexmock(module).should_receive('_expand_directory').and_return(['foo']).and_return(['bar']) flexmock(module).should_receive('_write_exclude_file').and_return(None)