From e83ad9e1e4cb3dfb2209268f51a0f853825c6fc4 Mon Sep 17 00:00:00 2001 From: Divyansh Singh Date: Sat, 25 Mar 2023 01:04:57 +0530 Subject: [PATCH] use repository["path"] instead of repository --- borgmatic/actions/borg.py | 6 ++-- borgmatic/actions/break_lock.py | 8 +++-- borgmatic/actions/check.py | 4 +-- borgmatic/actions/compact.py | 8 +++-- borgmatic/actions/export_tar.py | 8 +++-- borgmatic/actions/extract.py | 8 +++-- borgmatic/actions/info.py | 6 ++-- borgmatic/actions/list.py | 8 ++--- borgmatic/actions/mount.py | 10 +++--- borgmatic/actions/prune.py | 4 +-- borgmatic/actions/rcreate.py | 4 +-- borgmatic/actions/restore.py | 27 ++++++++++++----- borgmatic/actions/rinfo.py | 6 ++-- borgmatic/actions/rlist.py | 4 +-- borgmatic/commands/borgmatic.py | 4 +++ borgmatic/config/normalize.py | 37 ++++++++++++++--------- borgmatic/config/schema.yaml | 36 ++++++++++++++-------- borgmatic/config/validate.py | 14 +++++---- tests/integration/config/test_validate.py | 21 +++++++++---- tests/unit/actions/test_borg.py | 2 +- tests/unit/actions/test_break_lock.py | 2 +- tests/unit/actions/test_check.py | 6 ++-- tests/unit/actions/test_compact.py | 6 ++-- tests/unit/actions/test_create.py | 4 +-- tests/unit/actions/test_export_tar.py | 2 +- tests/unit/actions/test_extract.py | 2 +- tests/unit/actions/test_info.py | 2 +- tests/unit/actions/test_list.py | 2 +- tests/unit/actions/test_mount.py | 2 +- tests/unit/actions/test_prune.py | 4 +-- tests/unit/actions/test_rcreate.py | 4 +-- tests/unit/actions/test_restore.py | 16 +++++----- tests/unit/actions/test_rinfo.py | 2 +- tests/unit/actions/test_rlist.py | 2 +- tests/unit/commands/test_borgmatic.py | 36 +++++++++++----------- tests/unit/config/test_normalize.py | 10 +++--- 36 files changed, 193 insertions(+), 134 deletions(-) diff --git a/borgmatic/actions/borg.py b/borgmatic/actions/borg.py index a50dd286..bf9abd5a 100644 --- a/borgmatic/actions/borg.py +++ b/borgmatic/actions/borg.py @@ -16,9 +16,9 @@ def run_borg( if borg_arguments.repository is None or borgmatic.config.validate.repositories_match( repository, borg_arguments.repository ): - logger.info('{}: Running arbitrary Borg command'.format(repository)) + logger.info('{}: Running arbitrary Borg command'.format(repository['path'])) archive_name = borgmatic.borg.rlist.resolve_archive_name( - repository, + repository['path'], borg_arguments.archive, storage, local_borg_version, @@ -26,7 +26,7 @@ def run_borg( remote_path, ) borgmatic.borg.borg.run_arbitrary_borg( - repository, + repository['path'], storage, local_borg_version, options=borg_arguments.options, diff --git a/borgmatic/actions/break_lock.py b/borgmatic/actions/break_lock.py index 65384d7a..eb6e4547 100644 --- a/borgmatic/actions/break_lock.py +++ b/borgmatic/actions/break_lock.py @@ -15,7 +15,11 @@ def run_break_lock( if break_lock_arguments.repository is None or borgmatic.config.validate.repositories_match( repository, break_lock_arguments.repository ): - logger.info(f'{repository}: Breaking repository and cache locks') + logger.info(f'{repository["path"]}: Breaking repository and cache locks') borgmatic.borg.break_lock.break_lock( - repository, storage, local_borg_version, local_path=local_path, remote_path=remote_path, + repository['path'], + storage, + local_borg_version, + local_path=local_path, + remote_path=remote_path, ) diff --git a/borgmatic/actions/check.py b/borgmatic/actions/check.py index f3572395..ff8225ec 100644 --- a/borgmatic/actions/check.py +++ b/borgmatic/actions/check.py @@ -37,9 +37,9 @@ def run_check( global_arguments.dry_run, **hook_context, ) - logger.info('{}: Running consistency checks'.format(repository)) + logger.info('{}: Running consistency checks'.format(repository['path'])) borgmatic.borg.check.check_archives( - repository, + repository['path'], location, storage, consistency, diff --git a/borgmatic/actions/compact.py b/borgmatic/actions/compact.py index 7a25b829..13bb28ea 100644 --- a/borgmatic/actions/compact.py +++ b/borgmatic/actions/compact.py @@ -39,10 +39,10 @@ def run_compact( **hook_context, ) if borgmatic.borg.feature.available(borgmatic.borg.feature.Feature.COMPACT, local_borg_version): - logger.info('{}: Compacting segments{}'.format(repository, dry_run_label)) + logger.info('{}: Compacting segments{}'.format(repository['path'], dry_run_label)) borgmatic.borg.compact.compact_segments( global_arguments.dry_run, - repository, + repository['path'], storage, local_borg_version, local_path=local_path, @@ -52,7 +52,9 @@ def run_compact( threshold=compact_arguments.threshold, ) else: # pragma: nocover - logger.info('{}: Skipping compact (only available/needed in Borg 1.2+)'.format(repository)) + logger.info( + '{}: Skipping compact (only available/needed in Borg 1.2+)'.format(repository['path']) + ) borgmatic.hooks.command.execute_hook( hooks.get('after_compact'), hooks.get('umask'), diff --git a/borgmatic/actions/export_tar.py b/borgmatic/actions/export_tar.py index ae349208..7599a23a 100644 --- a/borgmatic/actions/export_tar.py +++ b/borgmatic/actions/export_tar.py @@ -23,13 +23,15 @@ def run_export_tar( repository, export_tar_arguments.repository ): logger.info( - '{}: Exporting archive {} as tar file'.format(repository, export_tar_arguments.archive) + '{}: Exporting archive {} as tar file'.format( + repository['path'], export_tar_arguments.archive + ) ) borgmatic.borg.export_tar.export_tar_archive( global_arguments.dry_run, - repository, + repository['path'], borgmatic.borg.rlist.resolve_archive_name( - repository, + repository['path'], export_tar_arguments.archive, storage, local_borg_version, diff --git a/borgmatic/actions/extract.py b/borgmatic/actions/extract.py index a3d89a55..a36c498b 100644 --- a/borgmatic/actions/extract.py +++ b/borgmatic/actions/extract.py @@ -35,12 +35,14 @@ def run_extract( if extract_arguments.repository is None or borgmatic.config.validate.repositories_match( repository, extract_arguments.repository ): - logger.info('{}: Extracting archive {}'.format(repository, extract_arguments.archive)) + logger.info( + '{}: Extracting archive {}'.format(repository['path'], extract_arguments.archive) + ) borgmatic.borg.extract.extract_archive( global_arguments.dry_run, - repository, + repository['path'], borgmatic.borg.rlist.resolve_archive_name( - repository, + repository['path'], extract_arguments.archive, storage, local_borg_version, diff --git a/borgmatic/actions/info.py b/borgmatic/actions/info.py index ab4fe426..6cd775f5 100644 --- a/borgmatic/actions/info.py +++ b/borgmatic/actions/info.py @@ -20,9 +20,9 @@ def run_info( repository, info_arguments.repository ): if not info_arguments.json: # pragma: nocover - logger.answer(f'{repository}: Displaying archive summary information') + logger.answer(f'{repository["path"]}: Displaying archive summary information') info_arguments.archive = borgmatic.borg.rlist.resolve_archive_name( - repository, + repository['path'], info_arguments.archive, storage, local_borg_version, @@ -30,7 +30,7 @@ def run_info( remote_path, ) json_output = borgmatic.borg.info.display_archives_info( - repository, + repository['path'], storage, local_borg_version, info_arguments=info_arguments, diff --git a/borgmatic/actions/list.py b/borgmatic/actions/list.py index 78efdf59..0e736f84 100644 --- a/borgmatic/actions/list.py +++ b/borgmatic/actions/list.py @@ -20,11 +20,11 @@ def run_list( ): if not list_arguments.json: # pragma: nocover if list_arguments.find_paths: - logger.answer(f'{repository}: Searching archives') + logger.answer(f'{repository["path"]}: Searching archives') elif not list_arguments.archive: - logger.answer(f'{repository}: Listing archives') + logger.answer(f'{repository["path"]}: Listing archives') list_arguments.archive = borgmatic.borg.rlist.resolve_archive_name( - repository, + repository['path'], list_arguments.archive, storage, local_borg_version, @@ -32,7 +32,7 @@ def run_list( remote_path, ) json_output = borgmatic.borg.list.list_archive( - repository, + repository['path'], storage, local_borg_version, list_arguments=list_arguments, diff --git a/borgmatic/actions/mount.py b/borgmatic/actions/mount.py index e2703a57..d2c1821d 100644 --- a/borgmatic/actions/mount.py +++ b/borgmatic/actions/mount.py @@ -17,14 +17,16 @@ def run_mount( repository, mount_arguments.repository ): if mount_arguments.archive: - logger.info('{}: Mounting archive {}'.format(repository, mount_arguments.archive)) + logger.info( + '{}: Mounting archive {}'.format(repository['path'], mount_arguments.archive) + ) else: # pragma: nocover - logger.info('{}: Mounting repository'.format(repository)) + logger.info('{}: Mounting repository'.format(repository['path'])) borgmatic.borg.mount.mount_archive( - repository, + repository['path'], borgmatic.borg.rlist.resolve_archive_name( - repository, + repository['path'], mount_arguments.archive, storage, local_borg_version, diff --git a/borgmatic/actions/prune.py b/borgmatic/actions/prune.py index ca098ce4..6ba28a92 100644 --- a/borgmatic/actions/prune.py +++ b/borgmatic/actions/prune.py @@ -37,10 +37,10 @@ def run_prune( global_arguments.dry_run, **hook_context, ) - logger.info('{}: Pruning archives{}'.format(repository, dry_run_label)) + logger.info('{}: Pruning archives{}'.format(repository['path'], dry_run_label)) borgmatic.borg.prune.prune_archives( global_arguments.dry_run, - repository, + repository['path'], storage, retention, local_borg_version, diff --git a/borgmatic/actions/rcreate.py b/borgmatic/actions/rcreate.py index 0052b4b6..92dcfe34 100644 --- a/borgmatic/actions/rcreate.py +++ b/borgmatic/actions/rcreate.py @@ -23,10 +23,10 @@ def run_rcreate( ): return - logger.info('{}: Creating repository'.format(repository)) + logger.info('{}: Creating repository'.format(repository['path'])) borgmatic.borg.rcreate.create_repository( global_arguments.dry_run, - repository, + repository['path'], storage, local_borg_version, rcreate_arguments.encryption_mode, diff --git a/borgmatic/actions/restore.py b/borgmatic/actions/restore.py index 7a058092..793b8698 100644 --- a/borgmatic/actions/restore.py +++ b/borgmatic/actions/restore.py @@ -256,22 +256,35 @@ def run_restore( return logger.info( - '{}: Restoring databases from archive {}'.format(repository, restore_arguments.archive) + '{}: Restoring databases from archive {}'.format( + repository['path'], restore_arguments.archive + ) ) borgmatic.hooks.dispatch.call_hooks_even_if_unconfigured( 'remove_database_dumps', hooks, - repository, + repository['path'], borgmatic.hooks.dump.DATABASE_HOOK_NAMES, location, global_arguments.dry_run, ) archive_name = borgmatic.borg.rlist.resolve_archive_name( - repository, restore_arguments.archive, storage, local_borg_version, local_path, remote_path, + repository['path'], + restore_arguments.archive, + storage, + local_borg_version, + local_path, + remote_path, ) archive_database_names = collect_archive_database_names( - repository, archive_name, location, storage, local_borg_version, local_path, remote_path, + repository['path'], + archive_name, + location, + storage, + local_borg_version, + local_path, + remote_path, ) restore_names = find_databases_to_restore(restore_arguments.databases, archive_database_names) found_names = set() @@ -291,7 +304,7 @@ def run_restore( found_names.add(database_name) restore_single_database( - repository, + repository['path'], location, storage, hooks, @@ -320,7 +333,7 @@ def run_restore( database['name'] = database_name restore_single_database( - repository, + repository['path'], location, storage, hooks, @@ -336,7 +349,7 @@ def run_restore( borgmatic.hooks.dispatch.call_hooks_even_if_unconfigured( 'remove_database_dumps', hooks, - repository, + repository['path'], borgmatic.hooks.dump.DATABASE_HOOK_NAMES, location, global_arguments.dry_run, diff --git a/borgmatic/actions/rinfo.py b/borgmatic/actions/rinfo.py index 611d1bc2..5e0a41a7 100644 --- a/borgmatic/actions/rinfo.py +++ b/borgmatic/actions/rinfo.py @@ -19,9 +19,11 @@ def run_rinfo( repository, rinfo_arguments.repository ): if not rinfo_arguments.json: # pragma: nocover - logger.answer('{}: Displaying repository summary information'.format(repository)) + logger.answer( + '{}: Displaying repository summary information'.format(repository['path']) + ) json_output = borgmatic.borg.rinfo.display_repository_info( - repository, + repository['path'], storage, local_borg_version, rinfo_arguments=rinfo_arguments, diff --git a/borgmatic/actions/rlist.py b/borgmatic/actions/rlist.py index 72d52068..29e500c1 100644 --- a/borgmatic/actions/rlist.py +++ b/borgmatic/actions/rlist.py @@ -19,9 +19,9 @@ def run_rlist( repository, rlist_arguments.repository ): if not rlist_arguments.json: # pragma: nocover - logger.answer('{}: Listing repository'.format(repository)) + logger.answer('{}: Listing repository'.format(repository['path'])) json_output = borgmatic.borg.rlist.list_repository( - repository, + repository['path'], storage, local_borg_version, rlist_arguments=rlist_arguments, diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 1f8b15f4..b52bc568 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -109,6 +109,8 @@ def run_configuration(config_filename, config, arguments): while not repo_queue.empty(): repository, retry_num = repo_queue.get() + if isinstance(repository, str): + repository = {'path': repository} timeout = retry_num * retry_wait if timeout: logger.warning(f'{config_filename}: Sleeping {timeout}s before next retry') @@ -263,6 +265,8 @@ def run_actions( invalid. ''' add_custom_log_levels() + if isinstance(repository, str): + repository = {'path': repository} repository_path = os.path.expanduser(repository['path']) global_arguments = arguments['global'] dry_run_label = ' (dry run; not making any changes)' if global_arguments.dry_run else '' diff --git a/borgmatic/config/normalize.py b/borgmatic/config/normalize.py index 8ce4af22..eb2ed013 100644 --- a/borgmatic/config/normalize.py +++ b/borgmatic/config/normalize.py @@ -56,14 +56,16 @@ def normalize(config_filename, config): # Upgrade remote repositories to ssh:// syntax, required in Borg 2. repositories = location.get('repositories') - if isinstance(repositories[0], str): - config['location']['repositories'] = [{'path': repository} for repository in repositories] - repositories = config['location']['repositories'] if repositories: + if isinstance(repositories[0], str): + config['location']['repositories'] = [ + {'path': repository} for repository in repositories + ] + repositories = config['location']['repositories'] config['location']['repositories'] = [] for repository_dict in repositories: - repository = repository_dict['path'] - if '~' in repository: + repository_path = repository_dict['path'] + if '~' in repository_path: logs.append( logging.makeLogRecord( dict( @@ -73,37 +75,42 @@ def normalize(config_filename, config): ) ) ) - if ':' in repository: - if repository.startswith('file://'): - updated_repository_path = os.path.abspath(repository.partition('file://')[-1]) + if ':' in repository_path: + if repository_path.startswith('file://'): + updated_repository_path = os.path.abspath( + repository_path.partition('file://')[-1] + ) config['location']['repositories'].append( { 'path': updated_repository_path, - 'label': repository_dict.get('label', None), + 'label': repository_dict.get('label', ''), } ) - elif repository.startswith('ssh://'): + elif repository_path.startswith('ssh://'): config['location']['repositories'].append( - {'path': repository, 'label': repository_dict.get('label', None),} + {'path': repository_path, 'label': repository_dict.get('label', '')} ) else: - rewritten_repository = f"ssh://{repository.replace(':~', '/~').replace(':/', '/').replace(':', '/./')}" + rewritten_repository_path = f"ssh://{repository_path.replace(':~', '/~').replace(':/', '/').replace(':', '/./')}" logs.append( logging.makeLogRecord( dict( levelno=logging.WARNING, levelname='WARNING', - msg=f'{config_filename}: Remote repository paths without ssh:// syntax are deprecated. Interpreting "{repository}" as "{rewritten_repository}"', + msg=f'{config_filename}: Remote repository paths without ssh:// syntax are deprecated. Interpreting "{repository_path}" as "{rewritten_repository_path}"', ) ) ) config['location']['repositories'].append( - {'path': rewritten_repository, 'label': repository_dict.get('label', None),} + { + 'path': rewritten_repository_path, + 'label': repository_dict.get('label', ''), + } ) else: config['location']['repositories'].append( - {'path': repository, 'label': repository_dict.get('label', None),} + {'path': repository_path, 'label': repository_dict.get('label', '')} ) return logs diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index 4235adba..14d028b7 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -36,23 +36,33 @@ properties: path: type: string description: | - Path to local or remote repository (required). - are expanded. Multiple repositories are backed up to - in sequence. Borg placeholders can be used. See the - output of "borg help placeholders" for details. See - ssh_command for SSH options like identity file or - port. If systemd service is used, then add local - repository paths in the systemd service file to the - ReadWritePaths list. - example: - - ssh://user@backupserver/./sourcehostname.borg - - ssh://user@backupserver/./{fqdn} - - /var/local/backups/local.borg + Path to local or remote repository + (required). Tildes are expanded. + Multiple repositories are backed up + to in sequence. Borg placeholders + can be used. See the output of + "borg help placeholders" for + details. See ssh_command for SSH + options like identity file or port. + If systemd service is used, then + add local repository paths in the + systemd service file to the + ReadWritePaths list. + example: ssh://user@backupserver/./{fqdn} label: type: string description: | - Optional label for the repository. + Optional label for the repository. This + can be used with the --repository option + to select a repository to backup to. + If not specified, the repository path is + used as the label. example: backupserver + example: + - path: ssh://user@backupserver/./{fqdn} + label: backupserver + - path: /mnt/backup + label: local working_directory: type: string description: | diff --git a/borgmatic/config/validate.py b/borgmatic/config/validate.py index b43d42df..ecacec71 100644 --- a/borgmatic/config/validate.py +++ b/borgmatic/config/validate.py @@ -141,12 +141,14 @@ def repositories_match(first, second): Given two repository dicts with keys 'path' (relative and/or absolute), and 'label', return whether they match. ''' - if isinstance(first, str) and isinstance(second, str): - return normalize_repository_path(first) == normalize_repository_path(second) - elif isinstance(first, dict) and isinstance(second, str): - return (second == first.get('label')) or ( - normalize_repository_path(second) == normalize_repository_path(first.get('path')) - ) + if isinstance(first, str): + first = {'path': first, 'label': first} + if isinstance(second, str): + second = {'path': second, 'label': second} + return (first.get('label') == second.get('label')) or ( + normalize_repository_path(first.get('path')) + == normalize_repository_path(second.get('path')) + ) def guard_configuration_contains_repository(repository, configurations): diff --git a/tests/integration/config/test_validate.py b/tests/integration/config/test_validate.py index 5d948ae2..31a85cd1 100644 --- a/tests/integration/config/test_validate.py +++ b/tests/integration/config/test_validate.py @@ -63,7 +63,10 @@ def test_parse_configuration_transforms_file_into_mapping(): config, logs = module.parse_configuration('/tmp/config.yaml', '/tmp/schema.yaml') assert config == { - 'location': {'source_directories': ['/home', '/etc'], 'repositories': ['hostname.borg']}, + 'location': { + 'source_directories': ['/home', '/etc'], + 'repositories': [{'path': 'hostname.borg', 'label': ''}], + }, 'retention': {'keep_daily': 7, 'keep_hourly': 24, 'keep_minutely': 60}, 'consistency': {'checks': [{'name': 'repository'}, {'name': 'archives'}]}, } @@ -89,7 +92,7 @@ def test_parse_configuration_passes_through_quoted_punctuation(): assert config == { 'location': { 'source_directories': [f'/home/{string.punctuation}'], - 'repositories': ['test.borg'], + 'repositories': [{'path': 'test.borg', 'label': ''}], } } assert logs == [] @@ -151,7 +154,10 @@ def test_parse_configuration_inlines_include(): config, logs = module.parse_configuration('/tmp/config.yaml', '/tmp/schema.yaml') assert config == { - 'location': {'source_directories': ['/home'], 'repositories': ['hostname.borg']}, + 'location': { + 'source_directories': ['/home'], + 'repositories': [{'path': 'hostname.borg', 'label': ''}], + }, 'retention': {'keep_daily': 7, 'keep_hourly': 24}, } assert logs == [] @@ -185,7 +191,10 @@ def test_parse_configuration_merges_include(): config, logs = module.parse_configuration('/tmp/config.yaml', '/tmp/schema.yaml') assert config == { - 'location': {'source_directories': ['/home'], 'repositories': ['hostname.borg']}, + 'location': { + 'source_directories': ['/home'], + 'repositories': [{'path': 'hostname.borg', 'label': ''}], + }, 'retention': {'keep_daily': 1, 'keep_hourly': 24}, } assert logs == [] @@ -247,7 +256,7 @@ def test_parse_configuration_applies_overrides(): assert config == { 'location': { 'source_directories': ['/home'], - 'repositories': ['hostname.borg'], + 'repositories': [{'path': 'hostname.borg', 'label': ''}], 'local_path': 'borg2', } } @@ -273,7 +282,7 @@ def test_parse_configuration_applies_normalization(): assert config == { 'location': { 'source_directories': ['/home'], - 'repositories': ['hostname.borg'], + 'repositories': [{'path': 'hostname.borg', 'label': ''}], 'exclude_if_present': ['.nobackup'], } } diff --git a/tests/unit/actions/test_borg.py b/tests/unit/actions/test_borg.py index 7b22c7b3..f597acbf 100644 --- a/tests/unit/actions/test_borg.py +++ b/tests/unit/actions/test_borg.py @@ -13,7 +13,7 @@ def test_run_borg_does_not_raise(): borg_arguments = flexmock(repository=flexmock(), archive=flexmock(), options=flexmock()) module.run_borg( - repository='repo', + repository={'path': 'repos'}, storage={}, local_borg_version=None, borg_arguments=borg_arguments, diff --git a/tests/unit/actions/test_break_lock.py b/tests/unit/actions/test_break_lock.py index c7db00bc..6dc2470e 100644 --- a/tests/unit/actions/test_break_lock.py +++ b/tests/unit/actions/test_break_lock.py @@ -10,7 +10,7 @@ def test_run_break_lock_does_not_raise(): break_lock_arguments = flexmock(repository=flexmock()) module.run_break_lock( - repository='repo', + repository={'path': 'repo'}, storage={}, local_borg_version=None, break_lock_arguments=break_lock_arguments, diff --git a/tests/unit/actions/test_check.py b/tests/unit/actions/test_check.py index 3e1a9c2f..4c2027eb 100644 --- a/tests/unit/actions/test_check.py +++ b/tests/unit/actions/test_check.py @@ -18,7 +18,7 @@ def test_run_check_calls_hooks_for_configured_repository(): module.run_check( config_filename='test.yaml', - repository='repo', + repository={'path': 'repo'}, location={'repositories': ['repo']}, storage={}, consistency={}, @@ -49,7 +49,7 @@ def test_run_check_runs_with_selected_repository(): module.run_check( config_filename='test.yaml', - repository=flexmock(), + repository={'path': 'repo'}, location={'repositories': ['repo']}, storage={}, consistency={}, @@ -80,7 +80,7 @@ def test_run_check_bails_if_repository_does_not_match(): module.run_check( config_filename='test.yaml', - repository='repo', + repository={'path': 'repo'}, location={'repositories': ['repo']}, storage={}, consistency={}, diff --git a/tests/unit/actions/test_compact.py b/tests/unit/actions/test_compact.py index 4dae903e..fbd4f905 100644 --- a/tests/unit/actions/test_compact.py +++ b/tests/unit/actions/test_compact.py @@ -16,7 +16,7 @@ def test_compact_actions_calls_hooks_for_configured_repository(): module.run_compact( config_filename='test.yaml', - repository='repo', + repository={'path': 'repo'}, storage={}, retention={}, hooks={}, @@ -44,7 +44,7 @@ def test_compact_runs_with_selected_repository(): module.run_compact( config_filename='test.yaml', - repository='repo', + repository={'path': 'repo'}, storage={}, retention={}, hooks={}, @@ -72,7 +72,7 @@ def test_compact_bails_if_repository_does_not_match(): module.run_compact( config_filename='test.yaml', - repository='repo', + repository={'path': 'repo'}, storage={}, retention={}, hooks={}, diff --git a/tests/unit/actions/test_create.py b/tests/unit/actions/test_create.py index 8a9d0b4e..2b724085 100644 --- a/tests/unit/actions/test_create.py +++ b/tests/unit/actions/test_create.py @@ -24,7 +24,7 @@ def test_run_create_executes_and_calls_hooks_for_configured_repository(): list( module.run_create( config_filename='test.yaml', - repository='repo', + repository={'path': 'repo'}, location={}, storage={}, hooks={}, @@ -57,7 +57,7 @@ def test_run_create_runs_with_selected_repository(): list( module.run_create( config_filename='test.yaml', - repository='repo', + repository={'path': 'repo'}, location={}, storage={}, hooks={}, diff --git a/tests/unit/actions/test_export_tar.py b/tests/unit/actions/test_export_tar.py index 41b680af..6741d427 100644 --- a/tests/unit/actions/test_export_tar.py +++ b/tests/unit/actions/test_export_tar.py @@ -19,7 +19,7 @@ def test_run_export_tar_does_not_raise(): global_arguments = flexmock(monitoring_verbosity=1, dry_run=False) module.run_export_tar( - repository='repo', + repository={'path': 'repo'}, storage={}, local_borg_version=None, export_tar_arguments=export_tar_arguments, diff --git a/tests/unit/actions/test_extract.py b/tests/unit/actions/test_extract.py index 4222b8a8..32b93b4e 100644 --- a/tests/unit/actions/test_extract.py +++ b/tests/unit/actions/test_extract.py @@ -20,7 +20,7 @@ def test_run_extract_calls_hooks(): module.run_extract( config_filename='test.yaml', - repository='repo', + repository={'path': 'repo'}, location={'repositories': ['repo']}, storage={}, hooks={}, diff --git a/tests/unit/actions/test_info.py b/tests/unit/actions/test_info.py index 8cde178d..a4f1d544 100644 --- a/tests/unit/actions/test_info.py +++ b/tests/unit/actions/test_info.py @@ -14,7 +14,7 @@ def test_run_info_does_not_raise(): list( module.run_info( - repository='repo', + repository={'path': 'repo'}, storage={}, local_borg_version=None, info_arguments=info_arguments, diff --git a/tests/unit/actions/test_list.py b/tests/unit/actions/test_list.py index f4a603de..bfdfd010 100644 --- a/tests/unit/actions/test_list.py +++ b/tests/unit/actions/test_list.py @@ -14,7 +14,7 @@ def test_run_list_does_not_raise(): list( module.run_list( - repository='repo', + repository={'path': 'repo'}, storage={}, local_borg_version=None, list_arguments=list_arguments, diff --git a/tests/unit/actions/test_mount.py b/tests/unit/actions/test_mount.py index 0624a896..7eadfca1 100644 --- a/tests/unit/actions/test_mount.py +++ b/tests/unit/actions/test_mount.py @@ -17,7 +17,7 @@ def test_run_mount_does_not_raise(): ) module.run_mount( - repository='repo', + repository={'path': 'repo'}, storage={}, local_borg_version=None, mount_arguments=mount_arguments, diff --git a/tests/unit/actions/test_prune.py b/tests/unit/actions/test_prune.py index db9c1247..7af7ea77 100644 --- a/tests/unit/actions/test_prune.py +++ b/tests/unit/actions/test_prune.py @@ -13,7 +13,7 @@ def test_run_prune_calls_hooks_for_configured_repository(): module.run_prune( config_filename='test.yaml', - repository='repo', + repository={'path': 'repo'}, storage={}, retention={}, hooks={}, @@ -38,7 +38,7 @@ def test_run_prune_runs_with_selected_repository(): module.run_prune( config_filename='test.yaml', - repository='repo', + repository={'path': 'repo'}, storage={}, retention={}, hooks={}, diff --git a/tests/unit/actions/test_rcreate.py b/tests/unit/actions/test_rcreate.py index 78d4af1f..b77fa757 100644 --- a/tests/unit/actions/test_rcreate.py +++ b/tests/unit/actions/test_rcreate.py @@ -18,7 +18,7 @@ def test_run_rcreate_does_not_raise(): ) module.run_rcreate( - repository='repo', + repository={'path': 'repo'}, storage={}, local_borg_version=None, rcreate_arguments=arguments, @@ -45,7 +45,7 @@ def test_run_rcreate_bails_if_repository_does_not_match(): ) module.run_rcreate( - repository='repo', + repository={'path': 'repo'}, storage={}, local_borg_version=None, rcreate_arguments=arguments, diff --git a/tests/unit/actions/test_restore.py b/tests/unit/actions/test_restore.py index eaad6bf4..8255c87d 100644 --- a/tests/unit/actions/test_restore.py +++ b/tests/unit/actions/test_restore.py @@ -67,7 +67,7 @@ def test_collect_archive_database_names_parses_archive_paths(): ) archive_database_names = module.collect_archive_database_names( - repository='repo', + repository={'path': 'repo'}, archive='archive', location={'borgmatic_source_directory': '.borgmatic'}, storage=flexmock(), @@ -92,7 +92,7 @@ def test_collect_archive_database_names_parses_directory_format_archive_paths(): ) archive_database_names = module.collect_archive_database_names( - repository='repo', + repository={'path': 'repo'}, archive='archive', location={'borgmatic_source_directory': '.borgmatic'}, storage=flexmock(), @@ -113,7 +113,7 @@ def test_collect_archive_database_names_skips_bad_archive_paths(): ) archive_database_names = module.collect_archive_database_names( - repository='repo', + repository={'path': 'repo'}, archive='archive', location={'borgmatic_source_directory': '.borgmatic'}, storage=flexmock(), @@ -251,7 +251,7 @@ def test_run_restore_restores_each_database(): flexmock(module).should_receive('ensure_databases_found') module.run_restore( - repository='repo', + repository={'path': 'repo'}, location=flexmock(), storage=flexmock(), hooks=flexmock(), @@ -273,7 +273,7 @@ def test_run_restore_bails_for_non_matching_repository(): flexmock(module).should_receive('restore_single_database').never() module.run_restore( - repository='repo', + repository={'path': 'repo'}, location=flexmock(), storage=flexmock(), hooks=flexmock(), @@ -345,7 +345,7 @@ def test_run_restore_restores_database_configured_with_all_name(): flexmock(module).should_receive('ensure_databases_found') module.run_restore( - repository='repo', + repository={'path': 'repo'}, location=flexmock(), storage=flexmock(), hooks=flexmock(), @@ -417,7 +417,7 @@ def test_run_restore_skips_missing_database(): flexmock(module).should_receive('ensure_databases_found') module.run_restore( - repository='repo', + repository={'path': 'repo'}, location=flexmock(), storage=flexmock(), hooks=flexmock(), @@ -483,7 +483,7 @@ def test_run_restore_restores_databases_from_different_hooks(): flexmock(module).should_receive('ensure_databases_found') module.run_restore( - repository='repo', + repository={'path': 'repo'}, location=flexmock(), storage=flexmock(), hooks=flexmock(), diff --git a/tests/unit/actions/test_rinfo.py b/tests/unit/actions/test_rinfo.py index d789ef11..133e61ac 100644 --- a/tests/unit/actions/test_rinfo.py +++ b/tests/unit/actions/test_rinfo.py @@ -11,7 +11,7 @@ def test_run_rinfo_does_not_raise(): list( module.run_rinfo( - repository='repo', + repository={'path': 'repo'}, storage={}, local_borg_version=None, rinfo_arguments=rinfo_arguments, diff --git a/tests/unit/actions/test_rlist.py b/tests/unit/actions/test_rlist.py index 3da0f905..7f8b58aa 100644 --- a/tests/unit/actions/test_rlist.py +++ b/tests/unit/actions/test_rlist.py @@ -11,7 +11,7 @@ def test_run_rlist_does_not_raise(): list( module.run_rlist( - repository='repo', + repository={'path': 'repo'}, storage={}, local_borg_version=None, rlist_arguments=rlist_arguments, diff --git a/tests/unit/commands/test_borgmatic.py b/tests/unit/commands/test_borgmatic.py index 19ac00de..14e7443e 100644 --- a/tests/unit/commands/test_borgmatic.py +++ b/tests/unit/commands/test_borgmatic.py @@ -409,7 +409,7 @@ def test_run_actions_runs_rcreate(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) @@ -431,7 +431,7 @@ def test_run_actions_runs_transfer(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) @@ -454,7 +454,7 @@ def test_run_actions_runs_create(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) assert result == (expected,) @@ -477,7 +477,7 @@ def test_run_actions_runs_prune(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) @@ -499,7 +499,7 @@ def test_run_actions_runs_compact(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) @@ -522,7 +522,7 @@ def test_run_actions_runs_check_when_repository_enabled_for_checks(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) @@ -545,7 +545,7 @@ def test_run_actions_skips_check_when_repository_not_enabled_for_checks(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) @@ -567,7 +567,7 @@ def test_run_actions_runs_extract(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) @@ -589,7 +589,7 @@ def test_run_actions_runs_export_tar(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) @@ -611,7 +611,7 @@ def test_run_actions_runs_mount(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) @@ -633,7 +633,7 @@ def test_run_actions_runs_restore(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) @@ -656,7 +656,7 @@ def test_run_actions_runs_rlist(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) assert result == (expected,) @@ -680,7 +680,7 @@ def test_run_actions_runs_list(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) assert result == (expected,) @@ -704,7 +704,7 @@ def test_run_actions_runs_rinfo(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) assert result == (expected,) @@ -728,7 +728,7 @@ def test_run_actions_runs_info(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) assert result == (expected,) @@ -751,7 +751,7 @@ def test_run_actions_runs_break_lock(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) @@ -773,7 +773,7 @@ def test_run_actions_runs_borg(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) @@ -800,7 +800,7 @@ def test_run_actions_runs_multiple_actions_in_argument_order(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository_path='repo', + repository='repo', ) ) diff --git a/tests/unit/config/test_normalize.py b/tests/unit/config/test_normalize.py index 821c3202..ff67aa12 100644 --- a/tests/unit/config/test_normalize.py +++ b/tests/unit/config/test_normalize.py @@ -69,27 +69,27 @@ from borgmatic.config import normalize as module ), ( {'location': {'repositories': ['foo@bar:/repo']}}, - {'location': {'repositories': ['ssh://foo@bar/repo']}}, + {'location': {'repositories': [{'path': 'ssh://foo@bar/repo', 'label': ''}]}}, True, ), ( {'location': {'repositories': ['foo@bar:repo']}}, - {'location': {'repositories': ['ssh://foo@bar/./repo']}}, + {'location': {'repositories': [{'path': 'ssh://foo@bar/./repo', 'label': ''}]}}, True, ), ( {'location': {'repositories': ['foo@bar:~/repo']}}, - {'location': {'repositories': ['ssh://foo@bar/~/repo']}}, + {'location': {'repositories': [{'path': 'ssh://foo@bar/~/repo', 'label': ''}]}}, True, ), ( {'location': {'repositories': ['ssh://foo@bar:1234/repo']}}, - {'location': {'repositories': ['ssh://foo@bar:1234/repo']}}, + {'location': {'repositories': [{'path': 'ssh://foo@bar:1234/repo', 'label': ''}]}}, False, ), ( {'location': {'repositories': ['file:///repo']}}, - {'location': {'repositories': ['/repo']}}, + {'location': {'repositories': [{'path': '/repo', 'label': ''}]}}, False, ), ),