mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
wordpress: Fix backup, restore and uninstall when db is not running
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
c341a531dd
commit
d615ff107e
@ -144,21 +144,23 @@ def is_public() -> bool:
|
|||||||
def dump_database():
|
def dump_database():
|
||||||
"""Dump database to file."""
|
"""Dump database to file."""
|
||||||
_db_backup_file.parent.mkdir(parents=True, exist_ok=True)
|
_db_backup_file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
with _db_backup_file.open('w', encoding='utf-8') as file_handle:
|
with action_utils.service_ensure_running('mysql'):
|
||||||
subprocess.run([
|
with _db_backup_file.open('w', encoding='utf-8') as file_handle:
|
||||||
'mysqldump', '--add-drop-database', '--add-drop-table',
|
subprocess.run([
|
||||||
'--add-drop-trigger', '--user', 'root', '--databases', DB_NAME
|
'mysqldump', '--add-drop-database', '--add-drop-table',
|
||||||
], stdout=file_handle, check=True)
|
'--add-drop-trigger', '--user', 'root', '--databases', DB_NAME
|
||||||
|
], stdout=file_handle, check=True)
|
||||||
|
|
||||||
|
|
||||||
@privileged
|
@privileged
|
||||||
def restore_database():
|
def restore_database():
|
||||||
"""Restore database from file."""
|
"""Restore database from file."""
|
||||||
with _db_backup_file.open('r', encoding='utf-8') as file_handle:
|
with action_utils.service_ensure_running('mysql'):
|
||||||
subprocess.run(['mysql', '--user', 'root'], stdin=file_handle,
|
with _db_backup_file.open('r', encoding='utf-8') as file_handle:
|
||||||
check=True)
|
subprocess.run(['mysql', '--user', 'root'], stdin=file_handle,
|
||||||
|
check=True)
|
||||||
|
|
||||||
_set_privileges(DB_HOST, DB_NAME, DB_USER, _read_db_password())
|
_set_privileges(DB_HOST, DB_NAME, DB_USER, _read_db_password())
|
||||||
|
|
||||||
|
|
||||||
def _read_db_password():
|
def _read_db_password():
|
||||||
@ -188,6 +190,7 @@ def uninstall():
|
|||||||
|
|
||||||
def _drop_database():
|
def _drop_database():
|
||||||
"""Drop the mysql database that was created during install."""
|
"""Drop the mysql database that was created during install."""
|
||||||
query = f'''DROP DATABASE {DB_NAME};'''
|
with action_utils.service_ensure_running('mysql'):
|
||||||
subprocess.run(['mysql', '--user', 'root'], input=query.encode(),
|
query = f'''DROP DATABASE {DB_NAME};'''
|
||||||
check=True)
|
subprocess.run(['mysql', '--user', 'root'], input=query.encode(),
|
||||||
|
check=True)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user