From 557c89ac6dcc3aaf00dec8780650239ae71b8ddf Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 3 May 2025 13:41:19 -0600 Subject: [PATCH] Enhance backup logging and error handling in web server backup utility - Added detailed logging for PostgreSQL container retrieval and command execution, improving traceability during backup processes. - Updated success and error messages to provide clearer feedback on backup operations, including specific command outputs and error details. - Ensured proper stream handling for logging messages, enhancing the overall robustness of the backup utility. --- packages/server/src/utils/backups/web-server.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/server/src/utils/backups/web-server.ts b/packages/server/src/utils/backups/web-server.ts index 989f4c4a..ae63b188 100644 --- a/packages/server/src/utils/backups/web-server.ts +++ b/packages/server/src/utils/backups/web-server.ts @@ -42,24 +42,35 @@ export const runWebServerBackup = async (backup: BackupSchedule) => { ); if (!containerId) { + writeStream.write("PostgreSQL container not found❌"); + writeStream.end(); throw new Error("PostgreSQL container not found"); } + writeStream.write(`PostgreSQL container ID: ${containerId}`); + const postgresContainerId = containerId.trim(); const postgresCommand = `docker exec ${postgresContainerId} pg_dump -v -Fc -U dokploy -d dokploy > '${tempDir}/database.sql'`; + + writeStream.write(`Running command: ${postgresCommand}`); await execAsync(postgresCommand); await execAsync(`cp -r ${BASE_PATH}/* ${tempDir}/filesystem/`); + writeStream.write("Copied filesystem to temp directory"); + await execAsync( // Zip all .sql files since we created more than one `cd ${tempDir} && zip -r ${backupFileName} *.sql filesystem/ > /dev/null 2>&1`, ); + writeStream.write("Zipped database and filesystem"); + const uploadCommand = `rclone copyto ${rcloneFlags.join(" ")} "${tempDir}/${backupFileName}" "${s3Path}"`; + writeStream.write(`Running command: ${uploadCommand}`); await execAsync(uploadCommand); - writeStream.write("Backup done✅"); + writeStream.write("Uploaded backup to S3 ✅"); writeStream.end(); await updateDeploymentStatus(deployment.deploymentId, "done"); return true; @@ -68,7 +79,7 @@ export const runWebServerBackup = async (backup: BackupSchedule) => { } } catch (error) { console.error("Backup error:", error); - writeStream.write("Backup error❌"); + writeStream.write("Backup error❌\n"); writeStream.write(error instanceof Error ? error.message : "Unknown error"); writeStream.end(); await updateDeploymentStatus(deployment.deploymentId, "error");