mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-11 14:35:17 +00:00
Refactor backup and restore utilities for improved container handling
- Removed the `getRemoteServiceContainer` function and updated the `getServiceContainer` function to handle both local and remote service containers more efficiently. - Refactored backup and restore commands for MariaDB, MongoDB, MySQL, and PostgreSQL to utilize new utility functions for generating backup and restore commands, enhancing code clarity and maintainability. - Streamlined command execution logic in backup and restore processes, ensuring consistent handling of container IDs across different database types.
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
import type { Destination } from "@dokploy/server/services/destination";
|
||||
import type { Mariadb } from "@dokploy/server/services/mariadb";
|
||||
import { getS3Credentials } from "../backups/utils";
|
||||
import {
|
||||
getRemoteServiceContainer,
|
||||
getServiceContainer,
|
||||
} from "../docker/utils";
|
||||
import { getServiceContainer } from "../docker/utils";
|
||||
import { execAsync, execAsyncRemote } from "../process/execAsync";
|
||||
import { getMariadbRestoreCommand } from "./utils";
|
||||
|
||||
export const restoreMariadbBackup = async (
|
||||
mariadb: Mariadb,
|
||||
@@ -21,22 +19,27 @@ export const restoreMariadbBackup = async (
|
||||
const bucketPath = `:s3:${destination.bucket}`;
|
||||
const backupPath = `${bucketPath}/${backupFile}`;
|
||||
|
||||
const { Id: containerName } = serverId
|
||||
? await getRemoteServiceContainer(serverId, appName)
|
||||
: await getServiceContainer(appName);
|
||||
const { Id: containerId } = await getServiceContainer(appName, serverId);
|
||||
|
||||
const restoreCommand = `
|
||||
rclone cat ${rcloneFlags.join(" ")} "${backupPath}" | gunzip | docker exec -i ${containerName} mariadb -u ${databaseUser} -p${databasePassword} ${database}
|
||||
const restoreCommand = getMariadbRestoreCommand(
|
||||
containerId,
|
||||
database,
|
||||
databaseUser,
|
||||
databasePassword || "",
|
||||
);
|
||||
|
||||
const command = `
|
||||
rclone cat ${rcloneFlags.join(" ")} "${backupPath}" | gunzip | ${restoreCommand}
|
||||
`;
|
||||
|
||||
emit("Starting restore...");
|
||||
|
||||
emit(`Executing command: ${restoreCommand}`);
|
||||
emit(`Executing command: ${command}`);
|
||||
|
||||
if (serverId) {
|
||||
await execAsyncRemote(serverId, restoreCommand);
|
||||
await execAsyncRemote(serverId, command);
|
||||
} else {
|
||||
await execAsync(restoreCommand);
|
||||
await execAsync(command);
|
||||
}
|
||||
|
||||
emit("Restore completed successfully!");
|
||||
|
||||
Reference in New Issue
Block a user