Laravel-backup: Issue with mysqldump - Could not open required defaults file: /tmp/phpmWxslE

Created on 25 Jan 2021  路  9Comments  路  Source: spatie/laravel-backup

Hello guys,
I'm experiencing an issue with the database backup feature.

`Backup failed because The dump process failed with exitcode 1 : General error : mysqldump: [ERROR] Could not open required defaults file: /tmp/phpmWxslE
mysqldump: [ERROR] Fatal error in defaults handling. Program aborted!
.

0 /home/vagrant/Code/app.test.it/vendor/spatie/db-dumper/src/DbDumper.php(263): Spatie\DbDumper\Exceptions\DumpFailed::processDidNotEndSuccessfully()

1 /home/vagrant/Code/app.test.it/vendor/spatie/db-dumper/src/Databases/MySql.php(197): Spatie\DbDumper\DbDumper->checkIfDumpWasSuccessFul()

2 /home/vagrant/Code/app.test.it/vendor/spatie/laravel-backup/src/Tasks/Backup/BackupJob.php(253): Spatie\DbDumper\Databases\MySql->dumpToFile()

3 [internal function]: Spatie\Backup\Tasks\Backup\BackupJob->Spatie\Backup\Tasks\Backup{closure}()

4 /home/vagrant/Code/app.test.it/vendor/laravel/framework/src/Illuminate/Support/Collection.php(638): array_map()

5 /home/vagrant/Code/app.test.it/vendor/spatie/laravel-backup/src/Tasks/Backup/BackupJob.php(256): Illuminate\Support\Collection->map()

6 /home/vagrant/Code/app.test.it/vendor/spatie/laravel-backup/src/Tasks/Backup/BackupJob.php(170): Spatie\Backup\Tasks\Backup\BackupJob->dumpDatabases()

7 /home/vagrant/Code/app.test.it/vendor/spatie/laravel-backup/src/Tasks/Backup/BackupJob.php(146): Spatie\Backup\Tasks\Backup\BackupJob->createBackupManifest()

8 /home/vagrant/Code/app.test.it/vendor/spatie/laravel-backup/src/Commands/BackupCommand.php(56): Spatie\Backup\Tasks\Backup\BackupJob->run()

9 /home/vagrant/Code/app.test.it/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Spatie\Backup\Commands\BackupCommand->handle()

10 /home/vagrant/Code/app.test.it/vendor/laravel/framework/src/Illuminate/Container/Util.php(37): Illuminate\Container\BoundMethod::Illuminate\Container{closure}()

11 /home/vagrant/Code/app.test.it/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()

12 /home/vagrant/Code/app.test.it/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()

13 /home/vagrant/Code/app.test.it/vendor/laravel/framework/src/Illuminate/Container/Container.php(596): Illuminate\Container\BoundMethod::call()

14 /home/vagrant/Code/app.test.it/vendor/laravel/framework/src/Illuminate/Console/Command.php(134): Illuminate\Container\Container->call()

15 /home/vagrant/Code/app.test.it/vendor/symfony/console/Command/Command.php(258): Illuminate\Console\Command->execute()

16 /home/vagrant/Code/app.test.it/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\Component\Console\Command\Command->run()

17 /home/vagrant/Code/app.test.it/vendor/spatie/laravel-backup/src/Commands/BaseCommand.php(16): Illuminate\Console\Command->run()

18 /home/vagrant/Code/app.test.it/vendor/symfony/console/Application.php(920): Spatie\Backup\Commands\BaseCommand->run()

19 /home/vagrant/Code/app.test.it/vendor/symfony/console/Application.php(266): Symfony\Component\Console\Application->doRunCommand()

20 /home/vagrant/Code/app.test.it/vendor/symfony/console/Application.php(142): Symfony\Component\Console\Application->doRun()

21 /home/vagrant/Code/app.test.it/vendor/laravel/framework/src/Illuminate/Console/Application.php(93): Symfony\Component\Console\Application->run()

22 /home/vagrant/Code/app.test.it/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\Console\Application->run()

23 /home/vagrant/Code/app.test.it/artisan(37): Illuminate\Foundation\Console\Kernel->handle()

24 {main}

Backup failed because: The dump process failed with exitcode 1 : General error : mysqldump: [ERROR] Could not open required defaults file: /tmp/phpmWxslE
mysqldump: [ERROR] Fatal error in defaults handling. Program aborted!
`

If I manually perform the command mysqldump DB_NAME > test.sql it works as expected.
I'm running MySQL 5.7.29 and I have tried also on a droplet provisioned through Forge.

Any suggestion?

All 9 comments

The problem seems related with the generation of the temporaryCredentialsFile.
If I remove this option in the MySql.php file (line 239 - db-dumper package) the backup seems working correctly.
It looks like the package is not able to generate the temporary file with the credentials to be used in the command.

Any help for a better solution?

Same Here

Same issue on fresh install. Tested on MacOS and CentOS 7.

tmpfile() generates an unreadable file for the mysqldump process to open. src/Databases/MySQL.php line 336.

$tempFileHandle = tmpfile();

If this is swapped for a generic shared tmp space the file is available to the sub-process. tmpfile() appears to create a protected/isolated temporary file on certain OS's:

$tempFileHandle = fopen('/tmp/tmp','w');

Anyone following this thread DON'T copy that code, it won't destroy the temporary file - you'll leave and expose your credentials in /tmp!

Update:

I'm using the following for now. If you have permission to write to your base_path(), this will store a the credentials for mysqldump at the same level as the regular .env file. As per above, it will not delete it, but it will place it in a safer place than /tmp!

vendor/spatie/db-dumper/src/Databases/MySql.php - Line 336

//$tempFileHandle = tmpfile();
$tempFileHandle = fopen(base_path('.spatie_env'),'w');

same problem here

Same issue here after the underlying db-dumper package updated yesterday

I've tagged 2.20 of db-dumper that should solve the problem.

Closing this issue, but I'd appreciate if one of you can confirm that the issue is indeed solved.

@freekmurze Thank you so much for quick help :)
It works with me

@freekmurze hi freek. Yes, 2.20 is now successfully backed up my apps.

Thx for the prompt responses

Works like a charm!
Thanks @freekmurze !

Was this page helpful?
0 / 5 - 0 ratings