fix(restore): drop USE/CREATE DATABASE statements so mysql/mariadb restores target the selected database - #4967
Merged
Conversation
…stores target the selected database
narcisonunez
approved these changes
Aug 11, 2026
Collaborator
There was a problem hiding this comment.
Approving — works correctly for all dokploy-generated backups. One edge case: if an externally-created dump uses --add-drop-database, the DROP DATABASE statement won't get filtered and could still hit the wrong target. Not blocking, but happy to extend the regex to cover drop database in a follow-up PR if it ever comes up.
grep -viE '^[[:space:]]*(use|(create|drop)[[:space:]]+database)[[:space:]]'
pull Bot
pushed a commit
to tqa24/dokploy
that referenced
this pull request
Aug 14, 2026
…tements fix(restore): drop USE/CREATE DATABASE statements so mysql/mariadb restores target the selected database (cherry picked from commit ce0fe63) [skip ci]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3436
Dumps taken with
--databases(or brought from another instance) containUSE \source_db`;— the restore pipeline piped them verbatim intomariadb/mysql <target_db>, so every statement after theUSE` executed against the source database instead of the one selected in the restore dialog. In the reported case this overwrote a production database.The fix inserts a line filter between
gunzipand the client for mysql/mariadb restores that dropsUSE/CREATE DATABASEstatements, so the whole dump applies to the database passed on the command line. String values are safe:mysqldump/mariadb-dumpescape newlines inside values, so data lines can never start with these keywords.Verified against a real MariaDB 11 container: before the fix, restoring a
--databasesdump intodev_dboverwroteproduction_dband leftdev_dbempty; after the fix,production_dbis untouched anddev_dbreceives the data.Greptile Summary
This PR prevents MySQL and MariaDB restores from redirecting writes to a database named inside the dump.
USEandCREATE DATABASEstatements from MySQL/MariaDB restore streams.Confidence Score: 5/5
The PR appears safe to merge, with no actionable changed-code defects identified.
The filter covers the database-selection statements emitted by the supported MariaDB dump path, remains a harmless pass-through for ordinary SQL, and is limited to MySQL and MariaDB restores.
Reviews (1): Last reviewed commit: "fix(restore): drop USE/CREATE DATABASE s..." | Re-trigger Greptile
Context used: