Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nikhil_lu210's avatar

Artisan::call('backup:run'); Not working

I'm trying to create backup from my system through Spatie Laravel Backup package. And I'm calling artisan backup:run command from my controller Artisan::call('backup:run');. But its not working.

Can anyone please help me with this issue??

0 likes
30 replies
nikhil_lu210's avatar

obviously I did. and as they said php artisan backup:run working from cmd. but I want to do that from my controller using Artisan::call('backup:run'); this line.

Armani's avatar

Can you run:

php artisan backup:run
1 like
nikhil_lu210's avatar

It's worked from command promt. But I want to do this by my controller.

and its not working.

Snapey's avatar

are you using php artisan serve as your webserver?

1 like
Snapey's avatar

Thats your problem. the php internal webserver can only deal with a single request. Calling Artisan from within that request results in a hang whilst it waits for a second connection.

1 like
nikhil_lu210's avatar

So you meant, it will not work here??

Is that will work on server??

Snapey's avatar

Why are you trying to run it this way?

What does "not even working" mean?

2 likes
nikhil_lu210's avatar

May be you didn't get my point. let me clear it to you.

Actually I have developed an application. And I want to take backup from my Super Admin section.

https://snipboard.io/1Ya04b.jpg

And that's why I need to do that. So I can create new backup by clicking on the button. @snapey

Snapey's avatar

Then you have an error in your code to make it "not working"

1 like
nikhil_lu210's avatar

But other commands are working fine.

/**
     * Create New Backup
     */
    public function create()
    {
        Artisan::call('backup:run');
        
        toast('New Backup created successfully.', 'success')->autoClose(2000)->timerProgressBar();
        return redirect()->back();
    }
Snapey's avatar

How can we help when you refuse to describe what "not working" means?

1 like
nikhil_lu210's avatar

When I click on the Button "Create New Backup" it load sometime and after a certain time its redirect back with successful alert. but the backup does not created at all.

codelone's avatar

@nikhil_lu210 You can get the error message by using this

Route::get('/backup', function (Request $request) { Artisan::call('backup:run'); return Artisan::output(); });

tol64's avatar

Try running the command like this:

Artisan::queue('backup:run', ['--only-db' => true]);

And don't forget to run the command in queue mode:

php artisan queue:work
1 like
iftekhs's avatar

Try to check the output of artisan after you run it ->

Artisan::call('backup:run');
dd(Artisan::output());

And see what is the issue.

2 likes
GavaneKalpesh's avatar

Try This, Go to Config Folder inside database.php update the following line

'dump' => [ 'dump_binary_path' => 'F:/kalpesh/mysql/bin/', <-- Here Add Your Path

and it's worked for me.

1 like
codelone's avatar

I created a GitHub issue facing the same problem: https:// github.com/spatie/laravel-backup/issues/1578

Snapey's avatar

@codelone Unfortunately destroyed all credibility with

And its not just happened to me, 1000+ people are getting the same problem and have no solution for it, I already search the entire internet.

1 like
Snapey's avatar

@codelone might be related to permissions. When you run from the command line, you are executing mysqldump as yourself. When running from the application, you are running mysqldump as your web server user

1 like
fredsal's avatar

@codelone I did test it, it is working as expected, but now i see that you are using a really old version of package on windows, first upgrade to the latest version, add mysql path in environment variables of windows, also try disabling UAC

fredsal's avatar

@Snapey that is the most common problem in linux, I don't know if the same thing will happen in windows

codelone's avatar

I found the solution now and I posted it here: https://stackoverflow.com/a/73929009/13804634

But going to post here too... I had invested a lot of time, particularly in this specific issue and found the solution in my case...as php artisan backup: run command successfully backups the database using CLI...so there is no issue with the package itself... I'm using "spatie/laravel-backup": "^6.16"

route/web.php create a route to test the artisan command

Route::get('/backup', function() { Artisan::call('backup:run'); }); As I can see when we try to launch the laravel application we use CLI for example:

php artisan serve then your project will host on 127.0.0.1:8080/project/ or any given port.

Instead, try to access the project directly from your localhost without artisan and then navigate to your project directory from the address bar localhost/project/backup now, it will generate a backup in storage/app/public/ directory.

Must try this if you tried everything...

Please or to participate in this conversation.