MCPcopy
hub / github.com/Dokploy/dokploy / runComposeBackup

Function runComposeBackup

packages/server/src/utils/backups/compose.ts:19–81  ·  view source on GitHub ↗
(
	compose: Compose,
	backup: BackupSchedule,
)

Source from the content-addressed store, hash-verified

17} from "./utils";
18
19export const runComposeBackup = async (
20 compose: Compose,
21 backup: BackupSchedule,
22) => {
23 const { environmentId, name, appName } = compose;
24 const environment = await findEnvironmentById(environmentId);
25 const project = await findProjectById(environment.projectId);
26 const { prefix, databaseType, serviceName } = backup;
27 const destination = await findDestinationById(backup.destinationId);
28 const backupFileName = `${getBackupTimestamp()}.${databaseType === "mongo" ? "bson" : "sql"}.gz`;
29 const s3AppName = serviceName ? `${appName}_${serviceName}` : appName;
30 const bucketDestination = `${s3AppName}/${normalizeS3Path(prefix)}${backupFileName}`;
31 const deployment = await createDeploymentBackup({
32 backupId: backup.backupId,
33 title: "Compose Backup",
34 description: "Compose Backup",
35 });
36
37 try {
38 const rcloneFlags = getS3Credentials(destination);
39 const rcloneDestination = `:s3:${destination.bucket}/${bucketDestination}`;
40 const rcloneCommand = `rclone rcat ${rcloneFlags.join(" ")} "${rcloneDestination}"`;
41
42 const backupCommand = getBackupCommand(
43 backup,
44 rcloneCommand,
45 deployment.logPath,
46 );
47 if (compose.serverId) {
48 await execAsyncRemote(compose.serverId, backupCommand);
49 } else {
50 await execAsync(backupCommand, {
51 shell: "/bin/bash",
52 });
53 }
54
55 await sendDatabaseBackupNotifications({
56 applicationName: name,
57 projectName: project.name,
58 databaseType: getDatabaseType(databaseType),
59 type: "success",
60 organizationId: project.organizationId,
61 databaseName: backup.database,
62 });
63
64 await updateDeploymentStatus(deployment.deploymentId, "done");
65 } catch (error) {
66 console.log(error);
67 await sendDatabaseBackupNotifications({
68 applicationName: name,
69 projectName: project.name,
70 databaseType: getDatabaseType(databaseType),
71 type: "error",
72 // @ts-ignore
73 errorMessage: error?.message || "Error message not provided",
74 organizationId: project.organizationId,
75 databaseName: backup.database,
76 });

Callers 3

scheduleBackupFunction · 0.90
backup.tsFile · 0.90
runJobsFunction · 0.90

Calls 13

findEnvironmentByIdFunction · 0.90
findProjectByIdFunction · 0.90
findDestinationByIdFunction · 0.90
getBackupTimestampFunction · 0.90
normalizeS3PathFunction · 0.90
createDeploymentBackupFunction · 0.90
getS3CredentialsFunction · 0.90
getBackupCommandFunction · 0.90
execAsyncRemoteFunction · 0.90
execAsyncFunction · 0.90
updateDeploymentStatusFunction · 0.90

Tested by

no test coverage detected