Backup doesn't work

Published 6 months ago by adnan483

I'm using paulvl/backup backup package, when I try to use it from Terminal:

php artisan backup:mysql-dump

it works perfect and store it inside of /storage/app/backups but when try to use it from controller

public function store(){
        Artisan::call('backup:mysql-dump');
    }

it doesn't work?

BezhanSalleh

@ADNAN483 what does it show, error or anything?

adnan483

@Yama Nothing, there is no error. when I use dd() it shows only 0.

BezhanSalleh

@adnan483

Route::get('/backup_database', function(){
    \Artisan::call('backup:mysql-dump');
    return 'database backed up';
});

the problem might be in how you are making the request... try the above snippet,check your storage/app/ there should be a file named yourdb_timestamp.sql if you haven't changed the default path in config/backup.php and then see where and what is not working in your code... you haven't posted your route or how you are trying to get the backup...

adnan483

@Yama The same problem again, it shows database backed up but it's not, I tried as return \Artisan::output() and got this 'Database 'test' cannot be dumped'

BezhanSalleh

@adnan483 that's because you can't connect to your database. make sure you are using correct DB_USERNAME=your-mysql-username and DB_PASSWORD=your-mysql-password in your .env file then run:

php artisan config:cache && php artisan route:cache

now point to the route, it will backup your database

adnan483

@Yama Everything is ok with .env file, I'm using it normally for other things, but still not working.

Snapey
Snapey
6 months ago (929,835 XP)

the account being used (for instance www-data) may not have write permissions for the place you are trying to write the dump.

When you do it from the command line, the php session is running in whatever elevated account you use.

Try specifying a storage location that you know your webserver can write to such as the /storage/logs folder.

adnan483

@Snapey I tried that but still same message: Database 'test' cannot be dumped'

Snapey
Snapey
6 months ago (929,835 XP)

Try this one https://github.com/spatie/laravel-backup

it may be more forthcoming regarding errors. It's also a very polished package with 660,000 downloads

adnan483

@Snapey I tried spatie backup right now and now have bigger problem, can open application, just see this Class 'Backup\BackupServiceProvider' not found, I remove it from vendor and still same problem

Snapey
Snapey
6 months ago (929,835 XP)

you need to add and remove packages through composer .. not just delete the folder

adnan483

@Snapey I did that and just have this:

(1/1) FatalErrorException syntax error, unexpected ':', expecting ';' or '{' in Inflector.php (line 265)

Snapey
Snapey
6 months ago (929,835 XP)

that normally signifies an issue with the php version.

when you worked with composer did you accidentally update laravel version?

adnan483

No, I'm still on 5.6, this is after I remove backup from composer

BezhanSalleh

@adnan did you do compser update after you removed the package?

Please sign in or create an account to participate in this conversation.