mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Refactor backup and command execution utilities for improved robustness
- Removed unnecessary console logging in the backup scheduling utility to streamline output. - Updated container ID retrieval to handle potential null values gracefully, enhancing error handling. - Modified command execution logging to use single quotes for consistency and improved readability.
This commit is contained in:
@@ -21,9 +21,6 @@ export const scheduleBackup = (backup: BackupSchedule) => {
|
|||||||
compose,
|
compose,
|
||||||
} = backup;
|
} = backup;
|
||||||
scheduleJob(backupId, schedule, async () => {
|
scheduleJob(backupId, schedule, async () => {
|
||||||
console.log("backup", backup);
|
|
||||||
console.log("databaseType", databaseType);
|
|
||||||
console.log("schedule", schedule);
|
|
||||||
if (backup.backupType === "database") {
|
if (backup.backupType === "database") {
|
||||||
if (databaseType === "postgres" && postgres) {
|
if (databaseType === "postgres" && postgres) {
|
||||||
await runPostgresBackup(postgres, backup);
|
await runPostgresBackup(postgres, backup);
|
||||||
|
|||||||
@@ -49,12 +49,12 @@ export const runCommand = async (scheduleId: string) => {
|
|||||||
application.appName,
|
application.appName,
|
||||||
application.serverId,
|
application.serverId,
|
||||||
);
|
);
|
||||||
containerId = container.Id;
|
containerId = container?.Id || "";
|
||||||
serverId = application.serverId || "";
|
serverId = application.serverId || "";
|
||||||
}
|
}
|
||||||
if (scheduleType === "compose" && compose) {
|
if (scheduleType === "compose" && compose) {
|
||||||
const container = await getComposeContainer(compose, serviceName || "");
|
const container = await getComposeContainer(compose, serviceName || "");
|
||||||
containerId = container.Id;
|
containerId = container?.Id || "";
|
||||||
serverId = compose.serverId || "";
|
serverId = compose.serverId || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,8 +64,8 @@ export const runCommand = async (scheduleId: string) => {
|
|||||||
serverId,
|
serverId,
|
||||||
`
|
`
|
||||||
set -e
|
set -e
|
||||||
echo "Running command: docker exec ${containerId} ${shellType} -c \"${command}\"" >> ${deployment.logPath};
|
echo "Running command: docker exec ${containerId} ${shellType} -c '${command}'" >> ${deployment.logPath};
|
||||||
docker exec ${containerId} ${shellType} -c "${command}" >> ${deployment.logPath} 2>> ${deployment.logPath} || {
|
docker exec ${containerId} ${shellType} -c '${command}' >> ${deployment.logPath} 2>> ${deployment.logPath} || {
|
||||||
echo "❌ Command failed" >> ${deployment.logPath};
|
echo "❌ Command failed" >> ${deployment.logPath};
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@ export const runCommand = async (scheduleId: string) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
writeStream.write(
|
writeStream.write(
|
||||||
`docker exec ${containerId} ${shellType} -c "${command}"\n`,
|
`docker exec ${containerId} ${shellType} -c ${command}\n`,
|
||||||
);
|
);
|
||||||
await spawnAsync(
|
await spawnAsync(
|
||||||
"docker",
|
"docker",
|
||||||
|
|||||||
Reference in New Issue
Block a user