mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-07-22 02:03:01 +02:00
For the "recreate" action, actually pass the "--dry-run" flag through to Borg instead of just skipping the Borg call (#1241).
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
2.1.1.dev0
|
||||
* #1241: For the "recreate" action, actually pass the "--dry-run" flag through to Borg instead of
|
||||
just skipping the Borg call.
|
||||
|
||||
2.1.0
|
||||
* TL;DR: Many logging, memory, and performance improvements. Mind those breaking changes!
|
||||
* #485: When running commands (database clients, command hooks, etc.), elevate stderr output to
|
||||
|
||||
@@ -18,6 +18,7 @@ def run_recreate(
|
||||
local_borg_version,
|
||||
recreate_arguments,
|
||||
global_arguments,
|
||||
dry_run_label,
|
||||
local_path,
|
||||
remote_path,
|
||||
):
|
||||
@@ -25,9 +26,9 @@ def run_recreate(
|
||||
Run the "recreate" action for the given repository.
|
||||
'''
|
||||
if recreate_arguments.archive:
|
||||
logger.answer(f'Recreating archive {recreate_arguments.archive}')
|
||||
logger.answer(f'Recreating archive {recreate_arguments.archive}{dry_run_label}')
|
||||
else:
|
||||
logger.answer('Recreating repository')
|
||||
logger.answer(f'Recreating repository{dry_run_label}')
|
||||
|
||||
# Collect and process patterns.
|
||||
processed_patterns = borgmatic.actions.pattern.process_patterns(
|
||||
|
||||
@@ -72,6 +72,7 @@ def recreate_archive(
|
||||
+ (('--chunker-params', chunker_params) if chunker_params else ())
|
||||
+ (('--recompress', recompress) if recompress else ())
|
||||
+ exclude_flags
|
||||
+ (('--dry-run',) if global_arguments.dry_run else ())
|
||||
+ (tuple(shlex.split(extra_borg_options)) if extra_borg_options else ())
|
||||
+ (
|
||||
(
|
||||
@@ -94,10 +95,6 @@ def recreate_archive(
|
||||
)
|
||||
)
|
||||
|
||||
if global_arguments.dry_run:
|
||||
logger.info('Skipping the archive recreation (dry run)')
|
||||
return
|
||||
|
||||
borgmatic.execute.execute_command(
|
||||
full_command=recreate_command,
|
||||
output_log_level=logging.INFO,
|
||||
|
||||
@@ -441,6 +441,7 @@ def run_actions( # noqa: PLR0912, PLR0915
|
||||
local_borg_version,
|
||||
action_arguments,
|
||||
global_arguments,
|
||||
dry_run_label,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
|
||||
@@ -39,7 +39,7 @@ def bash_completion():
|
||||
'check_version() {',
|
||||
' local this_script="$(cat "$BASH_SOURCE" 2> /dev/null)"',
|
||||
' local installed_script="$(borgmatic --bash-completion 2> /dev/null)"',
|
||||
' if [ "$this_script" != "$installed_script" ] && [ "$installed_script" != "" ];'
|
||||
' if [ "$this_script" != "$installed_script" ] && [ "$installed_script" != "" ];' # noqa: ISC004
|
||||
f''' then cat << EOF\n{borgmatic.commands.completion.actions.upgrade_message(
|
||||
'bash',
|
||||
'sudo sh -c "borgmatic --bash-completion > $BASH_SOURCE"',
|
||||
|
||||
@@ -60,7 +60,7 @@ follows:
|
||||
unsafe_skip_path_validation_before_create: true
|
||||
```
|
||||
|
||||
However, this is indeed unsafe, and could lead to hangs or data being left out
|
||||
However, this is indeed unsafe and could lead to hangs or data being left out
|
||||
of backups. Use this option at your own risk.
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "borgmatic"
|
||||
version = "2.1.0"
|
||||
version = "2.1.1.dev0"
|
||||
authors = [
|
||||
{ name="Dan Helfman", email="witten@torsion.org" },
|
||||
]
|
||||
|
||||
@@ -22,6 +22,7 @@ def test_run_recreate_does_not_raise():
|
||||
local_borg_version=None,
|
||||
recreate_arguments=flexmock(repository=flexmock(), archive=None),
|
||||
global_arguments=flexmock(),
|
||||
dry_run_label='',
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
@@ -45,6 +46,7 @@ def test_run_recreate_with_archive_does_not_raise():
|
||||
local_borg_version=None,
|
||||
recreate_arguments=flexmock(repository=flexmock(), archive='test-archive'),
|
||||
global_arguments=flexmock(),
|
||||
dry_run_label='',
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
@@ -69,6 +71,7 @@ def test_run_recreate_with_leftover_recreate_archive_raises():
|
||||
local_borg_version=None,
|
||||
recreate_arguments=flexmock(repository=flexmock(), archive='test-archive.recreate'),
|
||||
global_arguments=flexmock(),
|
||||
dry_run_label='',
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
@@ -93,6 +96,7 @@ def test_run_recreate_with_latest_archive_resolving_to_leftover_recreate_archive
|
||||
local_borg_version=None,
|
||||
recreate_arguments=flexmock(repository=flexmock(), archive='latest'),
|
||||
global_arguments=flexmock(),
|
||||
dry_run_label='',
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
@@ -122,6 +126,7 @@ def test_run_recreate_with_archive_already_exists_error_raises():
|
||||
local_borg_version=None,
|
||||
recreate_arguments=flexmock(repository=flexmock(), archive='test-archive', target=None),
|
||||
global_arguments=flexmock(),
|
||||
dry_run_label='',
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
@@ -155,6 +160,7 @@ def test_run_recreate_with_target_and_archive_already_exists_error_raises():
|
||||
target='target-archive',
|
||||
),
|
||||
global_arguments=flexmock(),
|
||||
dry_run_label='',
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
@@ -188,6 +194,7 @@ def test_run_recreate_with_other_called_process_error_passes_it_through():
|
||||
target='target-archive',
|
||||
),
|
||||
global_arguments=flexmock(),
|
||||
dry_run_label='',
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
@@ -20,44 +20,6 @@ def insert_execute_command_mock(command, working_directory=None, borg_exit_codes
|
||||
).once()
|
||||
|
||||
|
||||
def test_recreate_archive_dry_run_skips_execution():
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_exclude_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.pattern).should_receive('write_patterns_file').and_return(None)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_list_filter_flags').and_return('')
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive(
|
||||
'make_repository_archive_flags',
|
||||
).and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
),
|
||||
)
|
||||
flexmock(module.borgmatic.execute).should_receive('execute_command').never()
|
||||
|
||||
recreate_arguments = flexmock(
|
||||
repository=flexmock(),
|
||||
list=None,
|
||||
target=None,
|
||||
comment=None,
|
||||
timestamp=None,
|
||||
match_archives=None,
|
||||
)
|
||||
|
||||
result = module.recreate_archive(
|
||||
repository='repo',
|
||||
archive='archive',
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
recreate_arguments=recreate_arguments,
|
||||
global_arguments=flexmock(dry_run=True),
|
||||
local_path='borg',
|
||||
)
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
def test_recreate_calls_borg_with_required_flags():
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_exclude_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.pattern).should_receive('write_patterns_file').and_return(None)
|
||||
@@ -93,6 +55,41 @@ def test_recreate_calls_borg_with_required_flags():
|
||||
)
|
||||
|
||||
|
||||
def test_recreate_with_dry_run_calls_borg_with_dry_run_flag():
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_exclude_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.pattern).should_receive('write_patterns_file').and_return(None)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_list_filter_flags').and_return('')
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive(
|
||||
'make_repository_archive_flags',
|
||||
).and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'recreate', '--log-json', '--dry-run', '--repo', 'repo'))
|
||||
|
||||
module.recreate_archive(
|
||||
repository='repo',
|
||||
archive='archive',
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
recreate_arguments=flexmock(
|
||||
list=None,
|
||||
target=None,
|
||||
comment=None,
|
||||
timestamp=None,
|
||||
match_archives=None,
|
||||
),
|
||||
global_arguments=flexmock(dry_run=True),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
patterns=None,
|
||||
)
|
||||
|
||||
|
||||
def test_recreate_with_remote_path():
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_exclude_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.pattern).should_receive('write_patterns_file').and_return(None)
|
||||
|
||||
Reference in New Issue
Block a user