mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-18 13:45:23 +02:00
* refactor: improve restore logging for database backups - Updated restore functions across various database types (Postgres, MySQL, MongoDB, MariaDB, LibSQL, and Compose) to provide clearer logging messages. - Replaced generic command execution logs with specific messages indicating the database being restored and the source backup file. - This change enhances the clarity of restore operations and aids in troubleshooting by providing more context in the logs. * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import type { apiRestoreBackup } from "@dokploy/server/db/schema";
|
|
import type { Destination } from "@dokploy/server/services/destination";
|
|
import type { Libsql } from "@dokploy/server/services/libsql";
|
|
import type { z } from "zod";
|
|
import { getS3Credentials, getServiceContainerCommand } from "../backups/utils";
|
|
import { execAsync, execAsyncRemote } from "../process/execAsync";
|
|
|
|
export const restoreLibsqlBackup = async (
|
|
libsql: Libsql,
|
|
destination: Destination,
|
|
backupInput: z.infer<typeof apiRestoreBackup>,
|
|
emit: (log: string) => void,
|
|
) => {
|
|
try {
|
|
const { appName, serverId } = libsql;
|
|
|
|
const rcloneFlags = getS3Credentials(destination);
|
|
const bucketPath = `:s3:${destination.bucket}`;
|
|
|
|
const backupPath = `${bucketPath}/${backupInput.backupFile}`;
|
|
|
|
const rcloneCommand = `rclone cat ${rcloneFlags.join(" ")} "${backupPath}"`;
|
|
|
|
const containerSearch = getServiceContainerCommand(appName);
|
|
const restoreCommand = `docker exec -i $CONTAINER_ID sh -c "tar xzf - -C /var/lib/sqld"`;
|
|
|
|
const command = `CONTAINER_ID=$(${containerSearch}) && ${rcloneCommand} | ${restoreCommand}`;
|
|
|
|
emit("Starting restore...");
|
|
emit(`Restoring libsql from ${backupInput.backupFile}`);
|
|
|
|
if (serverId) {
|
|
await execAsyncRemote(serverId, command);
|
|
} else {
|
|
await execAsync(command);
|
|
}
|
|
|
|
emit("Restore completed successfully!");
|
|
} catch (error) {
|
|
emit(
|
|
`Error: ${
|
|
error instanceof Error ? error.message : "Error restoring libsql backup"
|
|
}`,
|
|
);
|
|
throw error;
|
|
}
|
|
};
|