Enhance PostgreSQL backup command in web server utility

- Added error handling to check for the existence of the PostgreSQL container before executing the backup command.
- Updated the backup command to use the retrieved container ID, ensuring the command runs correctly.
This commit is contained in:
Mauricio Siu 2025-04-17 01:58:25 -06:00
parent f4cd617107
commit 8e8bc3e71e

View File

@ -23,7 +23,17 @@ export const runWebServerBackup = async (backup: BackupSchedule) => {
try { try {
await execAsync(`mkdir -p ${tempDir}/filesystem`); await execAsync(`mkdir -p ${tempDir}/filesystem`);
const postgresCommand = `docker exec $(docker ps --filter "name=dokploy-postgres" -q) pg_dump -v -Fc -U dokploy -d dokploy > ${tempDir}/database.sql`; // First get the container ID
const { stdout: containerId } = await execAsync(
"docker ps --filter 'name=dokploy-postgres' -q",
);
if (!containerId) {
throw new Error("PostgreSQL container not found");
}
// Then run pg_dump with the container ID
const postgresCommand = `docker exec ${containerId.trim()} pg_dump -v -Fc -U dokploy -d dokploy > '${tempDir}/database.sql'`;
await execAsync(postgresCommand); await execAsync(postgresCommand);
await execAsync(`cp -r ${BASE_PATH}/* ${tempDir}/filesystem/`); await execAsync(`cp -r ${BASE_PATH}/* ${tempDir}/filesystem/`);