@ivymasterman I can suggest ready-to-use package from spatie https://spatie.be/docs/laravel-backup/v8/introduction
php artisan backup:run --only-db
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying to set up a scheduler for weekly database backup in laravel. I have created a command and filled out some data like the command itself and description, and registered it in the console kernel as well. The issue is that the file never gets created and/or stored in storage.
This is the part of the code where is the command:
public function handle()
{
Log::info('Database backup completed.');
$filename = 'mysite' . Carbon::now()->format('Y-m-d') . ".gz";
$command = "mysqldump --user=" . env('DB_USERNAME') ." --password=" . env('DB_PASSWORD') . " --host=" . env('DB_HOST') . " " . env('DB_DATABASE') . " | gzip > " . storage_path() . "/app/backup/" . $filename;
$returnVar = NULL;
$output = NULL;
exec($command, $output, $returnVar);
}
This is the kernel part:
/**
- The Artisan commands provided by your application.
- @var array
*/
protected $commands = [
OtherCron::class,
DatabaseBackupCron::class,
];
/**
Note: I have used "->everyFiveMinutes()" just for testing purposes :)
@ivymasterman I can suggest ready-to-use package from spatie https://spatie.be/docs/laravel-backup/v8/introduction
php artisan backup:run --only-db
Please or to participate in this conversation.