refactor: DB dump executable logic (#22799)
This commit is contained in:
parent
8df5402b1f
commit
d1111fb189
1 changed files with 25 additions and 9 deletions
|
|
@ -362,22 +362,38 @@ class BackupGenerator:
|
|||
with open(site_config_backup_path, "w") as n, open(site_config_path) as c:
|
||||
n.write(c.read())
|
||||
|
||||
def get_db_dump_exeuctable(self) -> str:
|
||||
db_exc, exists = None, False
|
||||
|
||||
if self.db_type == "mariadb":
|
||||
if mariadb_dump_path := which("mariadb-dump"):
|
||||
exists = bool(mariadb_dump_path)
|
||||
db_exc = "mariadb-dump"
|
||||
else:
|
||||
# Fallback to mysqldump if mariadb-dump is not available.
|
||||
db_exc = "mysqldump"
|
||||
exists = bool(which(db_exc))
|
||||
elif self.db_type == "postgres":
|
||||
db_exc = "pg_dump"
|
||||
exists = bool(which(db_exc))
|
||||
|
||||
if not exists:
|
||||
frappe.throw(
|
||||
f"{db_exc} not found in PATH! This is required to take a backup.",
|
||||
exc=frappe.ExecutableNotFound,
|
||||
)
|
||||
return db_exc
|
||||
|
||||
def take_dump(self):
|
||||
import frappe.utils
|
||||
from frappe.utils.change_log import get_app_branch
|
||||
|
||||
db_exc = {
|
||||
"mariadb": ("mariadb-dump", which("mariadb-dump") or which("mysqldump")),
|
||||
"postgres": ("pg_dump", which("pg_dump")),
|
||||
}[self.db_type]
|
||||
db_exc = self.get_db_dump_exeuctable()
|
||||
gzip_exc = which("gzip")
|
||||
|
||||
if not (gzip_exc and db_exc[1]):
|
||||
_exc = "gzip" if not gzip_exc else db_exc[0]
|
||||
if not gzip_exc:
|
||||
frappe.throw(
|
||||
f"{_exc} not found in PATH! This is required to take a backup.", exc=frappe.ExecutableNotFound
|
||||
"`gzip` not found in PATH! This is required to take a backup.", exc=frappe.ExecutableNotFound
|
||||
)
|
||||
db_exc = db_exc[0]
|
||||
|
||||
database_header_content = [
|
||||
f"Backup generated by Frappe {frappe.__version__} on branch {get_app_branch('frappe') or 'N/A'}",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue