Laravel-backup: Misuse of shell builtins.

Created on 16 Mar 2016  ·  27Comments  ·  Source: spatie/laravel-backup

Hi,
I got this problem when running backup:run

Starting backup... Dumping database prostats_db... Backup failed because The dump process failed with exitcode 2 : Misuse of shell builtins. Backup completed!

I'm running on L5.2, PHP5.6 and Debian 8

Most helpful comment

I'll update our documentation to make it more clear that it should only be the path to the binary that should be filled in.

All 27 comments

Could you try running a shell command via php?

Yes i can

Could you try calling mysqldump specifically through php?

Yes i can do that too, through system()

Could you try running a command using symfony/process

http://symfony.com/doc/current/components/process.html

I have the same problem with two environments:
codeanywhere dev-box: Ubuntu 14.04 with PHP 5.5.9 - Laravel 5.2
digitalocean droplet: Ubuntu 14.04 with PHP 5.5.9 - Laravel 5.2

php artisan backup:run --only-files works! I guess it uses symfony/process too.

I think it's a problem with mysqlbackup.

mysqldump -umyusr -pmypwd --database dbname works.

php -r "system('mysqldump -umyusr -pmypwd dbname');" works too.

But php artisan backup:run --only-db fails.

--only-files doesn't use symfony process. Could you try if dumping the db using spatie/db-dumper works? (That package is used under the hood of laravel-backup)

Another two tests:

File backuptest.php:
<?php
include 'vendor/autoload.php';
Spatie\DbDumper\Databases\MySql::create()
->setDbName('dbname')
->setUserName('myusr')
->setPassword('mypwd')
->dumpToFile('test.sql');

php backuptest.php Works fine! (spatie/db-dumper version 1.2.2)
)

File symfonytest.php:
<?php
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
$process = new Process('mysqldump -umyusr -pmypwd dbname');
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();

php symfonytest.php Was successful too. (symfony/process version 3.0.3)

Thank you for running these tests. I'm a bit stumped because under the hood laravel-backup does what you've done in your tests.

Are you running your tests and laravel-backup on the command line?

Yes, i used the same shell for this three commands:

me@server:/path/to/approot$ php artisan backup:run
me@server:/path/to/approot$ php backuptest.php
me@server:/path/to/approot$ php symfonytest.php

Wild guess—

Could you edit lines 173-178 in vendor/spatie/db-dumper/src/Databases/MySql.php:

$command = [
    "{$this->dumpBinaryPath}mysqldump",
    "-h {$this->host}",
    "--defaults-extra-file={$temporaryCredentialsFile}",
    '--skip-comments',
    $this->useExtendedInserts ? '--extended-insert' : '--skip-extended-insert',
];

(added that -h flag)

The -h flag was not the problem... PEBCAK!
I configured usr/bin/mysqldump for dump_command_path in config/database.php.

I'm very sorry for the inconvenience... -.-

@yadounis Perhaps you did the same.

I'll update our documentation to make it more clear that it should only be the path to the binary that should be filled in.

@heikoeln can you please give me more details on how you solved this issue ? Your answer is not clear for me. Thanks.

@yadounis
I configured 'dump_command_path' => '/usr/bin/mysqldump', in config/database.php.

But this is right (path only):
'mysql' => [
'driver' => 'mysql',
'dump_command_path' => '/usr/bin',
[...]
],

Both are not working for me, still have the same issue !

capture d ecran 2016-03-23 a 09 29 49

capture d ecran 2016-03-23 a 09 31 11

@yadounis
Your config is still wrong.
Change it to 'dump_command_path' => '/usr/bin',
(without mysqldump)

I tested both configs :
'dump_command_path' => '/usr/bin'
and
'dump_command_path' => '/usr/bin/mysqldump'

and both are resulting with the same error

Ah ok. I understand. Path only is the only way that shoud work.
Are you sure that the conifgured mysql user has the minimum grants for mysqldump? Esp. LOCK TABLES is needed.

Yes, it was a privilages issue, its worked when i used the mysql root.

thanks :+1:

和环境是有关系的,如果laravel是在Homestead环境下,必须要进入虚拟机里面执行

vagrant ssh
cd /path
php artisan backup:run

I am facing the same issue in Laravel 5.7, php 7.1.
Will someone kindly update ?

What privileges it needs?

Got a solution.
Place your laravel application inside xamp(htdocs) or wamp

stop php artisan serve

then enter following in your browser

localhost/My_APP_NAME/public

Was having this same issue on a production server.

The dump process failed with exitcode 2 : Misuse of shell builtins : mysqldump: Got error: 1045: "Access denied for user 'user'@'localhost' (using password: YES)" when trying to connect

I eventually solved it by updating the database user's password and removing special characters such as #.

After digging on the spatie/db-dumper library, it seems that the --defaults-extra-file on here doesn't work for me. Always returning this error:

Backup failed because The dump process failed with exitcode 2 : Misuse of shell builtins : mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES)...

I tried changing it to --defaults-file and now its working fine. Not sure what happened behind-the-scene. Can someone enlighten me?

My Setup:

"laravel/framework": "5.1.*",
"spatie/laravel-backup": "^3.0.0",

PS: This is an old project and haven't upgraded the Laravel version since.
Edit: Related issue

add if you xampp: /Applications/Xampp/bin
if you using Mamp: /Applications/Mamp/Library/bin

Was this page helpful?
0 / 5 - 0 ratings