From 1bc7bb49714a33ac9613a2da10cc7951ccace276 Mon Sep 17 00:00:00 2001 From: Divyansh Singh Date: Mon, 15 May 2023 23:04:42 +0530 Subject: [PATCH] feat: store configs used to create an archive in the archive --- borgmatic/borg/create.py | 2 +- borgmatic/commands/borgmatic.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index e3b70eb5..284789d6 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -351,7 +351,7 @@ def create_archive( sources = deduplicate_directories( map_directories_to_devices( expand_directories( - tuple(location_config.get('source_directories', ())) + borgmatic_source_directories + tuple(location_config.get('source_directories', ())) + borgmatic_source_directories + tuple(global_arguments.config_paths) ) ), additional_directory_devices=map_directories_to_devices( diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 44396cd4..3afa625b 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -45,10 +45,10 @@ logger = logging.getLogger(__name__) LEGACY_CONFIG_PATH = '/etc/borgmatic/config' -def run_configuration(config_filename, config, arguments): +def run_configuration(config_filename, config, arguments, used_config_paths): ''' - Given a config filename, the corresponding parsed config dict, and command-line arguments as a - dict from subparser name to a namespace of parsed arguments, execute the defined create, prune, + Given a config filename, the corresponding parsed config dict, command-line arguments as a + dict from subparser name to a namespace of parsed arguments, and a list of paths of all configs used, execute the defined create, prune, compact, check, and/or other actions. Yield a combination of: @@ -61,6 +61,7 @@ def run_configuration(config_filename, config, arguments): for section_name in ('location', 'storage', 'retention', 'consistency', 'hooks') ) global_arguments = arguments['global'] + global_arguments.config_paths = used_config_paths local_path = location.get('local_path', 'borg') remote_path = location.get('remote_path') @@ -644,8 +645,9 @@ def collect_configuration_run_summary_logs(configs, arguments): # Execute the actions corresponding to each configuration file. json_results = [] + used_config_paths = list(configs.keys()) for config_filename, config in configs.items(): - results = list(run_configuration(config_filename, config, arguments)) + results = list(run_configuration(config_filename, config, arguments, used_config_paths)) error_logs = tuple(result for result in results if isinstance(result, logging.LogRecord)) if error_logs: