mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
zoph: Don't fail with backup/restore if app is disabled
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
6646512a0a
commit
17e84419b8
@ -102,7 +102,11 @@ def is_configured() -> bool | None:
|
|||||||
|
|
||||||
@privileged
|
@privileged
|
||||||
def dump_database():
|
def dump_database():
|
||||||
"""Dump database to file."""
|
"""Dump database to file.
|
||||||
|
|
||||||
|
May be called when app is disabled.
|
||||||
|
"""
|
||||||
|
with action_utils.service_ensure_running('mysql'):
|
||||||
db_name = _get_db_name()
|
db_name = _get_db_name()
|
||||||
os.makedirs(os.path.dirname(DB_BACKUP_FILE), exist_ok=True)
|
os.makedirs(os.path.dirname(DB_BACKUP_FILE), exist_ok=True)
|
||||||
with open(DB_BACKUP_FILE, 'w', encoding='utf-8') as db_backup_file:
|
with open(DB_BACKUP_FILE, 'w', encoding='utf-8') as db_backup_file:
|
||||||
@ -112,9 +116,14 @@ def dump_database():
|
|||||||
|
|
||||||
@privileged
|
@privileged
|
||||||
def restore_database():
|
def restore_database():
|
||||||
"""Restore database from file."""
|
"""Restore database from file.
|
||||||
|
|
||||||
|
May be called when app is disabled.
|
||||||
|
"""
|
||||||
|
with action_utils.service_ensure_running('mysql'):
|
||||||
db_name = _get_db_name()
|
db_name = _get_db_name()
|
||||||
subprocess.run(['mysqladmin', '--force', 'drop', db_name], check=False)
|
subprocess.run(['mysqladmin', '--force', 'drop', db_name], check=False)
|
||||||
subprocess.run(['mysqladmin', 'create', db_name], check=True)
|
subprocess.run(['mysqladmin', 'create', db_name], check=True)
|
||||||
with open(DB_BACKUP_FILE, 'r', encoding='utf-8') as db_restore_file:
|
with open(DB_BACKUP_FILE, 'r', encoding='utf-8') as db_restore_file:
|
||||||
subprocess.run(['mysql', db_name], stdin=db_restore_file, check=True)
|
subprocess.run(['mysql', db_name], stdin=db_restore_file,
|
||||||
|
check=True)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user