From dfccc1b94a57cf791bf4fe06b4353e20fa75c2ee Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Fri, 14 Apr 2023 16:27:45 +0200 Subject: [PATCH] Exit on error when restoring all PostgreSQL databases "--set ON_ERROR_STOP=on" is equivalent to "--exit-on-error" in pg_restore. --- borgmatic/hooks/postgresql.py | 2 +- tests/unit/hooks/test_postgresql.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/borgmatic/hooks/postgresql.py b/borgmatic/hooks/postgresql.py index fbe890a..b91b97b 100644 --- a/borgmatic/hooks/postgresql.py +++ b/borgmatic/hooks/postgresql.py @@ -223,7 +223,7 @@ def restore_database_dump(database_config, log_prefix, location_config, dry_run, + ( ('--if-exists', '--exit-on-error', '--clean', '--dbname', database['name']) if not all_databases - else ('--no-psqlrc',) + else ('--no-psqlrc', '--set', 'ON_ERROR_STOP=on') ) + (('--host', database['hostname']) if 'hostname' in database else ()) + (('--port', str(database['port'])) if 'port' in database else ()) diff --git a/tests/unit/hooks/test_postgresql.py b/tests/unit/hooks/test_postgresql.py index 704d5a7..5f02978 100644 --- a/tests/unit/hooks/test_postgresql.py +++ b/tests/unit/hooks/test_postgresql.py @@ -607,7 +607,7 @@ def test_restore_database_dump_runs_psql_for_all_database_dump(): flexmock(module).should_receive('make_dump_path') flexmock(module.dump).should_receive('make_database_dump_filename') flexmock(module).should_receive('execute_command_with_processes').with_args( - ('psql', '--no-password', '--no-psqlrc'), + ('psql', '--no-password', '--no-psqlrc', '--set', 'ON_ERROR_STOP=on'), processes=[extract_process], output_log_level=logging.DEBUG, input_file=extract_process.stdout,