From fa2aff47df15645e9fa5792c82a4b32981a01236 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Fri, 10 Jul 2020 15:04:29 +0530 Subject: [PATCH] fix: psql command with subprocess --- build/common/commands/restore_backup.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/build/common/commands/restore_backup.py b/build/common/commands/restore_backup.py index 1fe46ae5..fa8f4883 100644 --- a/build/common/commands/restore_backup.py +++ b/build/common/commands/restore_backup.py @@ -200,15 +200,16 @@ def restore_postgres(config, site_config, database_file): db_name = site_config.get('db_name') db_password = site_config.get('db_password') - psql_command = ["psql", f"postgres://{db_root_user}:{db_root_password}@{db_host}:{db_port}"] + psql_command = ["psql"] + psql_uri = f"postgres://{db_root_user}:{db_root_password}@{db_host}:{db_port}" print('Restoring PostgreSQL') - run_command(psql_command + ["-c", f"\"DROP DATABASE IF EXISTS {db_name}\""]) - run_command(psql_command + ["-c", f"\"DROP USER IF EXISTS {db_name}\""]) - run_command(psql_command + ["-c ", f"\"CREATE DATABASE {db_name}\""]) - run_command(psql_command + ["-c", f"\"CREATE user {db_name} password '{db_password}'\""]) - run_command(psql_command + ["-c", f"\"GRANT ALL PRIVILEGES ON DATABASE \"{db_name}\" TO {db_name}\""]) - run_command(["psql", f"{psql_command[-1]}/{db_name}", "<", database_file.replace('.gz', '')]) + run_command(psql_command + [psql_uri, "-c", f"DROP DATABASE IF EXISTS \"{db_name}\""]) + run_command(psql_command + [psql_uri, "-c", f"DROP USER IF EXISTS {db_name}"]) + run_command(psql_command + [psql_uri, "-c", f"CREATE DATABASE \"{db_name}\""]) + run_command(psql_command + [psql_uri, "-c", f"CREATE user {db_name} password '{db_password}'"]) + run_command(psql_command + [psql_uri, "-c", f"GRANT ALL PRIVILEGES ON DATABASE \"{db_name}\" TO {db_name}"]) + run_command(psql_command + [f"{psql_uri}/{db_name}", "<", database_file.replace('.gz', '')]) def restore_mariadb(config, site_config, database_file):