mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Implement enhanced backup logging and deployment tracking for database backups
- Refactored backup utilities for MariaDB, MongoDB, MySQL, and PostgreSQL to include detailed logging of command execution, improving traceability and debugging. - Introduced deployment tracking for backups, allowing for better management of backup statuses and notifications. - Updated backup command execution to utilize writable streams, ensuring efficient data handling during backup processes. - Enhanced error handling and logging for backup operations, providing clearer feedback on success or failure.
This commit is contained in:
@@ -3,13 +3,17 @@ import type { Postgres } from "@dokploy/server/services/postgres";
|
||||
import { findProjectById } from "@dokploy/server/services/project";
|
||||
import { getServiceContainer } from "../docker/utils";
|
||||
import { sendDatabaseBackupNotifications } from "../notifications/database-backup";
|
||||
import { execAsync, execAsyncRemote } from "../process/execAsync";
|
||||
import { execAsyncRemote, execAsyncStream } from "../process/execAsync";
|
||||
import {
|
||||
getPostgresBackupCommand,
|
||||
getS3Credentials,
|
||||
normalizeS3Path,
|
||||
} from "./utils";
|
||||
import { createDeploymentBackup } from "@dokploy/server/services/deployment";
|
||||
import {
|
||||
createDeploymentBackup,
|
||||
updateDeploymentStatus,
|
||||
} from "@dokploy/server/services/deployment";
|
||||
import { createWriteStream } from "node:fs";
|
||||
|
||||
export const runPostgresBackup = async (
|
||||
postgres: Postgres,
|
||||
@@ -45,9 +49,37 @@ export const runPostgresBackup = async (
|
||||
);
|
||||
|
||||
if (postgres.serverId) {
|
||||
await execAsyncRemote(postgres.serverId, `${command} | ${rcloneCommand}`);
|
||||
await execAsyncRemote(
|
||||
postgres.serverId,
|
||||
`
|
||||
set -e;
|
||||
echo "Running command." >> ${deployment.logPath};
|
||||
export RCLONE_LOG_LEVEL=DEBUG;
|
||||
${command} | ${rcloneCommand} >> ${deployment.logPath} 2>> ${deployment.logPath} || {
|
||||
echo "❌ Command failed" >> ${deployment.logPath};
|
||||
exit 1;
|
||||
}
|
||||
echo "✅ Command executed successfully" >> ${deployment.logPath};
|
||||
`,
|
||||
);
|
||||
} else {
|
||||
await execAsync(`${command} | ${rcloneCommand}`);
|
||||
const writeStream = createWriteStream(deployment.logPath, { flags: "a" });
|
||||
await execAsyncStream(
|
||||
`${command} | ${rcloneCommand}`,
|
||||
(data) => {
|
||||
if (writeStream.writable) {
|
||||
writeStream.write(data);
|
||||
}
|
||||
},
|
||||
{
|
||||
env: {
|
||||
...process.env,
|
||||
RCLONE_LOG_LEVEL: "DEBUG",
|
||||
},
|
||||
},
|
||||
);
|
||||
writeStream.write("Backup done✅");
|
||||
writeStream.end();
|
||||
}
|
||||
|
||||
await sendDatabaseBackupNotifications({
|
||||
@@ -57,6 +89,8 @@ export const runPostgresBackup = async (
|
||||
type: "success",
|
||||
organizationId: project.organizationId,
|
||||
});
|
||||
|
||||
await updateDeploymentStatus(deployment.deploymentId, "done");
|
||||
} catch (error) {
|
||||
await sendDatabaseBackupNotifications({
|
||||
applicationName: name,
|
||||
@@ -68,6 +102,8 @@ export const runPostgresBackup = async (
|
||||
organizationId: project.organizationId,
|
||||
});
|
||||
|
||||
await updateDeploymentStatus(deployment.deploymentId, "error");
|
||||
|
||||
throw error;
|
||||
} finally {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user