From 8d28a50a17ae3f54cad33c8368e71ea68079e9e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20DEM=C4=B0RC=C4=B0?= Date: Sun, 20 Apr 2025 12:14:41 +0000 Subject: [PATCH] fix(backup): handle multiple container IDs in backup command Ensure only one container ID is used when running `docker exec` for pg_dump to avoid errors caused by multiple matching containers. Fixes INTERNAL_SERVER_ERROR from backup.manualBackupWebServer path. Co-authored-by: Merloss 54235902+Merloss@users.noreply.github.com --- packages/server/src/utils/backups/web-server.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/server/src/utils/backups/web-server.ts b/packages/server/src/utils/backups/web-server.ts index ef2249d0a..1870a08c9 100644 --- a/packages/server/src/utils/backups/web-server.ts +++ b/packages/server/src/utils/backups/web-server.ts @@ -24,6 +24,7 @@ export const runWebServerBackup = async (backup: BackupSchedule) => { await execAsync(`mkdir -p ${tempDir}/filesystem`); // First get the container ID + // Returns: ID\nID\nID... const { stdout: containerId } = await execAsync( "docker ps --filter 'name=dokploy-postgres' -q", ); @@ -32,14 +33,20 @@ export const runWebServerBackup = async (backup: BackupSchedule) => { throw new Error("PostgreSQL container not found"); } + // ID\nID\nID... => [ "ID", "ID", ... ] + const containers = containerId.trim().split("\n").filter(Boolean); + // 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); + for (const containerId of containers) { + // Maybe we can find a better identification for this part vvv + const postgresCommand = `docker exec ${containerId.trim()} pg_dump -v -Fc -U dokploy -d dokploy > '${tempDir}/database-${containerId}.sql'`; + await execAsync(postgresCommand); + } await execAsync(`cp -r ${BASE_PATH}/* ${tempDir}/filesystem/`); - await execAsync( - `cd ${tempDir} && zip -r ${backupFileName} database.sql filesystem/ > /dev/null 2>&1`, + await execAsync( // Zip all .sql files since we created more than one + `cd ${tempDir} && zip -r ${backupFileName} *.sql filesystem/ > /dev/null 2>&1`, ); const uploadCommand = `rclone copyto ${rcloneFlags.join(" ")} "${tempDir}/${backupFileName}" "${s3Path}"`;