Can you show the database part of your env file (hide your password!) + the config for the used database in /config/database.php ?
Spatie Laravel Backup not working on server
I deployed my project to a shared host with Spatie Laravel Backup package but it is not working. I run this command:
php artisan backup:run --disable-notifications --only-db
It gives me this error:
Dumping database mountdu8_tamizandik...
Backup failed because The dump process failed with a none successful exitcode.
Exitcode
========
2: Misuse of shell builtins
Output
======
<no output>
Error Output
============
mysqldump: Got error: 1045: Access denied for user 'mountdu8_finance'@'localhost' (using password: YES) when trying to connect
my database name is mountdu8_tamizandik but it asks for user mountdu8_finance, I don't know why.
I don't have mountdu8_finance user on the server.
locally it works fine.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mountdu8_tamizandik
DB_USERNAME=mountdu8_tamizandik
DB_PASSWORD=
and database.php
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => 'InnoDB',
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
@Armani Be aware that mountdu8_finance is the username, not the database
Can you try php artisan config:clear
@Sinnbeck Yes I set it but I did not provide a first, I know that is a username.
I run php artisan config:clear but nothing changed, I think config is not cached at all
@Armani Can you check the /config/backup.php file, to see which databases it is set to backup?
Something like this
'databases' => [
'mysql',
],
@Sinnbeck It is just this line:
'databases' => [
'mysql',
],
@Armani Can you try starting php artisan tinker on the server. Then put in config('database.connections.mysql');
Do you get the correct username here?
@Sinnbeck Yes it gives me the correct username and password
@Armani And if you run the command again, it still gives the wrong username?
@Sinnbeck Unfortunately yes
@Armani If you run the commands directly, does it work then? You can see this post for which commands it runs under the hood: https://github.com/spatie/laravel-backup/issues/92
It is something like
mysqldump -umyusr -pmypwd --database dbname
@Sinnbeck I logged in using SSH and tried to run the mysql command but it gives me error:
syntax error near unexpected token `)'
@Armani How were you running the artisan command if you didnt log in with SSH? What was the command you ran?
Any chance there is a ) in your password?
@Sinnbeck I run the same command you provided with my username and password and database name.
Yes I have )
@Armani Try this then
mysqldump -umyusr -p --database dbname
This should promt you for your password
@Sinnbeck It says:
[ERROR] unknown option '--database'
@Armani Ok try this then
mysqldump dbname -umyusr -p
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysqldump mountdu8_tamizandik -u mountdu8_tamizandik -p' at line 1
@Armani Did you run it inside your sql console instead of on the CLI?
@Sinnbeck I connected to server using SSH and PuTTY. and I logged into MySQL user mountdu8_tamizandik, then run the command
@Armani Skip this part and try again
I logged into MySQL user mountdu8_tamizandik
It is the same place where you run php artisan backup:run --disable-notifications --only-db
@Sinnbeck This syntax worked for me:
mysqldump -u mountdu8_tamizandik -p mountdu8_tamizandik
@Armani Just to make sure. You are running the php artisan backup:run --disable-notifications --only-db command in that same SSH connection?
@Sinnbeck Yes it is the same connection, I can run all artisan commands on the server.
@Armani Then I sadly don't know. If mountdu8_finance is completely unknow to you, I have no clue where it comes from
Aha! I think I found the issue. The way the package works is by creating a conf file where it can read the credentials from. My guess is that mountdu8_finance is some other user on the server, and you are for some reason sharing that credentials file :/
I am currently investigating where it stores that file
@Sinnbeck I even tried this:
$schedule->command(\Spatie\DbDumper\Databases\MySql::create()
->setDbName('mountdu8_tamizandik')
->setUserName('mountdu8_tamizandik')
->setPassword('')
->dumpToFile('dump.sql'))->daily();
But it gives me the same error.
@Armani Yeah. Its the DbDumper that makes the file :)
Can you try this in php artisan tinker on the server?
stream_get_meta_data(tmpfile())['uri'];
Does this return a different path each time?
@Sinnbeck Yes it does:
stream_get_meta_data(tmpfile())['uri']
=> "/tmp/phpo73Y0h"
>>> stream_get_meta_data(tmpfile())['uri']
=> "/tmp/phpGCzDQu"
>>> stream_get_meta_data(tmpfile())['uri']
=> "/tmp/phpvQaP4P"
@Armani Really really strange then! Are you using the latest version of the package? I am thinking if it was changed at some point.
It really seems that you are getting the file of some other user :/
@Sinnbeck I'm using latest version:
"spatie/laravel-backup": "^8.1"
I can not access other user files. I don't understand.
@Armani From what I understand you dont know anything about mountdu8_finance and this is a shared server. And I assume that the host have given you this username mountdu8_tamizandik. So my guess is that you for some reason are getting the credentials file of another user (the user who owns mountdu8_finance). Why this is happening I don't know, but it is concerning.
@Sinnbeck But why every Laravel functionality works except this package.
@Armani Yes. But no other packages are creating a file like that I would assume.
Can you check one thing. When you log in using ssh. Is there a .my.cnf file present on the server?
@Sinnbeck Yes it is a file named .my.cnf
@Armani does it contain a username and password? Are they yours? Does it suddenly start working if you rename that file?
@Sinnbeck Yes it is not my username and password, Can I rename the file? Can I change the username and password?
@Armani yes
mv oldname new
@Sinnbeck I edited the file and used my credentials and now it works fine.
@Armani exelent. Removing or renaming it would probably solve the problem as well. But worrying that it had someone else's credentials.
Please mark a best answer to set the thread as solved
Please or to participate in this conversation.