diff --git a/packages/server/src/utils/backups/web-server.ts b/packages/server/src/utils/backups/web-server.ts index aae90a5bf..5fa1336dd 100644 --- a/packages/server/src/utils/backups/web-server.ts +++ b/packages/server/src/utils/backups/web-server.ts @@ -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",