Skip to content

Commit c6ab76f

Browse files
committed
fix(volume-backups): preserve backup failure status
1 parent 2598a62 commit c6ab76f

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

‎apps/dokploy/__test__/backups/volume-backup-restart.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,39 @@ describe("createRestartSafeBackupCommand", () => {
2828
expect(outputLines(result.stdout)).toEqual(["stop", "backup", "start"]);
2929
});
3030

31+
it("preserves the backup error status when the restart also fails", () => {
32+
const result = runCommand(
33+
createRestartSafeBackupCommand({
34+
stopCommand: 'echo "stop"',
35+
backupCommand: 'echo "backup"; exit 23',
36+
startCommand: 'echo "start"; exit 17',
37+
uploadCommand: 'echo "upload"',
38+
}),
39+
);
40+
41+
expect(result.status).toBe(23);
42+
expect(outputLines(result.stdout)).toEqual([
43+
"stop",
44+
"backup",
45+
"start",
46+
"Service restart also failed with exit code 17",
47+
]);
48+
});
49+
50+
it("returns the restart error status when the backup succeeds", () => {
51+
const result = runCommand(
52+
createRestartSafeBackupCommand({
53+
stopCommand: 'echo "stop"',
54+
backupCommand: 'echo "backup"',
55+
startCommand: 'echo "start"; exit 17',
56+
uploadCommand: 'echo "upload"',
57+
}),
58+
);
59+
60+
expect(result.status).toBe(17);
61+
expect(outputLines(result.stdout)).toEqual(["stop", "backup", "start"]);
62+
});
63+
3164
it("uploads only after a successful backup and service restart", () => {
3265
const result = runCommand(
3366
createRestartSafeBackupCommand({

‎packages/server/src/utils/volume-backups/backup.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,21 @@ export const createRestartSafeBackupCommand = ({
2828
${backupCommand}
2929
)
3030
DOKPLOY_VOLUME_BACKUP_STATUS=$?
31+
(
32+
set -e
33+
${startCommand}
34+
)
35+
DOKPLOY_VOLUME_RESTART_STATUS=$?
3136
set -e
32-
${startCommand}
3337
if [ "$DOKPLOY_VOLUME_BACKUP_STATUS" -ne 0 ]; then
38+
if [ "$DOKPLOY_VOLUME_RESTART_STATUS" -ne 0 ]; then
39+
echo "Service restart also failed with exit code $DOKPLOY_VOLUME_RESTART_STATUS"
40+
fi
3441
exit "$DOKPLOY_VOLUME_BACKUP_STATUS"
3542
fi
43+
if [ "$DOKPLOY_VOLUME_RESTART_STATUS" -ne 0 ]; then
44+
exit "$DOKPLOY_VOLUME_RESTART_STATUS"
45+
fi
3646
${uploadCommand}
3747
`;
3848

0 commit comments

Comments
 (0)