From d6585811d634f3c591013254eef2570ffcf52ba6 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 13 Feb 2016 10:43:31 -0800 Subject: [PATCH] Added support for --one-file-system for Borg. --- AUTHORS | 1 + NEWS | 3 ++- atticmatic/backends/borg.py | 9 ++++++++- atticmatic/backends/shared.py | 5 ++++- atticmatic/config.py | 1 + atticmatic/tests/unit/backends/test_shared.py | 16 ++++++++++++++++ atticmatic/tests/unit/test_config.py | 2 ++ sample/config | 4 ++++ setup.py | 2 +- 9 files changed, 39 insertions(+), 4 deletions(-) diff --git a/AUTHORS b/AUTHORS index 2a2f28f..95d2df8 100644 --- a/AUTHORS +++ b/AUTHORS @@ -2,3 +2,4 @@ Dan Helfman : Main developer Alexander Görtz: Python 3 compatibility Henning Schroeder: Copy editing +Robin `ypid` Schneider: Support additional options of Borg diff --git a/NEWS b/NEWS index b7227b8..1b0963f 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ -0.1.8-dev +0.1.8.dev0 * Fixed handling of repeated spaces in source_directories which resulted in backup up everything. + * Added support for --one-file-system for Borg. 0.1.7 diff --git a/atticmatic/backends/borg.py b/atticmatic/backends/borg.py index 222c702..6105a05 100644 --- a/atticmatic/backends/borg.py +++ b/atticmatic/backends/borg.py @@ -7,7 +7,14 @@ from atticmatic.backends import shared COMMAND = 'borg' CONFIG_FORMAT = ( - shared.CONFIG_FORMAT[0], # location + Section_format( + 'location', + ( + option('source_directories'), + option('one_file_system', value_type=bool, required=False), + option('repository'), + ), + ), Section_format( 'storage', ( diff --git a/atticmatic/backends/shared.py b/atticmatic/backends/shared.py index a60aa3b..5544b30 100644 --- a/atticmatic/backends/shared.py +++ b/atticmatic/backends/shared.py @@ -58,6 +58,7 @@ def initialize(storage_config, command): def create_archive( excludes_filename, verbosity, storage_config, source_directories, repository, command, + one_file_system=None, ): ''' Given an excludes filename (or None), a vebosity flag, a storage config dict, a space-separated @@ -68,6 +69,7 @@ def create_archive( exclude_flags = ('--exclude-from', excludes_filename) if excludes_filename else () compression = storage_config.get('compression', None) compression_flags = ('--compression', compression) if compression else () + one_file_system_flags = ('--one-file-system',) if one_file_system else () verbosity_flags = { VERBOSITY_SOME: ('--stats',), VERBOSITY_LOTS: ('--verbose', '--stats'), @@ -80,7 +82,8 @@ def create_archive( hostname=platform.node(), timestamp=datetime.now().isoformat(), ), - ) + sources + exclude_flags + compression_flags + verbosity_flags + ) + sources + exclude_flags + compression_flags + one_file_system_flags + \ + verbosity_flags subprocess.check_call(full_command) diff --git a/atticmatic/config.py b/atticmatic/config.py index ddf574d..8f7ae9a 100644 --- a/atticmatic/config.py +++ b/atticmatic/config.py @@ -92,6 +92,7 @@ def parse_section_options(parser, section_format): type_getter = { str: parser.get, int: parser.getint, + bool: parser.getboolean, } return OrderedDict( diff --git a/atticmatic/tests/unit/backends/test_shared.py b/atticmatic/tests/unit/backends/test_shared.py index ddb090f..660fc5b 100644 --- a/atticmatic/tests/unit/backends/test_shared.py +++ b/atticmatic/tests/unit/backends/test_shared.py @@ -146,6 +146,22 @@ def test_create_archive_with_compression_should_call_attic_with_compression_para ) +def test_create_archive_with_one_file_system_should_call_attic_with_one_file_system_parameters(): + insert_subprocess_mock(CREATE_COMMAND + ('--one-file-system',)) + insert_platform_mock() + insert_datetime_mock() + + module.create_archive( + excludes_filename='excludes', + verbosity=None, + storage_config={}, + source_directories='foo bar', + repository='repo', + command='attic', + one_file_system=True, + ) + + BASE_PRUNE_FLAGS = ( ('--keep-daily', '1'), ('--keep-weekly', '2'), diff --git a/atticmatic/tests/unit/test_config.py b/atticmatic/tests/unit/test_config.py index 4b4d3a7..88569e1 100644 --- a/atticmatic/tests/unit/test_config.py +++ b/atticmatic/tests/unit/test_config.py @@ -154,6 +154,7 @@ def test_parse_section_options_should_return_section_options(): parser = flexmock() parser.should_receive('get').with_args('section', 'foo').and_return('value') parser.should_receive('getint').with_args('section', 'bar').and_return(1) + parser.should_receive('getboolean').never() parser.should_receive('has_option').with_args('section', 'foo').and_return(True) parser.should_receive('has_option').with_args('section', 'bar').and_return(True) @@ -179,6 +180,7 @@ def test_parse_section_options_for_missing_section_should_return_empty_dict(): parser = flexmock() parser.should_receive('get').never() parser.should_receive('getint').never() + parser.should_receive('getboolean').never() parser.should_receive('has_option').with_args('section', 'foo').and_return(False) parser.should_receive('has_option').with_args('section', 'bar').and_return(False) diff --git a/sample/config b/sample/config index cf4b391..3d9432f 100644 --- a/sample/config +++ b/sample/config @@ -2,6 +2,10 @@ # Space-separated list of source directories to backup. source_directories: /home /etc +# For Borg only, you can specify to stay in same file system (do not cross +# mount points). +#one_file_system: True + # Path to local or remote repository. repository: user@backupserver:sourcehostname.attic diff --git a/setup.py b/setup.py index 343d69f..ff5a4be 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages -VERSION = '0.1.7' +VERSION = '0.1.8.dev0' setup(