Laravel-backup: Automatic Backup in Laravel not working

Created on 25 Mar 2019  路  21Comments  路  Source: spatie/laravel-backup

scheduling 'backup:clean' and 'backup:run' not working in Laravel 5.7

This is the code I have in Kernel
protected function schedule(Schedule $schedule)
{
$schedule->command('backup:run')
->everyMinute();
}

Most helpful comment

I am facing the same problem too.
I tracked the root cause by following code:

$schedule->command('backup:run')->everyMinute()->appendOutputTo('/var/www/storage/logs/cron.log');

then, I found there are error message in the cron.log file as following:

 Starting backup...
Backup failed because: mkdir(): Permission denied.

On my side , the owner of database backup directory and temporary directory config in config\backup.php is invalid . After I change the owner of them, backup cron job works fine.

All 21 comments

It seems to work in my applications. Could you create a demo app for me to look at where this does not work?

login.zip
Hi Freekmurze
I have uploaded a demo project

Could you create a repo for me to look at?

Well, I follow the instruction until the end. However, the backup system is properly working but it does not work with schedule.
These are steps I follow

  1. composer require spatie/laravel-backup
  2. php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"
  3. I add the following code into database.php file in Mysql section
    'dump' => [
    'dump_binary_path' => 'C:\xampp\mysql\bin',
    'excludeTables' => [
    'table_to_exclude_from_backup',
    'another_table_to_exclude'
    ]
    ]
  4. Then I run the following code for backup (php artisan backup:run)
    Note: from step 1 to step 4 are working.
  1. I run this code: cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
  2. Then I set this code into kernel.php:
    protected function schedule(Schedule $schedule)
    {

    $schedule->command('backup:run')
             ->everyMinute();
    

    }

Hi FreekMurze,
in Laravel 5.8 it returns:
no scheduled commands are ready to go.

In App\Console\Kernel.php

protected $commands = [];

protected function schedule(Schedule $schedule)
{
  $schedule->command('backup:run')->daily()->at('18:42');
}

If I run

php artisan backup:run

everything goes fine

I'm having issues too, manually running the command is fine but the schedule isn't working anymore.

My last scheduled backup was 26th March 19. did laravel have an update that broke things maybe? hmmm

Same problem here:

If i run it with "php artisan backup:run" everything works thine. But not with the Scheduler.

Same problem here after updating from 6.0.3 to 6.0.7

If i run it with "php artisan backup:run" everything works thine. But not with the

Scheduler.

Same problem here php 7.3.3 and laravel 5.8. Has anyone found a solution or another plugin to solve this issue?

Same problem here. Any updates?

This is a problem for me too. I can run "php artisan backup:run" but it won't run to the schedule.

I am facing the same problem too.

I noticed the PHP CLI version when I run php -v on the terminal and the PHP CLI version when the cronjob is run is different.

With php -v on the terminal, PHP output version 7.3.1
image

With php -v on the cronjob, PHP output version 7.1.23
image
image

spatie/db-dumper will only work with version PHP version 7.3 or above, so you will need to make sure you run PHP 7.3 on the cronjob. Below is how I do it:

Get the current PHP path on your terminal:
image
Change your PHP path on the cronjob:
image

Okay so... I fixed my issue.

If you have this issue make sure to check your kernel file.

The thing was that I was running Laravel's "queue:work" in the Kernel.php so when I ran schedule:work then all the commands only ran once since the queue was the last command and it got stuck there. After I removed the queue:work from the kernel and created a separate cron for it, everything started working as expected!

Awesome package and the issues was on my side.
Thanks

Facing the same problem as above, when I run manually all works perfect but scheduler never fires.

Okay so... I fixed my issue.

If you have this issue make sure to check your kernel file.

The thing was that I was running Laravel's "queue:work" in the Kernel.php so when I ran schedule:work then all the commands only ran once since the queue was the last command and it got stuck there. After I removed the queue:work from the kernel and created a separate cron for it, everything started working as expected!

Awesome package and the issues was on my side.
Thanks

I am facing the same problem too.
I tracked the root cause by following code:

$schedule->command('backup:run')->everyMinute()->appendOutputTo('/var/www/storage/logs/cron.log');

then, I found there are error message in the cron.log file as following:

 Starting backup...
Backup failed because: mkdir(): Permission denied.

On my side , the owner of database backup directory and temporary directory config in config\backup.php is invalid . After I change the owner of them, backup cron job works fine.

Stil not working for me. Please provide a concrete solution.

I had the same problem, figured out that I was running commands through Scheduler in the wrong way:
This was my code:

$schedule->command('command.backup:clean')->dailyAt("05:00");

That should be

$schedule->command('backup:clean')->dailyAt("05:00");

Now everything works fine.

So guys,

I have the same problem. I wrote $schedule->command('backup:run')->dailyAt("05:00"); but not work. I need to inform anythink on $commands???

protected $commands = [ // ];

I am facing the same problem too.

I noticed the PHP CLI version when I run php -v on the terminal and the PHP CLI version when the cronjob is run is different.

With php -v on the terminal, PHP output version 7.3.1
image

With php -v on the cronjob, PHP output version 7.1.23
image
image

spatie/db-dumper will only work with version PHP version 7.3 or above, so you will need to make sure you run PHP 7.3 on the cronjob. Below is how I do it:

Get the current PHP path on your terminal:
image
Change your PHP path on the cronjob:
image

Is it true that it needs php7.3?? - our DO server runs 7.2, so that might be why.

I faced a similar issue but ultimately solved it by following laravel documentation
I had to add
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

(Note: I didn't redirect my logs initial to /dev/null instead to a log file so that I could debug the issue )
in cron

and set the current time zone according to my area

$schedule->command('backup:run --only-db')->timezone('Asia/Kolkata')->dailyAt('01:35');

Was this page helpful?
0 / 5 - 0 ratings