Partial conversion of showing repository labels in logs instead of paths (part of #635).

This commit is contained in:
Dan Helfman 2023-05-16 09:36:50 -07:00
parent ba845d4008
commit b45e45f161
16 changed files with 54 additions and 29 deletions

View file

@ -22,7 +22,9 @@ def run_borg(
if borg_arguments.repository is None or borgmatic.config.validate.repositories_match( if borg_arguments.repository is None or borgmatic.config.validate.repositories_match(
repository, borg_arguments.repository repository, borg_arguments.repository
): ):
logger.info(f'{repository["path"]}: Running arbitrary Borg command') logger.info(
f'{repository.get("label", repository["path"])}: Running arbitrary Borg command'
)
archive_name = borgmatic.borg.rlist.resolve_archive_name( archive_name = borgmatic.borg.rlist.resolve_archive_name(
repository['path'], repository['path'],
borg_arguments.archive, borg_arguments.archive,

View file

@ -21,7 +21,9 @@ def run_break_lock(
if break_lock_arguments.repository is None or borgmatic.config.validate.repositories_match( if break_lock_arguments.repository is None or borgmatic.config.validate.repositories_match(
repository, break_lock_arguments.repository repository, break_lock_arguments.repository
): ):
logger.info(f'{repository["path"]}: Breaking repository and cache locks') logger.info(
f'{repository.get("label", repository["path"])}: Breaking repository and cache locks'
)
borgmatic.borg.break_lock.break_lock( borgmatic.borg.break_lock.break_lock(
repository['path'], repository['path'],
storage, storage,

View file

@ -37,7 +37,7 @@ def run_check(
global_arguments.dry_run, global_arguments.dry_run,
**hook_context, **hook_context,
) )
logger.info(f'{repository["path"]}: Running consistency checks') logger.info(f'{repository.get("label", repository["path"])}: Running consistency checks')
borgmatic.borg.check.check_archives( borgmatic.borg.check.check_archives(
repository['path'], repository['path'],
location, location,

View file

@ -39,7 +39,9 @@ def run_compact(
**hook_context, **hook_context,
) )
if borgmatic.borg.feature.available(borgmatic.borg.feature.Feature.COMPACT, local_borg_version): if borgmatic.borg.feature.available(borgmatic.borg.feature.Feature.COMPACT, local_borg_version):
logger.info(f'{repository["path"]}: Compacting segments{dry_run_label}') logger.info(
f'{repository.get("label", repository["path"])}: Compacting segments{dry_run_label}'
)
borgmatic.borg.compact.compact_segments( borgmatic.borg.compact.compact_segments(
global_arguments.dry_run, global_arguments.dry_run,
repository['path'], repository['path'],
@ -53,7 +55,9 @@ def run_compact(
threshold=compact_arguments.threshold, threshold=compact_arguments.threshold,
) )
else: # pragma: nocover else: # pragma: nocover
logger.info(f'{repository["path"]}: Skipping compact (only available/needed in Borg 1.2+)') logger.info(
f'{repository.get("label", repository["path"])}: Skipping compact (only available/needed in Borg 1.2+)'
)
borgmatic.hooks.command.execute_hook( borgmatic.hooks.command.execute_hook(
hooks.get('after_compact'), hooks.get('after_compact'),
hooks.get('umask'), hooks.get('umask'),

View file

@ -42,7 +42,7 @@ def run_create(
global_arguments.dry_run, global_arguments.dry_run,
**hook_context, **hook_context,
) )
logger.info(f'{repository["path"]}: Creating archive{dry_run_label}') logger.info(f'{repository.get("label", repository["path"])}: Creating archive{dry_run_label}')
borgmatic.hooks.dispatch.call_hooks_even_if_unconfigured( borgmatic.hooks.dispatch.call_hooks_even_if_unconfigured(
'remove_database_dumps', 'remove_database_dumps',
hooks, hooks,

View file

@ -35,7 +35,9 @@ def run_extract(
if extract_arguments.repository is None or borgmatic.config.validate.repositories_match( if extract_arguments.repository is None or borgmatic.config.validate.repositories_match(
repository, extract_arguments.repository repository, extract_arguments.repository
): ):
logger.info(f'{repository["path"]}: Extracting archive {extract_arguments.archive}') logger.info(
f'{repository.get("label", repository["path"])}: Extracting archive {extract_arguments.archive}'
)
borgmatic.borg.extract.extract_archive( borgmatic.borg.extract.extract_archive(
global_arguments.dry_run, global_arguments.dry_run,
repository['path'], repository['path'],

View file

@ -26,7 +26,9 @@ def run_info(
repository, info_arguments.repository repository, info_arguments.repository
): ):
if not info_arguments.json: # pragma: nocover if not info_arguments.json: # pragma: nocover
logger.answer(f'{repository["path"]}: Displaying archive summary information') logger.answer(
f'{repository.get("label", repository["path"])}: Displaying archive summary information'
)
info_arguments.archive = borgmatic.borg.rlist.resolve_archive_name( info_arguments.archive = borgmatic.borg.rlist.resolve_archive_name(
repository['path'], repository['path'],
info_arguments.archive, info_arguments.archive,

View file

@ -26,9 +26,9 @@ def run_list(
): ):
if not list_arguments.json: # pragma: nocover if not list_arguments.json: # pragma: nocover
if list_arguments.find_paths: if list_arguments.find_paths:
logger.answer(f'{repository["path"]}: Searching archives') logger.answer(f'{repository.get("label", repository["path"])}: Searching archives')
elif not list_arguments.archive: elif not list_arguments.archive:
logger.answer(f'{repository["path"]}: Listing archives') logger.answer(f'{repository.get("label", repository["path"])}: Listing archives')
list_arguments.archive = borgmatic.borg.rlist.resolve_archive_name( list_arguments.archive = borgmatic.borg.rlist.resolve_archive_name(
repository['path'], repository['path'],
list_arguments.archive, list_arguments.archive,

View file

@ -23,9 +23,11 @@ def run_mount(
repository, mount_arguments.repository repository, mount_arguments.repository
): ):
if mount_arguments.archive: if mount_arguments.archive:
logger.info(f'{repository["path"]}: Mounting archive {mount_arguments.archive}') logger.info(
f'{repository.get("label", repository["path"])}: Mounting archive {mount_arguments.archive}'
)
else: # pragma: nocover else: # pragma: nocover
logger.info(f'{repository["path"]}: Mounting repository') logger.info(f'{repository.get("label", repository["path"])}: Mounting repository')
borgmatic.borg.mount.mount_archive( borgmatic.borg.mount.mount_archive(
repository['path'], repository['path'],

View file

@ -37,7 +37,7 @@ def run_prune(
global_arguments.dry_run, global_arguments.dry_run,
**hook_context, **hook_context,
) )
logger.info(f'{repository["path"]}: Pruning archives{dry_run_label}') logger.info(f'{repository.get("label", repository["path"])}: Pruning archives{dry_run_label}')
borgmatic.borg.prune.prune_archives( borgmatic.borg.prune.prune_archives(
global_arguments.dry_run, global_arguments.dry_run,
repository['path'], repository['path'],

View file

@ -23,7 +23,7 @@ def run_rcreate(
): ):
return return
logger.info(f'{repository["path"]}: Creating repository') logger.info(f'{repository.get("label", repository["path"])}: Creating repository')
borgmatic.borg.rcreate.create_repository( borgmatic.borg.rcreate.create_repository(
global_arguments.dry_run, global_arguments.dry_run,
repository['path'], repository['path'],

View file

@ -73,12 +73,14 @@ def restore_single_database(
Given (among other things) an archive name, a database hook name, and a configured database Given (among other things) an archive name, a database hook name, and a configured database
configuration dict, restore that database from the archive. configuration dict, restore that database from the archive.
''' '''
logger.info(f'{repository}: Restoring database {database["name"]}') logger.info(
f'{repository.get("label", repository["path"])}: Restoring database {database["name"]}'
)
dump_pattern = borgmatic.hooks.dispatch.call_hooks( dump_pattern = borgmatic.hooks.dispatch.call_hooks(
'make_database_dump_pattern', 'make_database_dump_pattern',
hooks, hooks,
repository, repository['path'],
borgmatic.hooks.dump.DATABASE_HOOK_NAMES, borgmatic.hooks.dump.DATABASE_HOOK_NAMES,
location, location,
database['name'], database['name'],
@ -87,7 +89,7 @@ def restore_single_database(
# Kick off a single database extract to stdout. # Kick off a single database extract to stdout.
extract_process = borgmatic.borg.extract.extract_archive( extract_process = borgmatic.borg.extract.extract_archive(
dry_run=global_arguments.dry_run, dry_run=global_arguments.dry_run,
repository=repository, repository=repository['path'],
archive=archive_name, archive=archive_name,
paths=borgmatic.hooks.dump.convert_glob_patterns_to_borg_patterns([dump_pattern]), paths=borgmatic.hooks.dump.convert_glob_patterns_to_borg_patterns([dump_pattern]),
location_config=location, location_config=location,
@ -106,7 +108,7 @@ def restore_single_database(
borgmatic.hooks.dispatch.call_hooks( borgmatic.hooks.dispatch.call_hooks(
'restore_database_dump', 'restore_database_dump',
{hook_name: [database]}, {hook_name: [database]},
repository, repository['path'],
borgmatic.hooks.dump.DATABASE_HOOK_NAMES, borgmatic.hooks.dump.DATABASE_HOOK_NAMES,
location, location,
global_arguments.dry_run, global_arguments.dry_run,
@ -265,7 +267,7 @@ def run_restore(
return return
logger.info( logger.info(
f'{repository["path"]}: Restoring databases from archive {restore_arguments.archive}' f'{repository.get("label", repository["path"])}: Restoring databases from archive {restore_arguments.archive}'
) )
borgmatic.hooks.dispatch.call_hooks_even_if_unconfigured( borgmatic.hooks.dispatch.call_hooks_even_if_unconfigured(
@ -314,7 +316,7 @@ def run_restore(
found_names.add(database_name) found_names.add(database_name)
restore_single_database( restore_single_database(
repository['path'], repository,
location, location,
storage, storage,
hooks, hooks,
@ -343,7 +345,7 @@ def run_restore(
database['name'] = database_name database['name'] = database_name
restore_single_database( restore_single_database(
repository['path'], repository,
location, location,
storage, storage,
hooks, hooks,

View file

@ -25,7 +25,9 @@ def run_rinfo(
repository, rinfo_arguments.repository repository, rinfo_arguments.repository
): ):
if not rinfo_arguments.json: # pragma: nocover if not rinfo_arguments.json: # pragma: nocover
logger.answer(f'{repository["path"]}: Displaying repository summary information') logger.answer(
f'{repository.get("label", repository["path"])}: Displaying repository summary information'
)
json_output = borgmatic.borg.rinfo.display_repository_info( json_output = borgmatic.borg.rinfo.display_repository_info(
repository['path'], repository['path'],

View file

@ -25,7 +25,7 @@ def run_rlist(
repository, rlist_arguments.repository repository, rlist_arguments.repository
): ):
if not rlist_arguments.json: # pragma: nocover if not rlist_arguments.json: # pragma: nocover
logger.answer(f'{repository["path"]}: Listing repository') logger.answer(f'{repository.get("label", repository["path"])}: Listing repository')
json_output = borgmatic.borg.rlist.list_repository( json_output = borgmatic.borg.rlist.list_repository(
repository['path'], repository['path'],

View file

@ -17,7 +17,9 @@ def run_transfer(
''' '''
Run the "transfer" action for the given repository. Run the "transfer" action for the given repository.
''' '''
logger.info(f'{repository["path"]}: Transferring archives to repository') logger.info(
f'{repository.get("label", repository["path"])}: Transferring archives to repository'
)
borgmatic.borg.transfer.transfer_archives( borgmatic.borg.transfer.transfer_archives(
global_arguments.dry_run, global_arguments.dry_run,
repository['path'], repository['path'],

View file

@ -113,10 +113,14 @@ def run_configuration(config_filename, config, arguments):
while not repo_queue.empty(): while not repo_queue.empty():
repository, retry_num = repo_queue.get() repository, retry_num = repo_queue.get()
logger.debug(f'{repository["path"]}: Running actions for repository') logger.debug(
f'{repository.get("label", repository["path"])}: Running actions for repository'
)
timeout = retry_num * retry_wait timeout = retry_num * retry_wait
if timeout: if timeout:
logger.warning(f'{config_filename}: Sleeping {timeout}s before next retry') logger.warning(
f'{repository.get("label", repository["path"])}: Sleeping {timeout}s before next retry'
)
time.sleep(timeout) time.sleep(timeout)
try: try:
yield from run_actions( yield from run_actions(
@ -139,14 +143,14 @@ def run_configuration(config_filename, config, arguments):
) )
tuple( # Consume the generator so as to trigger logging. tuple( # Consume the generator so as to trigger logging.
log_error_records( log_error_records(
f'{repository["path"]}: Error running actions for repository', f'{repository.get("label", repository["path"])}: Error running actions for repository',
error, error,
levelno=logging.WARNING, levelno=logging.WARNING,
log_command_error_output=True, log_command_error_output=True,
) )
) )
logger.warning( logger.warning(
f'{config_filename}: Retrying... attempt {retry_num + 1}/{retries}' f'{repository.get("label", repository["path"])}: Retrying... attempt {retry_num + 1}/{retries}'
) )
continue continue
@ -154,7 +158,8 @@ def run_configuration(config_filename, config, arguments):
return return
yield from log_error_records( yield from log_error_records(
f'{repository["path"]}: Error running actions for repository', error f'{repository.get("label", repository["path"])}: Error running actions for repository',
error,
) )
encountered_error = error encountered_error = error
error_repository = repository['path'] error_repository = repository['path']