diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 2c23ad0e..68f416b2 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -286,6 +286,7 @@ def run_actions( global_arguments = arguments['global'] dry_run_label = ' (dry run; not making any changes)' if global_arguments.dry_run else '' hook_context = { + 'repository_label': repository.get('label', ''), 'repository': repository_path, # Deprecated: For backwards compatibility with borgmatic < 1.6.0. 'repositories': ','.join([repo['path'] for repo in config['repositories']]), diff --git a/docs/how-to/add-preparation-and-cleanup-steps-to-backups.md b/docs/how-to/add-preparation-and-cleanup-steps-to-backups.md index 2c71a415..1d05c0d9 100644 --- a/docs/how-to/add-preparation-and-cleanup-steps-to-backups.md +++ b/docs/how-to/add-preparation-and-cleanup-steps-to-backups.md @@ -84,6 +84,8 @@ variables you can use here: path of the borgmatic log file, only set when the `--log-file` flag is used * `repository`: path of the current repository as configured in the current borgmatic configuration file + * `repository_label`: current repository label as configured in the current + borgmatic configuration file Note that you can also interpolate in [arbitrary environment variables](https://torsion.org/borgmatic/docs/how-to/provide-your-passwords/). diff --git a/tests/unit/commands/test_borgmatic.py b/tests/unit/commands/test_borgmatic.py index 911e2add..b0b6a153 100644 --- a/tests/unit/commands/test_borgmatic.py +++ b/tests/unit/commands/test_borgmatic.py @@ -494,10 +494,15 @@ def test_run_actions_adds_log_file_to_hook_context(): expected = flexmock() flexmock(borgmatic.actions.create).should_receive('run_create').with_args( config_filename=object, - repository={'path': 'repo'}, + repository={'path': 'repo', 'label': ''}, config={'repositories': []}, config_paths=[], - hook_context={'repository': 'repo', 'repositories': '', 'log_file': 'foo'}, + hook_context={ + 'repository': 'repo', + 'repository_label': '', + 'repositories': '', + 'log_file': 'foo', + }, local_borg_version=object, create_arguments=object, global_arguments=object, @@ -515,7 +520,7 @@ def test_run_actions_adds_log_file_to_hook_context(): local_path=flexmock(), remote_path=flexmock(), local_borg_version=flexmock(), - repository={'path': 'repo'}, + repository={'path': 'repo', 'label': ''}, ) ) assert result == (expected,)