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

This commit is contained in:
Mauricio Siu
2026-08-04 11:34:08 -06:00
parent a0162ab566
commit 2505c347bc
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 || "")}`;