Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.3.3]: Using --defaults-extra in mysqldump causing backupcommand to fail #12349

Closed
jan-thoma opened this issue Nov 18, 2022 · 12 comments · Fixed by #12430
Closed

[4.3.3]: Using --defaults-extra in mysqldump causing backupcommand to fail #12349

jan-thoma opened this issue Nov 18, 2022 · 12 comments · Fixed by #12430
Assignees

Comments

@jan-thoma
Copy link

What happened?

Description

The argument --defaults-extra-file in the backup command reads in the standard config if present and let the command fail if another config is present.

Steps to reproduce

  1. Start a DDEV CraftCMS Project and connect to an external MySQL Database Service
  2. Try create a backup via console or admin interface
  3. The backup fails because it picks up the ~/.my.cnf file

Expected behavior

Craft should only read Credentials from it's own .env file. Therefore --defaults-file instead of --defaults-extra-file should be used

Actual behavior

CraftCMS chooses the credentials from ~/.my.cnf

Craft CMS version

4.3.3

PHP version

8.1

Operating system and version

DDEV

Database type and version

MySQL 5.7

Image driver and version

No response

Installed plugins and versions

@angrybrad
Copy link
Member

Just to make sure I'm following, you've got a .my.cnf file in your home directory that contains database credentials.

Craft's default backup command uses --defaults-extra-file to write its credentials out to a temp file, but that breaks if ~/.my.cnf is set and the fix that worked for you was to change the backup command to use --defaults-file instead?

@jan-thoma
Copy link
Author

Correct

@jan-thoma
Copy link
Author

@angrybrad
Copy link
Member

angrybrad commented Nov 21, 2022

@jan-thoma I'm assuming that the user creds in .my.cnf are different than the creds you've configured Craft to connect to the database in the .env file? Trying to fine a way to replicate this locally.

@angrybrad
Copy link
Member

Nermind... could replicate it - fixed for the next release!

@brandonkelly
Copy link
Member

Craft 4.3.4 is out with that fix.

@jan-thoma
Copy link
Author

The restore command is affected as well

#3 [internal function]: weareferal\remotesync\controllers\RemoteSyncController->actionPullDatabase()
#4 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#5 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#6 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('pull-database', Array)
#7 /var/www/html/vendor/craftcms/cms/src/web/Application.php(301): yii\base\Module->runAction('remote-sync/rem...', Array)
#8 /var/www/html/vendor/craftcms/cms/src/web/Application.php(625): craft\web\Application->runAction('remote-sync/rem...', Array)
#9 /var/www/html/vendor/craftcms/cms/src/web/Application.php(280): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#10 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#11 /var/www/html/web/index.php(26): yii\base\Application->run()
#12 {main} {"memory":3346872,"exception":"[object] (craft\\errors\\ShellCommandException(code: 0): The shell command \"mysql --defaults-extra-file=\"/tmp/mnrdmhrzhscn.cnf\" tkf < \"/var/www/html/storage/remote-sync/tkf__dev__221208_102731__hfjkojjkbp__v4.3.4.sql\"\" failed with exit code 1: ERROR 2005 (HY000): Unknown MySQL server host 'db' (-2) at /var/www/html/vendor/craftcms/cms/src/db/Connection.php:502)"} 

@brandonkelly
Copy link
Member

@jan-thoma Thanks for pointing that out! We released Craft 4.3.5 yesterday with a fix for DB restoring as well.

@pheeque1
Copy link

pheeque1 commented Jan 25, 2023

@brandonkelly
I believe the decision to ignore other user defined mysql option files for mysqldump might have been made too hastily. This is what happens when the --defaults-file option is used to specify the temporary configuration file instead of --defaults-extra-file option.

The OP is better off modifying the MySQL credentials defined in their .my.cnf config file rather than disabling it entirely.

Craft Copy needs it to set some configuration variables in order to maintain MySQL version incompatibilities.

I also doubt that Craft Copy is the only external library susceptible to this change.

@angrybrad
Copy link
Member

@pheeque1 I doubt we’ll find a default backup command that pleases everyone, but that command is 100% customizable via the https://craftcms.com/docs/4.x/config/general.html#backupcommand config setting, and Craft will respect that setting, so people can customize it as they need on a case-by-case basis.

@davidwebca
Copy link
Contributor

Hi @angrybrad! I just encountered an issue where I learned that some shared hosts and vps hosts don't allow writing to the core system tmp file folder and so the backup command fails without error message because of sys_get_temp_dir in the _createDumpConfigFile(). It seems that writing to the system tmp file isn't universally recognized. Could an .env variable be added so that we can simply override when encountering this issue? Should I open a new issue or would you prefer reopening this one? Thanks!

@angrybrad
Copy link
Member

@davidwebca could you make a new issue, please? I'll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants