From 5962fd473e54ada92de6a220db729da11c769bfe Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Fri, 21 Apr 2023 10:34:50 -0700 Subject: [PATCH] Another try. Backing out psql error changes (#678). --- .drone.yml | 2 +- NEWS | 1 - borgmatic/hooks/postgresql.py | 6 +----- tests/end-to-end/docker-compose.yaml | 1 - tests/end-to-end/test_database.py | 6 +++--- tests/unit/hooks/test_postgresql.py | 8 ++++++-- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/.drone.yml b/.drone.yml index f2c5f7d..dcc19c6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,3 +1,4 @@ +--- kind: pipeline name: python-3-8-alpine-3-13 @@ -5,7 +6,6 @@ services: - name: postgresql image: docker.io/postgres:13.1-alpine environment: - POSTGRES_USER: test POSTGRES_PASSWORD: test POSTGRES_DB: test - name: mysql diff --git a/NEWS b/NEWS index 530a447..2021467 100644 --- a/NEWS +++ b/NEWS @@ -7,7 +7,6 @@ commands with arguments. * #678: Fix calls to psql in PostgreSQL hook to ignore "~/.psqlrc", whose settings can break database dumping. - * #678: Fix calls to psql in PostgreSQL hook to abort on error during a database restore. * #682: Fix "source_directories_must_exist" option to expand globs and tildes in source directories. * #684: Rename "master" development branch to "main" to use more inclusive language. You'll need to update your development checkouts accordingly. diff --git a/borgmatic/hooks/postgresql.py b/borgmatic/hooks/postgresql.py index 859f7ec..3325391 100644 --- a/borgmatic/hooks/postgresql.py +++ b/borgmatic/hooks/postgresql.py @@ -229,11 +229,7 @@ def restore_database_dump(database_config, log_prefix, location_config, dry_run, restore_command = ( tuple(psql_command if use_psql_command else pg_restore_command) + ('--no-password',) - + ( - ('--no-psqlrc', '--set', 'ON_ERROR_STOP=on') - if use_psql_command - else ('--if-exists', '--exit-on-error', '--clean') - ) + + (('--no-psqlrc',) if use_psql_command else ('--if-exists', '--exit-on-error', '--clean')) + (('--dbname', database['name']) if not all_databases else ()) + (('--host', database['hostname']) if 'hostname' in database else ()) + (('--port', str(database['port'])) if 'port' in database else ()) diff --git a/tests/end-to-end/docker-compose.yaml b/tests/end-to-end/docker-compose.yaml index f9895a8..0bbec8c 100644 --- a/tests/end-to-end/docker-compose.yaml +++ b/tests/end-to-end/docker-compose.yaml @@ -3,7 +3,6 @@ services: postgresql: image: docker.io/postgres:13.1-alpine environment: - POSTGRES_USER: test POSTGRES_PASSWORD: test POSTGRES_DB: test mysql: diff --git a/tests/end-to-end/test_database.py b/tests/end-to-end/test_database.py index 8b38e07..5c4e22c 100644 --- a/tests/end-to-end/test_database.py +++ b/tests/end-to-end/test_database.py @@ -36,17 +36,17 @@ hooks: postgresql_databases: - name: test hostname: postgresql - username: test + username: postgres password: test format: {postgresql_dump_format} - name: all hostname: postgresql - username: test + username: postgres password: test - name: all format: custom hostname: postgresql - username: test + username: postgres password: test mysql_databases: - name: test diff --git a/tests/unit/hooks/test_postgresql.py b/tests/unit/hooks/test_postgresql.py index e3ecbdb..b3a55fa 100644 --- a/tests/unit/hooks/test_postgresql.py +++ b/tests/unit/hooks/test_postgresql.py @@ -656,7 +656,11 @@ 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', '--set', 'ON_ERROR_STOP=on'), + ( + 'psql', + '--no-password', + '--no-psqlrc', + ), processes=[extract_process], output_log_level=logging.DEBUG, input_file=extract_process.stdout, @@ -680,7 +684,7 @@ def test_restore_database_dump_runs_psql_for_plain_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', '--set', 'ON_ERROR_STOP=on', '--dbname', 'foo'), + ('psql', '--no-password', '--no-psqlrc', '--dbname', 'foo'), processes=[extract_process], output_log_level=logging.DEBUG, input_file=extract_process.stdout,