From 64a2c9e0a130f0b47622ed2b076eab9d82ace65f Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 17 May 2025 00:13:43 -0600 Subject: [PATCH] refactor: update database backup process in web server utility to use temporary file in container --- packages/server/src/utils/backups/web-server.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/server/src/utils/backups/web-server.ts b/packages/server/src/utils/backups/web-server.ts index 71df47ba..d9797a2a 100644 --- a/packages/server/src/utils/backups/web-server.ts +++ b/packages/server/src/utils/backups/web-server.ts @@ -51,10 +51,20 @@ export const runWebServerBackup = async (backup: BackupSchedule) => { const postgresContainerId = containerId.trim(); - const postgresCommand = `docker exec ${postgresContainerId} pg_dump -v -Fc -U dokploy -d dokploy > '${tempDir}/database.sql'`; + // First dump the database inside the container + const dumpCommand = `docker exec ${postgresContainerId} pg_dump -v -Fc -U dokploy -d dokploy -f /tmp/database.sql`; + writeStream.write(`Running dump command: ${dumpCommand}\n`); + await execAsync(dumpCommand); - writeStream.write(`Running command: ${postgresCommand}\n`); - await execAsync(postgresCommand); + // Then copy the file from the container to host + const copyCommand = `docker cp ${postgresContainerId}:/tmp/database.sql ${tempDir}/database.sql`; + writeStream.write(`Copying database dump: ${copyCommand}\n`); + await execAsync(copyCommand); + + // Clean up the temp file in the container + const cleanupCommand = `docker exec ${postgresContainerId} rm -f /tmp/database.sql`; + writeStream.write(`Cleaning up temp file: ${cleanupCommand}\n`); + await execAsync(cleanupCommand); await execAsync( `rsync -av --ignore-errors ${BASE_PATH}/ ${tempDir}/filesystem/`,