mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-11 09:04:54 +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,19 +102,28 @@ def is_configured() -> bool | None:
|
||||
|
||||
@privileged
|
||||
def dump_database():
|
||||
"""Dump database to file."""
|
||||
db_name = _get_db_name()
|
||||
os.makedirs(os.path.dirname(DB_BACKUP_FILE), exist_ok=True)
|
||||
with open(DB_BACKUP_FILE, 'w', encoding='utf-8') as db_backup_file:
|
||||
subprocess.run(['mysqldump', db_name], stdout=db_backup_file,
|
||||
check=True)
|
||||
"""Dump database to file.
|
||||
|
||||
May be called when app is disabled.
|
||||
"""
|
||||
with action_utils.service_ensure_running('mysql'):
|
||||
db_name = _get_db_name()
|
||||
os.makedirs(os.path.dirname(DB_BACKUP_FILE), exist_ok=True)
|
||||
with open(DB_BACKUP_FILE, 'w', encoding='utf-8') as db_backup_file:
|
||||
subprocess.run(['mysqldump', db_name], stdout=db_backup_file,
|
||||
check=True)
|
||||
|
||||
|
||||
@privileged
|
||||
def restore_database():
|
||||
"""Restore database from file."""
|
||||
db_name = _get_db_name()
|
||||
subprocess.run(['mysqladmin', '--force', 'drop', db_name], check=False)
|
||||
subprocess.run(['mysqladmin', 'create', db_name], check=True)
|
||||
with open(DB_BACKUP_FILE, 'r', encoding='utf-8') as db_restore_file:
|
||||
subprocess.run(['mysql', db_name], stdin=db_restore_file, check=True)
|
||||
"""Restore database from file.
|
||||
|
||||
May be called when app is disabled.
|
||||
"""
|
||||
with action_utils.service_ensure_running('mysql'):
|
||||
db_name = _get_db_name()
|
||||
subprocess.run(['mysqladmin', '--force', 'drop', db_name], check=False)
|
||||
subprocess.run(['mysqladmin', 'create', db_name], check=True)
|
||||
with open(DB_BACKUP_FILE, 'r', encoding='utf-8') as db_restore_file:
|
||||
subprocess.run(['mysql', db_name], stdin=db_restore_file,
|
||||
check=True)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user