2018-09-30 08:15:18 +02:00
|
|
|
import logging
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2019-06-25 20:30:55 +02:00
|
|
|
import pytest
|
2017-08-06 01:21:39 +02:00
|
|
|
from flexmock import flexmock
|
|
|
|
|
|
|
|
from borgmatic.borg import create as module
|
2019-05-13 23:39:10 +02:00
|
|
|
|
2018-09-30 22:57:20 +02:00
|
|
|
from ..test_verbosity import insert_logging_mock
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2017-09-10 02:23:31 +02:00
|
|
|
def test_expand_directory_with_basic_path_passes_it_through():
|
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_return('foo')
|
|
|
|
flexmock(module.glob).should_receive('glob').and_return([])
|
|
|
|
|
|
|
|
paths = module._expand_directory('foo')
|
|
|
|
|
|
|
|
assert paths == ['foo']
|
|
|
|
|
|
|
|
|
|
|
|
def test_expand_directory_with_glob_expands():
|
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_return('foo*')
|
|
|
|
flexmock(module.glob).should_receive('glob').and_return(['foo', 'food'])
|
|
|
|
|
|
|
|
paths = module._expand_directory('foo*')
|
|
|
|
|
|
|
|
assert paths == ['foo', 'food']
|
|
|
|
|
|
|
|
|
2018-02-19 00:34:19 +01:00
|
|
|
def test_expand_directories_flattens_expanded_directories():
|
2018-09-30 07:45:00 +02:00
|
|
|
flexmock(module).should_receive('_expand_directory').with_args('~/foo').and_return(
|
|
|
|
['/root/foo']
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('_expand_directory').with_args('bar*').and_return(
|
|
|
|
['bar', 'barf']
|
|
|
|
)
|
2018-02-19 00:34:19 +01:00
|
|
|
|
|
|
|
paths = module._expand_directories(('~/foo', 'bar*'))
|
|
|
|
|
|
|
|
assert paths == ('/root/foo', 'bar', 'barf')
|
|
|
|
|
|
|
|
|
|
|
|
def test_expand_directories_considers_none_as_no_directories():
|
|
|
|
paths = module._expand_directories(None)
|
|
|
|
|
|
|
|
assert paths == ()
|
|
|
|
|
|
|
|
|
2019-01-27 22:47:26 +01:00
|
|
|
def test_expand_home_directories_expands_tildes():
|
|
|
|
flexmock(module.os.path).should_receive('expanduser').with_args('~/bar').and_return('/foo/bar')
|
|
|
|
flexmock(module.os.path).should_receive('expanduser').with_args('baz').and_return('baz')
|
|
|
|
|
|
|
|
paths = module._expand_home_directories(('~/bar', 'baz'))
|
|
|
|
|
|
|
|
assert paths == ('/foo/bar', 'baz')
|
|
|
|
|
|
|
|
|
|
|
|
def test_expand_home_directories_considers_none_as_no_directories():
|
|
|
|
paths = module._expand_home_directories(None)
|
|
|
|
|
|
|
|
assert paths == ()
|
|
|
|
|
|
|
|
|
2021-10-11 19:40:10 +02:00
|
|
|
def test_map_directories_to_devices_gives_device_id_per_path():
|
|
|
|
flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))
|
|
|
|
flexmock(module.os).should_receive('stat').with_args('/bar').and_return(flexmock(st_dev=66))
|
|
|
|
|
|
|
|
device_map = module.map_directories_to_devices(('/foo', '/bar'))
|
|
|
|
|
|
|
|
assert device_map == {
|
|
|
|
'/foo': 55,
|
|
|
|
'/bar': 66,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def test_map_directories_to_devices_with_missing_path_does_not_error():
|
|
|
|
flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))
|
|
|
|
flexmock(module.os).should_receive('stat').with_args('/bar').and_raise(FileNotFoundError)
|
|
|
|
|
|
|
|
device_map = module.map_directories_to_devices(('/foo', '/bar'))
|
|
|
|
|
|
|
|
assert device_map == {
|
|
|
|
'/foo': 55,
|
|
|
|
'/bar': None,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-20 22:33:53 +02:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'directories,expected_directories',
|
|
|
|
(
|
2020-06-20 05:16:38 +02:00
|
|
|
({'/': 1, '/root': 1}, ('/',)),
|
|
|
|
({'/': 1, '/root/': 1}, ('/',)),
|
|
|
|
({'/': 1, '/root': 2}, ('/', '/root')),
|
|
|
|
({'/root': 1, '/': 1}, ('/',)),
|
|
|
|
({'/root': 1, '/root/foo': 1}, ('/root',)),
|
|
|
|
({'/root/': 1, '/root/foo': 1}, ('/root/',)),
|
|
|
|
({'/root': 1, '/root/foo/': 1}, ('/root',)),
|
|
|
|
({'/root': 1, '/root/foo': 2}, ('/root', '/root/foo')),
|
|
|
|
({'/root/foo': 1, '/root': 1}, ('/root',)),
|
2021-10-11 19:40:10 +02:00
|
|
|
({'/root': None, '/root/foo': None}, ('/root', '/root/foo')),
|
2020-06-20 05:16:38 +02:00
|
|
|
({'/root': 1, '/etc': 1, '/root/foo/bar': 1}, ('/etc', '/root')),
|
|
|
|
({'/root': 1, '/root/foo': 1, '/root/foo/bar': 1}, ('/root',)),
|
|
|
|
({'/dup': 1, '/dup': 1}, ('/dup',)),
|
|
|
|
({'/foo': 1, '/bar': 1}, ('/bar', '/foo')),
|
|
|
|
({'/foo': 1, '/bar': 2}, ('/bar', '/foo')),
|
2020-05-20 22:33:53 +02:00
|
|
|
),
|
|
|
|
)
|
2020-06-20 05:16:38 +02:00
|
|
|
def test_deduplicate_directories_removes_child_paths_on_the_same_filesystem(
|
|
|
|
directories, expected_directories
|
|
|
|
):
|
2020-05-20 22:33:53 +02:00
|
|
|
assert module.deduplicate_directories(directories) == expected_directories
|
|
|
|
|
|
|
|
|
2018-01-15 00:52:19 +01:00
|
|
|
def test_write_pattern_file_does_not_raise():
|
2018-09-30 07:45:00 +02:00
|
|
|
temporary_file = flexmock(name='filename', write=lambda mode: None, flush=lambda: None)
|
2017-08-06 01:21:39 +02:00
|
|
|
flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
|
|
|
|
|
2018-01-15 00:52:19 +01:00
|
|
|
module._write_pattern_file(['exclude'])
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2018-01-15 00:52:19 +01:00
|
|
|
def test_write_pattern_file_with_empty_exclude_patterns_does_not_raise():
|
|
|
|
module._write_pattern_file([])
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2018-01-15 00:52:19 +01:00
|
|
|
def test_make_pattern_flags_includes_pattern_filename_when_given():
|
|
|
|
pattern_flags = module._make_pattern_flags(
|
2018-09-30 07:45:00 +02:00
|
|
|
location_config={'patterns': ['R /', '- /var']}, pattern_filename='/tmp/patterns'
|
2018-01-15 00:52:19 +01:00
|
|
|
)
|
|
|
|
|
2018-01-16 05:22:53 +01:00
|
|
|
assert pattern_flags == ('--patterns-from', '/tmp/patterns')
|
2018-01-15 00:52:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_make_pattern_flags_includes_patterns_from_filenames_when_in_config():
|
|
|
|
pattern_flags = module._make_pattern_flags(
|
2018-09-30 07:45:00 +02:00
|
|
|
location_config={'patterns_from': ['patterns', 'other']}
|
2018-01-15 00:52:19 +01:00
|
|
|
)
|
|
|
|
|
2018-01-16 05:22:53 +01:00
|
|
|
assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', 'other')
|
2018-01-15 00:52:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_make_pattern_flags_includes_both_filenames_when_patterns_given_and_patterns_from_in_config():
|
|
|
|
pattern_flags = module._make_pattern_flags(
|
2018-09-30 07:45:00 +02:00
|
|
|
location_config={'patterns_from': ['patterns']}, pattern_filename='/tmp/patterns'
|
2018-01-15 00:52:19 +01:00
|
|
|
)
|
|
|
|
|
2018-01-16 05:22:53 +01:00
|
|
|
assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', '/tmp/patterns')
|
2018-01-15 00:52:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_make_pattern_flags_considers_none_patterns_from_filenames_as_empty():
|
2018-09-30 07:45:00 +02:00
|
|
|
pattern_flags = module._make_pattern_flags(location_config={'patterns_from': None})
|
2018-01-15 00:52:19 +01:00
|
|
|
|
|
|
|
assert pattern_flags == ()
|
|
|
|
|
|
|
|
|
2017-08-06 08:32:39 +02:00
|
|
|
def test_make_exclude_flags_includes_exclude_patterns_filename_when_given():
|
|
|
|
exclude_flags = module._make_exclude_flags(
|
2018-09-30 07:45:00 +02:00
|
|
|
location_config={'exclude_patterns': ['*.pyc', '/var']}, exclude_filename='/tmp/excludes'
|
2017-08-06 08:32:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
assert exclude_flags == ('--exclude-from', '/tmp/excludes')
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_exclude_flags_includes_exclude_from_filenames_when_in_config():
|
|
|
|
|
|
|
|
exclude_flags = module._make_exclude_flags(
|
2018-09-30 07:45:00 +02:00
|
|
|
location_config={'exclude_from': ['excludes', 'other']}
|
2017-08-06 08:32:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', 'other')
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_exclude_flags_includes_both_filenames_when_patterns_given_and_exclude_from_in_config():
|
|
|
|
exclude_flags = module._make_exclude_flags(
|
2018-09-30 07:45:00 +02:00
|
|
|
location_config={'exclude_from': ['excludes']}, exclude_filename='/tmp/excludes'
|
2017-08-06 08:32:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', '/tmp/excludes')
|
|
|
|
|
|
|
|
|
2017-08-27 19:01:49 +02:00
|
|
|
def test_make_exclude_flags_considers_none_exclude_from_filenames_as_empty():
|
2018-09-30 07:45:00 +02:00
|
|
|
exclude_flags = module._make_exclude_flags(location_config={'exclude_from': None})
|
2017-08-27 19:01:49 +02:00
|
|
|
|
|
|
|
assert exclude_flags == ()
|
|
|
|
|
|
|
|
|
2017-08-06 08:32:39 +02:00
|
|
|
def test_make_exclude_flags_includes_exclude_caches_when_true_in_config():
|
2018-09-30 07:45:00 +02:00
|
|
|
exclude_flags = module._make_exclude_flags(location_config={'exclude_caches': True})
|
2017-08-06 08:32:39 +02:00
|
|
|
|
|
|
|
assert exclude_flags == ('--exclude-caches',)
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_exclude_flags_does_not_include_exclude_caches_when_false_in_config():
|
2018-09-30 07:45:00 +02:00
|
|
|
exclude_flags = module._make_exclude_flags(location_config={'exclude_caches': False})
|
2017-08-06 08:32:39 +02:00
|
|
|
|
|
|
|
assert exclude_flags == ()
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_exclude_flags_includes_exclude_if_present_when_in_config():
|
2020-01-23 22:41:37 +01:00
|
|
|
exclude_flags = module._make_exclude_flags(
|
|
|
|
location_config={'exclude_if_present': ['exclude_me', 'also_me']}
|
|
|
|
)
|
2017-08-06 08:32:39 +02:00
|
|
|
|
2020-01-23 22:41:37 +01:00
|
|
|
assert exclude_flags == (
|
|
|
|
'--exclude-if-present',
|
|
|
|
'exclude_me',
|
|
|
|
'--exclude-if-present',
|
|
|
|
'also_me',
|
|
|
|
)
|
2017-08-06 08:32:39 +02:00
|
|
|
|
|
|
|
|
2019-11-01 23:50:59 +01:00
|
|
|
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 == ()
|
|
|
|
|
|
|
|
|
2017-08-06 08:32:39 +02:00
|
|
|
def test_make_exclude_flags_is_empty_when_config_has_no_excludes():
|
|
|
|
exclude_flags = module._make_exclude_flags(location_config={})
|
|
|
|
|
|
|
|
assert exclude_flags == ()
|
|
|
|
|
|
|
|
|
2019-10-23 01:28:42 +02:00
|
|
|
def test_borgmatic_source_directories_set_when_directory_exists():
|
|
|
|
flexmock(module.os.path).should_receive('exists').and_return(True)
|
|
|
|
flexmock(module.os.path).should_receive('expanduser')
|
|
|
|
|
2019-12-11 01:04:34 +01:00
|
|
|
assert module.borgmatic_source_directories('/tmp') == ['/tmp']
|
2019-10-23 01:28:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_borgmatic_source_directories_empty_when_directory_does_not_exist():
|
|
|
|
flexmock(module.os.path).should_receive('exists').and_return(False)
|
|
|
|
flexmock(module.os.path).should_receive('expanduser')
|
|
|
|
|
2019-12-11 01:04:34 +01:00
|
|
|
assert module.borgmatic_source_directories('/tmp') == []
|
|
|
|
|
|
|
|
|
|
|
|
def test_borgmatic_source_directories_defaults_when_directory_not_given():
|
|
|
|
flexmock(module.os.path).should_receive('exists').and_return(True)
|
|
|
|
flexmock(module.os.path).should_receive('expanduser')
|
|
|
|
|
|
|
|
assert module.borgmatic_source_directories(None) == [module.DEFAULT_BORGMATIC_SOURCE_DIRECTORY]
|
2019-10-23 01:28:42 +02:00
|
|
|
|
|
|
|
|
2017-09-03 20:13:14 +02:00
|
|
|
DEFAULT_ARCHIVE_NAME = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'
|
2019-09-13 00:27:04 +02:00
|
|
|
ARCHIVE_WITH_PATHS = ('repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'bar')
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2017-09-10 02:23:31 +02:00
|
|
|
def test_create_archive_calls_borg_with_parameters():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-01-15 00:52:19 +01:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
2017-08-06 08:32:39 +02:00
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-12-01 01:55:05 +01:00
|
|
|
('borg', 'create') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2017-08-06 01:21:39 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-01-15 00:52:19 +01:00
|
|
|
def test_create_archive_with_patterns_calls_borg_with_patterns():
|
|
|
|
pattern_flags = ('--patterns-from', 'patterns')
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-09-30 07:45:00 +02:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(
|
|
|
|
flexmock(name='/tmp/patterns')
|
|
|
|
).and_return(None)
|
2018-01-15 00:52:19 +01:00
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(pattern_flags)
|
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-12-01 01:55:05 +01:00
|
|
|
('borg', 'create') + pattern_flags + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2018-01-15 00:52:19 +01:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2018-01-15 00:52:19 +01:00
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'patterns': ['pattern'],
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-09-10 02:23:31 +02:00
|
|
|
def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
|
2017-08-06 08:32:39 +02:00
|
|
|
exclude_flags = ('--exclude-from', 'excludes')
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(('exclude',))
|
2018-09-30 07:45:00 +02:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None).and_return(
|
|
|
|
flexmock(name='/tmp/excludes')
|
|
|
|
)
|
2018-01-15 00:52:19 +01:00
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
2017-08-06 08:32:39 +02:00
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(exclude_flags)
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-12-01 01:55:05 +01:00
|
|
|
('borg', 'create') + exclude_flags + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2017-08-06 01:21:39 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': ['exclude'],
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-09-08 22:53:37 +02:00
|
|
|
def test_create_archive_with_log_info_calls_borg_with_info_parameter():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-01-15 00:52:19 +01:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
2017-08-06 08:32:39 +02:00
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2020-01-11 16:38:07 +01:00
|
|
|
('borg', 'create', '--info') + ARCHIVE_WITH_PATHS,
|
2019-06-12 21:11:36 +02:00
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2018-09-08 22:53:37 +02:00
|
|
|
insert_logging_mock(logging.INFO)
|
2018-09-30 07:45:00 +02:00
|
|
|
|
2017-08-06 01:21:39 +02:00
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2017-08-06 01:21:39 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-06-12 20:31:46 +02:00
|
|
|
def test_create_archive_with_log_info_and_json_suppresses_most_borg_output():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-06-12 20:31:46 +02:00
|
|
|
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_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-12-01 01:55:05 +01:00
|
|
|
('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=None,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-06-12 20:31:46 +02:00
|
|
|
)
|
|
|
|
insert_logging_mock(logging.INFO)
|
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
json=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-09-08 22:53:37 +02:00
|
|
|
def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-01-15 00:52:19 +01:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
2017-08-06 08:32:39 +02:00
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2020-01-23 00:23:49 +01:00
|
|
|
('borg', 'create', '--debug', '--show-rc') + ARCHIVE_WITH_PATHS,
|
2019-06-12 21:11:36 +02:00
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2018-09-30 07:45:00 +02:00
|
|
|
)
|
2018-09-08 22:53:37 +02:00
|
|
|
insert_logging_mock(logging.DEBUG)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-06-12 20:31:46 +02:00
|
|
|
def test_create_archive_with_log_debug_and_json_suppresses_most_borg_output():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-06-12 20:31:46 +02:00
|
|
|
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(
|
2019-12-01 01:55:05 +01:00
|
|
|
('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=None,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-06-12 20:31:46 +02:00
|
|
|
)
|
|
|
|
insert_logging_mock(logging.DEBUG)
|
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
json=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-01-16 05:55:27 +01:00
|
|
|
def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-01-16 05:55:27 +01:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-12-01 01:55:05 +01:00
|
|
|
('borg', 'create', '--dry-run') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2018-01-16 05:55:27 +01:00
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=True,
|
2017-08-06 01:21:39 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-01-23 00:23:49 +01:00
|
|
|
def test_create_archive_with_stats_and_dry_run_calls_borg_without_stats_parameter():
|
2019-01-27 22:47:26 +01:00
|
|
|
# --dry-run and --stats are mutually exclusive, see:
|
|
|
|
# https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-02-18 23:26:51 +01:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2020-01-11 16:38:07 +01:00
|
|
|
('borg', 'create', '--info', '--dry-run') + ARCHIVE_WITH_PATHS,
|
2019-06-12 21:11:36 +02:00
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2018-09-08 22:53:37 +02:00
|
|
|
insert_logging_mock(logging.INFO)
|
2018-02-18 23:26:51 +01:00
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=True,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
2020-01-23 00:23:49 +01:00
|
|
|
stats=True,
|
2018-08-19 20:41:49 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_interval_parameters():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-08-19 20:41:49 +02:00
|
|
|
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(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-09-13 00:27:04 +02:00
|
|
|
('borg', 'create', '--checkpoint-interval', '600') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2018-08-19 20:41:49 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={'checkpoint_interval': 600},
|
2018-02-18 23:26:51 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-10-28 00:57:28 +02:00
|
|
|
def test_create_archive_with_chunker_params_calls_borg_with_chunker_params_parameters():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-10-28 00:57:28 +02:00
|
|
|
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(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-09-13 00:27:04 +02:00
|
|
|
('borg', 'create', '--chunker-params', '1,2,3,4') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2018-10-28 00:57:28 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={'chunker_params': '1,2,3,4'},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-09-10 02:23:31 +02:00
|
|
|
def test_create_archive_with_compression_calls_borg_with_compression_parameters():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-01-15 00:52:19 +01:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
2017-08-06 08:32:39 +02:00
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-09-13 00:27:04 +02:00
|
|
|
('borg', 'create', '--compression', 'rle') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2017-08-06 01:21:39 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={'compression': 'rle'},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-11-03 06:22:40 +01:00
|
|
|
def test_create_archive_with_remote_rate_limit_calls_borg_with_remote_ratelimit_parameters():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-01-15 00:52:19 +01:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
2017-11-03 06:22:40 +01:00
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-09-13 00:27:04 +02:00
|
|
|
('borg', 'create', '--remote-ratelimit', '100') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2017-11-03 06:22:40 +01:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2017-11-03 06:22:40 +01:00
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={'remote_rate_limit': 100},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-03-05 18:11:35 +01:00
|
|
|
def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_parameter():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-01-15 00:52:19 +01:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
2017-08-06 08:32:39 +02:00
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-12-01 01:55:05 +01:00
|
|
|
('borg', 'create', '--one-file-system') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2017-08-06 01:21:39 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'one_file_system': True,
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
)
|
2017-11-03 06:03:11 +01:00
|
|
|
|
|
|
|
|
2019-03-05 18:11:35 +01:00
|
|
|
def test_create_archive_with_numeric_owner_calls_borg_with_numeric_owner_parameter():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-03-05 18:11:35 +01:00
|
|
|
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(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-12-01 01:55:05 +01:00
|
|
|
('borg', 'create', '--numeric-owner') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2019-03-05 18:11:35 +01:00
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'numeric_owner': True,
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-09-09 20:14:33 +02:00
|
|
|
def test_create_archive_with_read_special_calls_borg_with_read_special_parameter():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-09-09 19:39:56 +02:00
|
|
|
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(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-12-01 01:55:05 +01:00
|
|
|
('borg', 'create', '--read-special') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2018-09-09 19:39:56 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'read_special': True,
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-06-25 20:30:55 +02:00
|
|
|
@pytest.mark.parametrize('option_name', ('atime', 'ctime', 'birthtime', 'bsd_flags'))
|
|
|
|
def test_create_archive_with_option_true_calls_borg_without_corresponding_parameter(option_name):
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-05-27 00:09:23 +02:00
|
|
|
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(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-12-01 01:55:05 +01:00
|
|
|
('borg', 'create') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2018-05-27 00:09:23 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
2019-06-25 20:30:55 +02:00
|
|
|
option_name: True,
|
2018-05-27 00:09:23 +02:00
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-06-25 20:30:55 +02:00
|
|
|
@pytest.mark.parametrize('option_name', ('atime', 'ctime', 'birthtime', 'bsd_flags'))
|
|
|
|
def test_create_archive_with_option_false_calls_borg_with_corresponding_parameter(option_name):
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-05-27 00:09:23 +02:00
|
|
|
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(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-09-13 00:27:04 +02:00
|
|
|
('borg', 'create', '--no' + option_name.replace('_', '')) + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2018-05-27 00:09:23 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
2019-06-25 20:30:55 +02:00
|
|
|
option_name: False,
|
2018-05-27 00:09:23 +02:00
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-11-03 06:03:11 +01:00
|
|
|
def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-01-15 00:52:19 +01:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
2017-11-03 06:03:11 +01:00
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-09-13 00:27:04 +02:00
|
|
|
('borg', 'create', '--files-cache', 'ctime,size') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2017-11-03 06:03:11 +01:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2017-11-03 06:03:11 +01:00
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'files_cache': 'ctime,size',
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2018-01-15 01:35:24 +01:00
|
|
|
def test_create_archive_with_local_path_calls_borg_via_local_path():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-01-15 01:35:24 +01:00
|
|
|
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(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-12-01 01:55:05 +01:00
|
|
|
('borg1', 'create') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg1',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2018-01-15 01:35:24 +01:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2018-01-15 01:35:24 +01:00
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
local_path='borg1',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-09-10 02:23:31 +02:00
|
|
|
def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-01-15 00:52:19 +01:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
2017-08-06 08:32:39 +02:00
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-09-13 00:27:04 +02:00
|
|
|
('borg', 'create', '--remote-path', 'borg1') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2017-08-06 01:21:39 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
2018-01-15 01:35:24 +01:00
|
|
|
remote_path='borg1',
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-09-10 02:23:31 +02:00
|
|
|
def test_create_archive_with_umask_calls_borg_with_umask_parameters():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-01-15 00:52:19 +01:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
2017-08-06 08:32:39 +02:00
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-12-01 01:55:05 +01:00
|
|
|
('borg', 'create', '--umask', '740') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2017-08-06 01:21:39 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={'umask': 740},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-02-20 00:51:04 +01:00
|
|
|
def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-02-20 00:51:04 +01:00
|
|
|
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(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-12-01 01:55:05 +01:00
|
|
|
('borg', 'create', '--lock-wait', '5') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2018-02-20 00:51:04 +01:00
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={'lock_wait': 5},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-01-22 22:28:24 +01:00
|
|
|
def test_create_archive_with_stats_calls_borg_with_stats_parameter_and_warning_output_log_level():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-06-12 20:49:35 +02:00
|
|
|
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(
|
2019-12-01 01:55:05 +01:00
|
|
|
('borg', 'create', '--stats') + ARCHIVE_WITH_PATHS,
|
2020-01-22 22:28:24 +01:00
|
|
|
output_log_level=logging.WARNING,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2020-01-22 22:28:24 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
stats=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_archive_with_stats_and_log_info_calls_borg_with_stats_parameter_and_info_output_log_level():
|
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2020-01-22 22:28:24 +01:00
|
|
|
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(
|
|
|
|
('borg', 'create', '--info', '--stats') + ARCHIVE_WITH_PATHS,
|
2020-01-22 19:03:26 +01:00
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-06-12 20:49:35 +02:00
|
|
|
)
|
2020-01-22 22:28:24 +01:00
|
|
|
insert_logging_mock(logging.INFO)
|
2019-06-12 20:49:35 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
stats=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-01-22 22:28:24 +01:00
|
|
|
def test_create_archive_with_files_calls_borg_with_list_parameter_and_warning_output_log_level():
|
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2020-01-22 22:28:24 +01:00
|
|
|
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(
|
|
|
|
('borg', 'create', '--list', '--filter', 'AME-') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.WARNING,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2020-01-22 22:28:24 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
files=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_archive_with_files_and_log_info_calls_borg_with_list_parameter_and_info_output_log_level():
|
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2020-01-22 22:28:24 +01:00
|
|
|
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(
|
|
|
|
('borg', 'create', '--list', '--filter', 'AME-', '--info') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2020-01-22 22:28:24 +01:00
|
|
|
)
|
|
|
|
insert_logging_mock(logging.INFO)
|
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
files=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-12-01 00:31:36 +01:00
|
|
|
def test_create_archive_with_progress_and_log_info_calls_borg_with_progress_parameter_and_no_list():
|
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-12-01 00:31:36 +01:00
|
|
|
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(())
|
2020-05-10 06:53:16 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'create', '--info', '--progress') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
|
|
|
output_file=module.DO_NOT_CAPTURE,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-12-01 00:31:36 +01:00
|
|
|
)
|
|
|
|
insert_logging_mock(logging.INFO)
|
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
progress=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-09-25 21:03:10 +02:00
|
|
|
def test_create_archive_with_progress_calls_borg_with_progress_parameter():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-09-25 21:03:10 +02:00
|
|
|
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(())
|
2020-05-10 06:53:16 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'create', '--progress') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
|
|
|
output_file=module.DO_NOT_CAPTURE,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-09-25 21:03:10 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
progress=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-05-11 20:34:14 +02:00
|
|
|
def test_create_archive_with_progress_and_stream_processes_calls_borg_with_progress_parameter():
|
|
|
|
processes = flexmock()
|
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2020-05-11 20:34:14 +02:00
|
|
|
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_processes').with_args(
|
2020-05-26 18:20:14 +02:00
|
|
|
('borg', 'create', '--one-file-system', '--read-special', '--progress')
|
|
|
|
+ ARCHIVE_WITH_PATHS,
|
2020-05-11 20:34:14 +02:00
|
|
|
processes=processes,
|
|
|
|
output_log_level=logging.INFO,
|
|
|
|
output_file=module.DO_NOT_CAPTURE,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2020-05-11 20:34:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
progress=True,
|
|
|
|
stream_processes=processes,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-09-24 21:52:04 +02:00
|
|
|
def test_create_archive_with_json_calls_borg_with_json_parameter():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-09-24 21:52:04 +02:00
|
|
|
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(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-12-01 01:55:05 +01:00
|
|
|
('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=None,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
).and_return('[]')
|
2018-09-24 21:52:04 +02:00
|
|
|
|
2019-04-03 07:30:14 +02:00
|
|
|
json_output = module.create_archive(
|
2018-09-24 21:52:04 +02:00
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
2018-09-30 07:45:00 +02:00
|
|
|
json=True,
|
2018-09-24 21:52:04 +02:00
|
|
|
)
|
|
|
|
|
2019-04-03 07:30:14 +02:00
|
|
|
assert json_output == '[]'
|
|
|
|
|
2018-09-24 21:52:04 +02:00
|
|
|
|
2019-06-12 20:49:35 +02:00
|
|
|
def test_create_archive_with_stats_and_json_calls_borg_without_stats_parameter():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-06-12 20:49:35 +02:00
|
|
|
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(
|
2019-12-01 01:55:05 +01:00
|
|
|
('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=None,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-06-12 20:49:35 +02:00
|
|
|
).and_return('[]')
|
|
|
|
|
|
|
|
json_output = module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
json=True,
|
|
|
|
stats=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert json_output == '[]'
|
|
|
|
|
|
|
|
|
2017-08-06 01:21:39 +02:00
|
|
|
def test_create_archive_with_source_directories_glob_expands():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'food'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-01-15 00:52:19 +01:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
2017-08-06 08:32:39 +02:00
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
|
2019-06-12 21:11:36 +02:00
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2018-09-30 07:45:00 +02:00
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food'])
|
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2017-08-06 01:21:39 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo*'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_archive_with_non_matching_source_directories_glob_passes_through():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo*',))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-01-15 00:52:19 +01:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
2017-08-06 08:32:39 +02:00
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-06-12 20:49:35 +02:00
|
|
|
('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo*'),
|
2019-06-12 21:11:36 +02:00
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
flexmock(module.glob).should_receive('glob').with_args('foo*').and_return([])
|
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2017-08-06 01:21:39 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo*'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-09-10 02:23:31 +02:00
|
|
|
def test_create_archive_with_glob_calls_borg_with_expanded_directories():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'food'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-01-15 00:52:19 +01:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
2017-08-06 08:32:39 +02:00
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
|
2019-06-12 21:11:36 +02:00
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2018-09-30 07:45:00 +02:00
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2017-08-06 01:21:39 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo*'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
)
|
2017-09-03 20:13:14 +02:00
|
|
|
|
|
|
|
|
2017-09-10 02:23:31 +02:00
|
|
|
def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-01-15 00:52:19 +01:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
2017-09-03 20:13:14 +02:00
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-12-01 01:55:05 +01:00
|
|
|
('borg', 'create', 'repo::ARCHIVE_NAME', 'foo', 'bar'),
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2017-09-03 20:13:14 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2017-09-03 20:13:14 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
2018-09-30 07:45:00 +02:00
|
|
|
storage_config={'archive_name_format': 'ARCHIVE_NAME'},
|
2017-09-03 20:13:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_archive_with_archive_name_format_accepts_borg_placeholders():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-01-27 22:47:26 +01:00
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
2018-01-15 00:52:19 +01:00
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
2017-09-03 20:13:14 +02:00
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2019-06-12 20:49:35 +02:00
|
|
|
('borg', 'create', 'repo::Documents_{hostname}-{now}', 'foo', 'bar'),
|
2019-06-12 21:11:36 +02:00
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2017-09-03 20:13:14 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2017-09-03 20:13:14 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
2018-09-30 07:45:00 +02:00
|
|
|
storage_config={'archive_name_format': 'Documents_{hostname}-{now}'},
|
2017-09-03 20:13:14 +02:00
|
|
|
)
|
2019-12-05 00:48:10 +01:00
|
|
|
|
|
|
|
|
2020-11-18 19:58:23 +01:00
|
|
|
def test_create_archive_with_repository_accepts_borg_placeholders():
|
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
|
|
|
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(
|
|
|
|
('borg', 'create', '{fqdn}::Documents_{hostname}-{now}', 'foo', 'bar'),
|
|
|
|
output_log_level=logging.INFO,
|
|
|
|
output_file=None,
|
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2020-11-18 19:58:23 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='{fqdn}',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['{fqdn}'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={'archive_name_format': 'Documents_{hostname}-{now}'},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-12-05 00:48:10 +01:00
|
|
|
def test_create_archive_with_extra_borg_options_calls_borg_with_extra_options():
|
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2019-12-05 00:48:10 +01:00
|
|
|
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(
|
|
|
|
('borg', 'create', '--extra', '--options') + ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2019-12-05 00:48:10 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={'extra_borg_options': {'create': '--extra --options'}},
|
|
|
|
)
|
2020-05-07 21:14:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_create_archive_with_stream_processes_calls_borg_with_processes():
|
|
|
|
processes = flexmock()
|
|
|
|
flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(())
|
2020-05-07 21:14:27 +02:00
|
|
|
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_processes').with_args(
|
2020-05-26 18:20:14 +02:00
|
|
|
('borg', 'create', '--one-file-system', '--read-special') + ARCHIVE_WITH_PATHS,
|
2020-05-07 21:14:27 +02:00
|
|
|
processes=processes,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2020-05-07 21:14:27 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
location_config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
storage_config={},
|
|
|
|
stream_processes=processes,
|
|
|
|
)
|