Fix all database hooks to error when the requested database to restore isn't present in the Borg archive (#560).
This commit is contained in:
parent
2b23a63a08
commit
e85d551eac
8 changed files with 13 additions and 21 deletions
2
NEWS
2
NEWS
|
@ -1,5 +1,7 @@
|
||||||
1.6.6.dev0
|
1.6.6.dev0
|
||||||
* #559: Update documentation about configuring multiple consistency checks or multiple databases.
|
* #559: Update documentation about configuring multiple consistency checks or multiple databases.
|
||||||
|
* #560: Fix all database hooks to error when the requested database to restore isn't present in the
|
||||||
|
Borg archive.
|
||||||
* #561: Fix command-line "--override" flag to continue supporting old configuration file formats.
|
* #561: Fix command-line "--override" flag to continue supporting old configuration file formats.
|
||||||
|
|
||||||
1.6.5
|
1.6.5
|
||||||
|
|
|
@ -137,8 +137,8 @@ def extract_archive(
|
||||||
extra_environment=borg_environment,
|
extra_environment=borg_environment,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Don't give Borg local path, so as to error on warnings, as Borg only gives a warning if the
|
# Don't give Borg local path so as to error on warnings, as "borg extract" only gives a warning
|
||||||
# restore paths don't exist in the archive!
|
# if the restore paths don't exist in the archive.
|
||||||
execute_command(
|
execute_command(
|
||||||
full_command, working_directory=destination_path, extra_environment=borg_environment
|
full_command, working_directory=destination_path, extra_environment=borg_environment
|
||||||
)
|
)
|
||||||
|
|
|
@ -131,12 +131,13 @@ def restore_database_dump(database_config, log_prefix, location_config, dry_run,
|
||||||
if dry_run:
|
if dry_run:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Don't give Borg local path so as to error on warnings, as "borg extract" only gives a warning
|
||||||
|
# if the restore paths don't exist in the archive.
|
||||||
execute_command_with_processes(
|
execute_command_with_processes(
|
||||||
restore_command,
|
restore_command,
|
||||||
[extract_process] if extract_process else [],
|
[extract_process] if extract_process else [],
|
||||||
output_log_level=logging.DEBUG,
|
output_log_level=logging.DEBUG,
|
||||||
input_file=extract_process.stdout if extract_process else None,
|
input_file=extract_process.stdout if extract_process else None,
|
||||||
borg_local_path=location_config.get('local_path', 'borg'),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -166,11 +166,12 @@ def restore_database_dump(database_config, log_prefix, location_config, dry_run,
|
||||||
if dry_run:
|
if dry_run:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Don't give Borg local path so as to error on warnings, as "borg extract" only gives a warning
|
||||||
|
# if the restore paths don't exist in the archive.
|
||||||
execute_command_with_processes(
|
execute_command_with_processes(
|
||||||
restore_command,
|
restore_command,
|
||||||
[extract_process],
|
[extract_process],
|
||||||
output_log_level=logging.DEBUG,
|
output_log_level=logging.DEBUG,
|
||||||
input_file=extract_process.stdout,
|
input_file=extract_process.stdout,
|
||||||
extra_environment=extra_environment,
|
extra_environment=extra_environment,
|
||||||
borg_local_path=location_config.get('local_path', 'borg'),
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -168,12 +168,13 @@ def restore_database_dump(database_config, log_prefix, location_config, dry_run,
|
||||||
if dry_run:
|
if dry_run:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Don't give Borg local path so as to error on warnings, as "borg extract" only gives a warning
|
||||||
|
# if the restore paths don't exist in the archive.
|
||||||
execute_command_with_processes(
|
execute_command_with_processes(
|
||||||
restore_command,
|
restore_command,
|
||||||
[extract_process] if extract_process else [],
|
[extract_process] if extract_process else [],
|
||||||
output_log_level=logging.DEBUG,
|
output_log_level=logging.DEBUG,
|
||||||
input_file=extract_process.stdout if extract_process else None,
|
input_file=extract_process.stdout if extract_process else None,
|
||||||
extra_environment=extra_environment,
|
extra_environment=extra_environment,
|
||||||
borg_local_path=location_config.get('local_path', 'borg'),
|
|
||||||
)
|
)
|
||||||
execute_command(analyze_command, extra_environment=extra_environment)
|
execute_command(analyze_command, extra_environment=extra_environment)
|
||||||
|
|
|
@ -159,7 +159,7 @@ def test_dump_databases_runs_mongodumpall_for_all_databases():
|
||||||
assert module.dump_databases(databases, 'test.yaml', {}, dry_run=False) == [process]
|
assert module.dump_databases(databases, 'test.yaml', {}, dry_run=False) == [process]
|
||||||
|
|
||||||
|
|
||||||
def test_restore_database_dump_runs_pg_restore():
|
def test_restore_database_dump_runs_mongorestore():
|
||||||
database_config = [{'name': 'foo'}]
|
database_config = [{'name': 'foo'}]
|
||||||
extract_process = flexmock(stdout=flexmock())
|
extract_process = flexmock(stdout=flexmock())
|
||||||
|
|
||||||
|
@ -170,7 +170,6 @@ def test_restore_database_dump_runs_pg_restore():
|
||||||
processes=[extract_process],
|
processes=[extract_process],
|
||||||
output_log_level=logging.DEBUG,
|
output_log_level=logging.DEBUG,
|
||||||
input_file=extract_process.stdout,
|
input_file=extract_process.stdout,
|
||||||
borg_local_path='borg',
|
|
||||||
).once()
|
).once()
|
||||||
|
|
||||||
module.restore_database_dump(
|
module.restore_database_dump(
|
||||||
|
@ -192,7 +191,7 @@ def test_restore_database_dump_errors_on_multiple_database_config():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_restore_database_dump_runs_pg_restore_with_hostname_and_port():
|
def test_restore_database_dump_runs_mongorestore_with_hostname_and_port():
|
||||||
database_config = [{'name': 'foo', 'hostname': 'database.example.org', 'port': 5433}]
|
database_config = [{'name': 'foo', 'hostname': 'database.example.org', 'port': 5433}]
|
||||||
extract_process = flexmock(stdout=flexmock())
|
extract_process = flexmock(stdout=flexmock())
|
||||||
|
|
||||||
|
@ -213,7 +212,6 @@ def test_restore_database_dump_runs_pg_restore_with_hostname_and_port():
|
||||||
processes=[extract_process],
|
processes=[extract_process],
|
||||||
output_log_level=logging.DEBUG,
|
output_log_level=logging.DEBUG,
|
||||||
input_file=extract_process.stdout,
|
input_file=extract_process.stdout,
|
||||||
borg_local_path='borg',
|
|
||||||
).once()
|
).once()
|
||||||
|
|
||||||
module.restore_database_dump(
|
module.restore_database_dump(
|
||||||
|
@ -221,7 +219,7 @@ def test_restore_database_dump_runs_pg_restore_with_hostname_and_port():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_restore_database_dump_runs_pg_restore_with_username_and_password():
|
def test_restore_database_dump_runs_mongorestore_with_username_and_password():
|
||||||
database_config = [
|
database_config = [
|
||||||
{
|
{
|
||||||
'name': 'foo',
|
'name': 'foo',
|
||||||
|
@ -251,7 +249,6 @@ def test_restore_database_dump_runs_pg_restore_with_username_and_password():
|
||||||
processes=[extract_process],
|
processes=[extract_process],
|
||||||
output_log_level=logging.DEBUG,
|
output_log_level=logging.DEBUG,
|
||||||
input_file=extract_process.stdout,
|
input_file=extract_process.stdout,
|
||||||
borg_local_path='borg',
|
|
||||||
).once()
|
).once()
|
||||||
|
|
||||||
module.restore_database_dump(
|
module.restore_database_dump(
|
||||||
|
@ -270,7 +267,6 @@ def test_restore_database_dump_runs_psql_for_all_database_dump():
|
||||||
processes=[extract_process],
|
processes=[extract_process],
|
||||||
output_log_level=logging.DEBUG,
|
output_log_level=logging.DEBUG,
|
||||||
input_file=extract_process.stdout,
|
input_file=extract_process.stdout,
|
||||||
borg_local_path='borg',
|
|
||||||
).once()
|
).once()
|
||||||
|
|
||||||
module.restore_database_dump(
|
module.restore_database_dump(
|
||||||
|
@ -300,7 +296,6 @@ def test_restore_database_dump_without_extract_process_restores_from_disk():
|
||||||
processes=[],
|
processes=[],
|
||||||
output_log_level=logging.DEBUG,
|
output_log_level=logging.DEBUG,
|
||||||
input_file=None,
|
input_file=None,
|
||||||
borg_local_path='borg',
|
|
||||||
).once()
|
).once()
|
||||||
|
|
||||||
module.restore_database_dump(
|
module.restore_database_dump(
|
||||||
|
|
|
@ -239,7 +239,6 @@ def test_restore_database_dump_runs_mysql_to_restore():
|
||||||
output_log_level=logging.DEBUG,
|
output_log_level=logging.DEBUG,
|
||||||
input_file=extract_process.stdout,
|
input_file=extract_process.stdout,
|
||||||
extra_environment=None,
|
extra_environment=None,
|
||||||
borg_local_path='borg',
|
|
||||||
).once()
|
).once()
|
||||||
|
|
||||||
module.restore_database_dump(
|
module.restore_database_dump(
|
||||||
|
@ -278,7 +277,6 @@ def test_restore_database_dump_runs_mysql_with_hostname_and_port():
|
||||||
output_log_level=logging.DEBUG,
|
output_log_level=logging.DEBUG,
|
||||||
input_file=extract_process.stdout,
|
input_file=extract_process.stdout,
|
||||||
extra_environment=None,
|
extra_environment=None,
|
||||||
borg_local_path='borg',
|
|
||||||
).once()
|
).once()
|
||||||
|
|
||||||
module.restore_database_dump(
|
module.restore_database_dump(
|
||||||
|
@ -296,7 +294,6 @@ def test_restore_database_dump_runs_mysql_with_username_and_password():
|
||||||
output_log_level=logging.DEBUG,
|
output_log_level=logging.DEBUG,
|
||||||
input_file=extract_process.stdout,
|
input_file=extract_process.stdout,
|
||||||
extra_environment={'MYSQL_PWD': 'trustsome1'},
|
extra_environment={'MYSQL_PWD': 'trustsome1'},
|
||||||
borg_local_path='borg',
|
|
||||||
).once()
|
).once()
|
||||||
|
|
||||||
module.restore_database_dump(
|
module.restore_database_dump(
|
||||||
|
|
|
@ -244,7 +244,6 @@ def test_restore_database_dump_runs_pg_restore():
|
||||||
output_log_level=logging.DEBUG,
|
output_log_level=logging.DEBUG,
|
||||||
input_file=extract_process.stdout,
|
input_file=extract_process.stdout,
|
||||||
extra_environment={'PGSSLMODE': 'disable'},
|
extra_environment={'PGSSLMODE': 'disable'},
|
||||||
borg_local_path='borg',
|
|
||||||
).once()
|
).once()
|
||||||
flexmock(module).should_receive('execute_command').with_args(
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
('psql', '--no-password', '--quiet', '--dbname', 'foo', '--command', 'ANALYZE'),
|
('psql', '--no-password', '--quiet', '--dbname', 'foo', '--command', 'ANALYZE'),
|
||||||
|
@ -296,7 +295,6 @@ def test_restore_database_dump_runs_pg_restore_with_hostname_and_port():
|
||||||
output_log_level=logging.DEBUG,
|
output_log_level=logging.DEBUG,
|
||||||
input_file=extract_process.stdout,
|
input_file=extract_process.stdout,
|
||||||
extra_environment={'PGSSLMODE': 'disable'},
|
extra_environment={'PGSSLMODE': 'disable'},
|
||||||
borg_local_path='borg',
|
|
||||||
).once()
|
).once()
|
||||||
flexmock(module).should_receive('execute_command').with_args(
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
(
|
(
|
||||||
|
@ -345,7 +343,6 @@ def test_restore_database_dump_runs_pg_restore_with_username_and_password():
|
||||||
output_log_level=logging.DEBUG,
|
output_log_level=logging.DEBUG,
|
||||||
input_file=extract_process.stdout,
|
input_file=extract_process.stdout,
|
||||||
extra_environment={'PGPASSWORD': 'trustsome1', 'PGSSLMODE': 'disable'},
|
extra_environment={'PGPASSWORD': 'trustsome1', 'PGSSLMODE': 'disable'},
|
||||||
borg_local_path='borg',
|
|
||||||
).once()
|
).once()
|
||||||
flexmock(module).should_receive('execute_command').with_args(
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
(
|
(
|
||||||
|
@ -380,7 +377,6 @@ def test_restore_database_dump_runs_psql_for_all_database_dump():
|
||||||
output_log_level=logging.DEBUG,
|
output_log_level=logging.DEBUG,
|
||||||
input_file=extract_process.stdout,
|
input_file=extract_process.stdout,
|
||||||
extra_environment={'PGSSLMODE': 'disable'},
|
extra_environment={'PGSSLMODE': 'disable'},
|
||||||
borg_local_path='borg',
|
|
||||||
).once()
|
).once()
|
||||||
flexmock(module).should_receive('execute_command').with_args(
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
('psql', '--no-password', '--quiet', '--command', 'ANALYZE'),
|
('psql', '--no-password', '--quiet', '--command', 'ANALYZE'),
|
||||||
|
@ -426,7 +422,6 @@ def test_restore_database_dump_without_extract_process_restores_from_disk():
|
||||||
output_log_level=logging.DEBUG,
|
output_log_level=logging.DEBUG,
|
||||||
input_file=None,
|
input_file=None,
|
||||||
extra_environment={'PGSSLMODE': 'disable'},
|
extra_environment={'PGSSLMODE': 'disable'},
|
||||||
borg_local_path='borg',
|
|
||||||
).once()
|
).once()
|
||||||
flexmock(module).should_receive('execute_command').with_args(
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
('psql', '--no-password', '--quiet', '--dbname', 'foo', '--command', 'ANALYZE'),
|
('psql', '--no-password', '--quiet', '--dbname', 'foo', '--command', 'ANALYZE'),
|
||||||
|
|
Loading…
Reference in a new issue