mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-12 15:05:19 +00:00
Merge pull request #2652 from Dokploy/2630-backups-dont-get-deleted-when-backup-fails
fix: enhance error handling in volume backup process by adding cleanu…
This commit is contained in:
@@ -1,15 +1,17 @@
|
|||||||
import { findVolumeBackupById } from "@dokploy/server/services/volume-backups";
|
import path from "node:path";
|
||||||
import { scheduledJobs, scheduleJob } from "node-schedule";
|
import { paths } from "@dokploy/server/constants";
|
||||||
import {
|
import {
|
||||||
createDeploymentVolumeBackup,
|
createDeploymentVolumeBackup,
|
||||||
updateDeploymentStatus,
|
updateDeploymentStatus,
|
||||||
} from "@dokploy/server/services/deployment";
|
} from "@dokploy/server/services/deployment";
|
||||||
|
import { findVolumeBackupById } from "@dokploy/server/services/volume-backups";
|
||||||
import {
|
import {
|
||||||
execAsync,
|
execAsync,
|
||||||
execAsyncRemote,
|
execAsyncRemote,
|
||||||
} from "@dokploy/server/utils/process/execAsync";
|
} from "@dokploy/server/utils/process/execAsync";
|
||||||
import { backupVolume } from "./backup";
|
import { scheduledJobs, scheduleJob } from "node-schedule";
|
||||||
import { getS3Credentials, normalizeS3Path } from "../backups/utils";
|
import { getS3Credentials, normalizeS3Path } from "../backups/utils";
|
||||||
|
import { backupVolume } from "./backup";
|
||||||
|
|
||||||
export const scheduleVolumeBackup = async (volumeBackupId: string) => {
|
export const scheduleVolumeBackup = async (volumeBackupId: string) => {
|
||||||
const volumeBackup = await findVolumeBackupById(volumeBackupId);
|
const volumeBackup = await findVolumeBackupById(volumeBackupId);
|
||||||
@@ -76,7 +78,20 @@ export const runVolumeBackup = async (volumeBackupId: string) => {
|
|||||||
|
|
||||||
await updateDeploymentStatus(deployment.deploymentId, "done");
|
await updateDeploymentStatus(deployment.deploymentId, "done");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
const { VOLUME_BACKUPS_PATH } = paths(!!serverId);
|
||||||
|
const volumeBackupPath = path.join(
|
||||||
|
VOLUME_BACKUPS_PATH,
|
||||||
|
volumeBackup.appName,
|
||||||
|
);
|
||||||
|
// delete all the .tar files
|
||||||
|
const command = `rm -rf ${volumeBackupPath}/*.tar`;
|
||||||
|
if (serverId) {
|
||||||
|
await execAsyncRemote(serverId, command);
|
||||||
|
} else {
|
||||||
|
await execAsync(command);
|
||||||
|
}
|
||||||
await updateDeploymentStatus(deployment.deploymentId, "error");
|
await updateDeploymentStatus(deployment.deploymentId, "error");
|
||||||
|
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user