feat: route web-server backups through generic destinations

This commit is contained in:
Furox 2026-09-04 20:23:35 +03:00 committed by Furox88
parent 1753a3e1df
commit 31be3b98dc

View File

@ -13,10 +13,15 @@ import {
updateDeploymentStatus,
} from "@dokploy/server/services/deployment";
import { findDestinationById } from "@dokploy/server/services/destination";
import { quote } from "shell-quote";
import { sendDokployBackupNotifications } from "../notifications/dokploy-backup";
import { execAsync } from "../process/execAsync";
import { redactRcloneCredentials } from "./redact";
import { getBackupTimestamp, getS3Credentials, normalizeS3Path } from "./utils";
import {
getBackupTimestamp,
getRclonePathAndFlags,
normalizeS3Path,
} from "./utils";
function formatBytes(bytes?: number) {
if (bytes === undefined) return "Unknown size";
@ -41,12 +46,13 @@ export const runWebServerBackup = async (backup: BackupSchedule) => {
let computedBackupSize: number | undefined;
try {
const destination = await findDestinationById(backup.destinationId);
const rcloneFlags = getS3Credentials(destination);
const timestamp = getBackupTimestamp();
const { BASE_PATH } = paths();
const tempDir = await mkdtemp(join(tmpdir(), "dokploy-backup-"));
const backupFileName = `webserver-backup-${timestamp}.zip`;
const s3Path = `:s3:${destination.bucket}/${backup.appName}/${normalizeS3Path(backup.prefix)}${backupFileName}`;
const destinationPath = `${backup.appName}/${normalizeS3Path(backup.prefix)}${backupFileName}`;
const { flags: rcloneFlags, path: rcloneDestination } =
await getRclonePathAndFlags(destination, destinationPath);
try {
await execAsync(`mkdir -p ${tempDir}/filesystem`);
@ -114,10 +120,10 @@ export const runWebServerBackup = async (backup: BackupSchedule) => {
// If stat fails, keep undefined
}
const uploadCommand = `rclone copyto ${rcloneFlags.join(" ")} "${zipPath}" "${s3Path}"`;
writeStream.write("Running command to upload backup to S3\n");
const uploadCommand = `rclone copyto ${rcloneFlags.join(" ")} ${quote([zipPath])} ${quote([rcloneDestination])}`;
writeStream.write("Running command to upload backup to destination\n");
await execAsync(uploadCommand);
writeStream.write("Uploaded backup to S3 ✅\n");
writeStream.write("Uploaded backup to destination ✅\n");
writeStream.end();
await sendDokployBackupNotifications({
type: "success",