Cms: Can't backup DB from admin on Valet

Created on 5 Dec 2019  路  6Comments  路  Source: craftcms/cms

Description

Unable to back-up the database from the Craft admin locally on Laravel Valet.

Steps to reproduce

  1. Press Backup button in Database Backup
  2. Get "There was a problem backing up your database. Please check the Craft logs." error.

Additional info

  • Craft version: 3.3.17 (Pro Trial)
  • PHP version: 7.4.0
  • Database driver & version: MySQL 5.7.28
  • Plugins & versions: n/a

I've read through many similar issues regarding this and I think I've found where the problem is (vaguely) but I'm not sure where to go from here.

Here's a few things I know:

  • mysqldump is present and can be found
  • I can successfully backup the DB on the CLI using ./craft backup
  • I can successfully run the command (slightly tweaked) that Craft runs when I hit the Backup button

On that last one, here's what I see in the error logs:

Could not create backup: The shell command "mysqldump --defaults-extra-file="/Users/ryan/Git/Beanstalk/clientname/storage/runtime/temp/my.cnf" --add-drop-table --comments --create-options --dump-date --no-autocommit --routines --set-charset --triggers --single-transaction --no-data --result-file="/Users/ryan/Git/Beanstalk/clientname/storage/backups/step-change-in-safety_191205_201550_p87yyvfon1_v3.3.17.sql" clientname && mysqldump --defaults-extra-file="/Users/ryan/Git/Beanstalk/clientname/storage/runtime/temp/my.cnf" --add-drop-table --comments --create-options --dump-date --no-autocommit --routines --set-charset --triggers --no-create-info --ignore-table=clientname.assetindexdata --ignore-table=clientname.assettransformindex --ignore-table=clientname.sessions --ignore-table=clientname.templatecaches --ignore-table=clientname.templatecachequeries --ignore-table=clientname.templatecacheelements --ignore-table=clientname.cache --ignore-table=clientname.templatecachecriteria clientname >> "/Users/ryan/Git/Beanstalk/clientname/storage/backups/step-change-in-safety_191205_201550_p87yyvfon1_v3.3.17.sql"" failed with exit code 127: sh: mysqldump: command not found in /Users/ryan/Git/Beanstalk/clientname/vendor/craftcms/cms/src/controllers/UtilitiesController.php:343

The mysqldump command can be found so something else is wrong (maybe). I kept an eye on the "storage/runtime/temp/" directory while pressing the Backup button and noticed the "my.cnf" file is created then instantly deleted.

So I took the above failed command, manually created a "my.cnf" file, pointed the command to that and then ran it from the command line. i.e. this:

mysqldump --defaults-extra-file="./my.cnf" --add-drop-table --comments --create-options --dump-date --no-autocommit --routines --set-charset --triggers --single-transaction --no-data --result-file="/Users/ryan/Git/Beanstalk/clientname/storage/backups/step-change-in-safety_191205_201550_p87yyvfon1_v3.3.17.sql" clientname && mysqldump --defaults-extra-file="./my.cnf" --add-drop-table --comments --create-options --dump-date --no-autocommit --routines --set-charset --triggers --no-create-info --ignore-table=clientname.assetindexdata --ignore-table=clientname.assettransformindex --ignore-table=clientname.sessions --ignore-table=clientname.templatecaches --ignore-table=clientname.templatecachequeries --ignore-table=clientname.templatecacheelements --ignore-table=clientname.cache --ignore-table=clientname.templatecachecriteria clientname >> "/Users/ryan/Git/Beanstalk/clientname/storage/backups/step-change-in-safety_191205_201550_p87yyvfon1_v3.3.17.sql"

馃挜It works!

So this is where I am, there's something going on with the my.cnf file Craft creates in the temp storage directory that prevents the command from being run.

Any ideas out there?

TIA

Most helpful comment

@RyanRoberts Here is a way to keep things walled off per environment -- by keeping the full paths to mysql and mysqldump in the .env file: https://packagist.org/packages/samhernandez/craft-db-paths. Same issue affects MAMP users.

All 6 comments

Hrm... not super-familiar with Valet, unfortunately.

If you create a test.php file in your public HTML folder, then put this in it:

<?php passthru('echo $PATH')

Then load that in a browser, does the path that gets output include the path to where mysqldump is located?

That's interesting, I get /usr/gnu/bin:/usr/local/bin:/bin:/usr/bin:. which is not the same as echo $PATH in the terminal.

The output from test.php doesn't have mysqldump's location (but the "normal" $PATH does).

That reminded me of an Issue I saw yesterday, adding putenv("PATH={$_SERVER["PATH"]}:/usr/local/opt/[email protected]/bin"); to the general.php config appears to solve the problem!

Now I just need to only have that locally and not get committed to staging and production 馃
[edit] sorted that out, everything now works 馃憤

Thanks for tip Brad.

Awesome... glad you're all sorted, @RyanRoberts!

@RyanRoberts Here is a way to keep things walled off per environment -- by keeping the full paths to mysql and mysqldump in the .env file: https://packagist.org/packages/samhernandez/craft-db-paths. Same issue affects MAMP users.

@RyanRoberts Here is a way to keep things walled off per environment -- by keeping the full paths to mysql and mysqldump in the .env file: https://packagist.org/packages/samhernandez/craft-db-paths. Same issue affects MAMP users.

Thanks! That looks great.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

michel-o picture michel-o  路  3Comments

angrybrad picture angrybrad  路  3Comments

michaelhue picture michaelhue  路  3Comments

lukebailey picture lukebailey  路  3Comments

RitterKnightCreative picture RitterKnightCreative  路  3Comments