From 4b523f9e2c9a802db8e950fdb85661dbe9586be2 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Fri, 8 May 2020 19:38:33 -0700 Subject: [PATCH] Make database restore output only show at verbosity 2. --- borgmatic/hooks/mysql.py | 3 ++- borgmatic/hooks/postgresql.py | 1 + tests/unit/hooks/test_mysql.py | 10 ++++++++-- tests/unit/hooks/test_postgresql.py | 6 ++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/borgmatic/hooks/mysql.py b/borgmatic/hooks/mysql.py index 49e2ea040..0805e0963 100644 --- a/borgmatic/hooks/mysql.py +++ b/borgmatic/hooks/mysql.py @@ -152,7 +152,7 @@ def restore_database_dump(database_config, log_prefix, location_config, dry_run, database = database_config[0] restore_command = ( - ('mysql', '--batch') + ('mysql', '--batch', '--verbose') + (('--host', database['hostname']) if 'hostname' in database else ()) + (('--port', str(database['port'])) if 'port' in database else ()) + (('--protocol', 'tcp') if 'hostname' in database or 'port' in database else ()) @@ -169,6 +169,7 @@ def restore_database_dump(database_config, log_prefix, location_config, dry_run, execute_command_with_processes( restore_command, [extract_process], + output_log_level=logging.DEBUG, input_file=extract_process.stdout, extra_environment=extra_environment, ) diff --git a/borgmatic/hooks/postgresql.py b/borgmatic/hooks/postgresql.py index 666540cac..f50da7b48 100644 --- a/borgmatic/hooks/postgresql.py +++ b/borgmatic/hooks/postgresql.py @@ -142,6 +142,7 @@ def restore_database_dump(database_config, log_prefix, location_config, dry_run, execute_command_with_processes( restore_command, [extract_process], + output_log_level=logging.DEBUG, input_file=extract_process.stdout, extra_environment=extra_environment, ) diff --git a/tests/unit/hooks/test_mysql.py b/tests/unit/hooks/test_mysql.py index abe837584..2b757c8bd 100644 --- a/tests/unit/hooks/test_mysql.py +++ b/tests/unit/hooks/test_mysql.py @@ -1,3 +1,5 @@ +import logging + import pytest from flexmock import flexmock @@ -201,8 +203,9 @@ def test_restore_database_dump_runs_mysql_to_restore(): extract_process = flexmock(stdout=flexmock()) flexmock(module).should_receive('execute_command_with_processes').with_args( - ('mysql', '--batch'), + ('mysql', '--batch', '--verbose'), processes=[extract_process], + output_log_level=logging.DEBUG, input_file=extract_process.stdout, extra_environment=None, ).once() @@ -232,6 +235,7 @@ def test_restore_database_dump_runs_mysql_with_hostname_and_port(): ( 'mysql', '--batch', + '--verbose', '--host', 'database.example.org', '--port', @@ -240,6 +244,7 @@ def test_restore_database_dump_runs_mysql_with_hostname_and_port(): 'tcp', ), processes=[extract_process], + output_log_level=logging.DEBUG, input_file=extract_process.stdout, extra_environment=None, ).once() @@ -254,8 +259,9 @@ def test_restore_database_dump_runs_mysql_with_username_and_password(): extract_process = flexmock(stdout=flexmock()) flexmock(module).should_receive('execute_command_with_processes').with_args( - ('mysql', '--batch', '--user', 'root'), + ('mysql', '--batch', '--verbose', '--user', 'root'), processes=[extract_process], + output_log_level=logging.DEBUG, input_file=extract_process.stdout, extra_environment={'MYSQL_PWD': 'trustsome1'}, ).once() diff --git a/tests/unit/hooks/test_postgresql.py b/tests/unit/hooks/test_postgresql.py index 68b551a3c..089f89a06 100644 --- a/tests/unit/hooks/test_postgresql.py +++ b/tests/unit/hooks/test_postgresql.py @@ -1,3 +1,5 @@ +import logging + import pytest from flexmock import flexmock @@ -203,6 +205,7 @@ def test_restore_database_dump_runs_pg_restore(): 'foo', ), processes=[extract_process], + output_log_level=logging.DEBUG, input_file=extract_process.stdout, extra_environment=None, ).once() @@ -247,6 +250,7 @@ def test_restore_database_dump_runs_pg_restore_with_hostname_and_port(): '5433', ), processes=[extract_process], + output_log_level=logging.DEBUG, input_file=extract_process.stdout, extra_environment=None, ).once() @@ -289,6 +293,7 @@ def test_restore_database_dump_runs_pg_restore_with_username_and_password(): 'postgres', ), processes=[extract_process], + output_log_level=logging.DEBUG, input_file=extract_process.stdout, extra_environment={'PGPASSWORD': 'trustsome1'}, ).once() @@ -319,6 +324,7 @@ def test_restore_database_dump_runs_psql_for_all_database_dump(): flexmock(module).should_receive('execute_command_with_processes').with_args( ('psql', '--no-password'), processes=[extract_process], + output_log_level=logging.DEBUG, input_file=extract_process.stdout, extra_environment=None, ).once()