mirror of
https://github.com/frappe/frappe_docker.git
synced 2024-12-23 18:48:58 +00:00
fix: mysql command with subprocess
This commit is contained in:
parent
fa2aff47df
commit
31ff697835
@ -98,15 +98,15 @@ def main():
|
|||||||
mysql_command = ["mysql", f"-h{db_host}", f"-u{mariadb_root_username}", f"-p{mariadb_root_password}", "-e"]
|
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
|
# 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)
|
run_command(command)
|
||||||
|
|
||||||
# Set db password
|
# 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)
|
run_command(command)
|
||||||
|
|
||||||
# Grant permission to database
|
# 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)
|
run_command(command)
|
||||||
|
|
||||||
if frappe.redis_server:
|
if frappe.redis_server:
|
||||||
|
@ -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}"]
|
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 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)
|
run_command(drop_database)
|
||||||
|
|
||||||
# create db
|
# 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)
|
run_command(create_database)
|
||||||
|
|
||||||
# create user
|
# 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)
|
run_command(create_user)
|
||||||
|
|
||||||
# grant db privileges to 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)
|
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')
|
print('Restoring MariaDB')
|
||||||
run_command(command)
|
run_command(command)
|
||||||
|
Loading…
Reference in New Issue
Block a user