diff --git a/app/features/admin/services/database_service.py b/app/features/admin/services/database_service.py index 394f9f4..d2c53ab 100644 --- a/app/features/admin/services/database_service.py +++ b/app/features/admin/services/database_service.py @@ -1,6 +1,7 @@ from __future__ import annotations import asyncio import shlex +import shutil from datetime import datetime, timezone from urllib.parse import urlparse from fastapi.responses import StreamingResponse @@ -64,11 +65,18 @@ class AdminDatabaseService: db_name = p.path.lstrip("/") or "acupedia_db" scope_flag = "" if scope == "full" else "-n content" - cmd = ( - f"PGPASSWORD={shlex.quote(pwd)} pg_dump " - f"-h {shlex.quote(host)} -p {shlex.quote(port)} -U {shlex.quote(user)} -d {shlex.quote(db_name)} " - f"--clean --if-exists {scope_flag} | gzip -9" - ) + if shutil.which("pg_dump"): + cmd = ( + f"PGPASSWORD={shlex.quote(pwd)} pg_dump " + f"-h {shlex.quote(host)} -p {shlex.quote(port)} -U {shlex.quote(user)} -d {shlex.quote(db_name)} " + f"--clean --if-exists {scope_flag} | gzip -9" + ) + else: + cmd = ( + f"docker exec -e PGPASSWORD={shlex.quote(pwd)} panacea-postgres pg_dump " + f"-U {shlex.quote(user)} -d {shlex.quote(db_name)} " + f"--clean --if-exists {scope_flag} | gzip -9" + ) timestamp_str = datetime.now(timezone.utc).strftime("%Y%m%d_%H%M%S") filename = f"acupedia_db_backup_{scope}_{timestamp_str}.sql.gz"