diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index a882531..a6df97b 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -91,6 +91,14 @@ def run_configuration(config_filename, config, arguments): 'pre-check', global_arguments.dry_run, ) + if 'extract' in arguments: + command.execute_hook( + hooks.get('before_extract'), + hooks.get('umask'), + config_filename, + 'pre-extract', + global_arguments.dry_run, + ) if prune_create_or_check: dispatch.call_hooks( 'ping_monitor', @@ -165,6 +173,14 @@ def run_configuration(config_filename, config, arguments): 'post-check', global_arguments.dry_run, ) + if 'extract' in arguments: + command.execute_hook( + hooks.get('after_extract'), + hooks.get('umask'), + config_filename, + 'post-extract', + global_arguments.dry_run, + ) if prune_create_or_check: dispatch.call_hooks( 'ping_monitor', diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index 71742b4..9e16704 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -473,6 +473,14 @@ map: before consistency checks, run once per configuration file. example: - echo "Starting checks." + before_extract: + seq: + - type: str + desc: | + List of one or more shell commands or scripts to execute + before extracting a backup, run once per configuration file. + example: + - echo "Starting extracting." after_backup: seq: - type: str @@ -497,6 +505,14 @@ map: after consistency checks, run once per configuration file. example: - echo "Finished checks." + after_extract: + seq: + - type: str + desc: | + List of one or more shell commands or scripts to execute + after extracting a backup, run once per configuration file. + example: + - echo "Finished extracting." on_error: seq: - type: str diff --git a/tests/unit/commands/test_borgmatic.py b/tests/unit/commands/test_borgmatic.py index 3ecf8c2..e9453d2 100644 --- a/tests/unit/commands/test_borgmatic.py +++ b/tests/unit/commands/test_borgmatic.py @@ -54,6 +54,17 @@ def test_run_configuration_calls_hooks_for_check_action(): list(module.run_configuration('test.yaml', config, arguments)) +def test_run_configuration_calls_hooks_for_extract_action(): + flexmock(module.borg_environment).should_receive('initialize') + flexmock(module.command).should_receive('execute_hook').twice() + flexmock(module.dispatch).should_receive('call_hooks').never() + flexmock(module).should_receive('run_actions').and_return([]) + config = {'location': {'repositories': ['foo']}} + arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'extract': flexmock()} + + list(module.run_configuration('test.yaml', config, arguments)) + + def test_run_configuration_does_not_trigger_hooks_for_list_action(): flexmock(module.borg_environment).should_receive('initialize') flexmock(module.command).should_receive('execute_hook').never()