Merge pull request #4967 from Dokploy/fix/restore-drop-use-statements

fix(restore): drop USE/CREATE DATABASE statements so mysql/mariadb restores target the selected database

(cherry picked from commit ce0fe63b4a)

[skip ci]
This commit is contained in:
Narciso E. Núñez Arias
2026-08-10 23:40:10 -04:00
committed by Dokploy Bot
parent 19958ee9d9
commit 2003886aa0
2 changed files with 64 additions and 1 deletions
+7 -1
View File
@@ -79,6 +79,10 @@ const generateRestoreCommand = (
}
};
// Dumps taken with `--databases` carry `USE`/`CREATE DATABASE` statements that
// would redirect the restore away from the database selected in the dialog.
export const stripDatabaseSwitchCommand = `grep -viE '^[[:space:]]*(use|create[[:space:]]+database)[[:space:]]'`;
const getMongoSpecificCommand = (
rcloneCommand: string,
restoreCommand: string,
@@ -125,7 +129,9 @@ export const getRestoreCommand = ({
const restoreCommand = generateRestoreCommand(type, credentials);
let cmd = `CONTAINER_ID=$(${containerSearch})`;
if (type !== "mongo") {
if (type === "mysql" || type === "mariadb") {
cmd += ` && ${rcloneCommand} | ${stripDatabaseSwitchCommand} | ${restoreCommand}`;
} else if (type !== "mongo") {
cmd += ` && ${rcloneCommand} | ${restoreCommand}`;
} else {
cmd += ` && ${getMongoSpecificCommand(rcloneCommand, restoreCommand, backupFile || "")}`;