From 31ff697835ef0af2be35dec43fbe9353140697f2 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Fri, 10 Jul 2020 15:42:36 +0530 Subject: [PATCH] fix: mysql command with subprocess --- build/common/commands/new.py | 6 +++--- build/common/commands/restore_backup.py | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/build/common/commands/new.py b/build/common/commands/new.py index feba0401..f6cc00a3 100644 --- a/build/common/commands/new.py +++ b/build/common/commands/new.py @@ -98,15 +98,15 @@ def main(): mysql_command = ["mysql", f"-h{db_host}", f"-u{mariadb_root_username}", f"-p{mariadb_root_password}", "-e"] # update User's host to '%' required to connect from any container - command = mysql_command + [f"\"UPDATE mysql.user SET Host = '%' where User = '{db_name}'; FLUSH PRIVILEGES;\""] + command = mysql_command + [f"UPDATE mysql.user SET Host = '%' where User = '{db_name}'; FLUSH PRIVILEGES;"] run_command(command) # Set db password - command = mysql_command + [f"\"ALTER USER '{db_name}'@'%' IDENTIFIED BY '{db_password}'; FLUSH PRIVILEGES;\""] + command = mysql_command + [f"ALTER USER '{db_name}'@'%' IDENTIFIED BY '{db_password}'; FLUSH PRIVILEGES;"] run_command(command) # Grant permission to database - command = mysql_command + [f"\"GRANT ALL PRIVILEGES ON \`{db_name}\`.* TO '{db_name}'@'%'; FLUSH PRIVILEGES;\""] + command = mysql_command + [f"GRANT ALL PRIVILEGES ON \`{db_name}\`.* TO '{db_name}'@'%'; FLUSH PRIVILEGES;"] run_command(command) if frappe.redis_server: diff --git a/build/common/commands/restore_backup.py b/build/common/commands/restore_backup.py index fa8f4883..d2e4f0ee 100644 --- a/build/common/commands/restore_backup.py +++ b/build/common/commands/restore_backup.py @@ -229,22 +229,22 @@ def restore_mariadb(config, site_config, database_file): mysql_command = ["mysql", f"-u{db_root_user}", f"-h{db_host}", f"-p{db_root_password}", f"-P{db_port}"] # drop db if exists for clean restore - drop_database = mysql_command + ["-e", f"\"DROP DATABASE IF EXISTS \`{db_name}\`;\""] + drop_database = mysql_command + ["-e", f"DROP DATABASE IF EXISTS \`{db_name}\`;"] run_command(drop_database) # create db - create_database = mysql_command + ["-e", f"\"CREATE DATABASE IF NOT EXISTS \`{db_name}\`;\""] + create_database = mysql_command + ["-e", f"CREATE DATABASE IF NOT EXISTS \`{db_name}\`;"] run_command(create_database) # create user - create_user = mysql_command + ["-e", f"\"CREATE USER IF NOT EXISTS \'{db_name}\'@\'%\' IDENTIFIED BY \'{db_password}\'; FLUSH PRIVILEGES;\""] + create_user = mysql_command + ["-e", f"CREATE USER IF NOT EXISTS \'{db_name}\'@\'%\' IDENTIFIED BY \'{db_password}\'; FLUSH PRIVILEGES;"] run_command(create_user) # grant db privileges to user - grant_privileges = mysql_command + ["-e", f"\"GRANT ALL PRIVILEGES ON \`{db_name}\`.* TO '{db_name}'@'%' IDENTIFIED BY '{db_password}'; FLUSH PRIVILEGES;\""] + grant_privileges = mysql_command + ["-e", f"GRANT ALL PRIVILEGES ON \`{db_name}\`.* TO '{db_name}'@'%' IDENTIFIED BY '{db_password}'; FLUSH PRIVILEGES;"] run_command(grant_privileges) - command = mysql_command + [f"'{db_name}'", "<", database_file.replace(".gz", "")] + command = mysql_command + [f"{db_name}", "<", database_file.replace(".gz", "")] print('Restoring MariaDB') run_command(command)