Daily scheduled backups with laravel-backups
January 3, 2025
Over the past month I've been working hard to launch and grow a Job Board for my home town. It's now at a point where almost everything is automated (another article coming on that soon) except backups of the SQLite database.
The site runs on Laravel, and so I did a quick google and came across Laravel-backup , a package for doing exactly what it says on the tin. So here's a quick guide on how I added daily scheduled backups!
Installation and configuration
We start at the beginning, by installing the package and publishing the config file.
composer require spatie/laravel-backup
php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"
This publishes the config file to config/backup.php, open this file up and scroll down to files -> include
For me, I just included the path to the database file; database/database.sqlite
However, feel free to backup everything and anything you may find important such as the storage folder, or logs!
After that, scroll down to databases and remove 'mysql' as we're not using that.
Finally, change destination -> disks -> local to your preferred disk.
That completes the setup!
Scheduling the backup
Open routes/console.php and add the following
Schedule::command('backup:run')->daily()->at('01:00')
->onFailure(function () {
})
->onSuccess(function () {
//
});
And voila! Your site will now automatically backup every night at 1am.
If you're running on Forge, remember to enable the Laravel Scheduler in your Sites settings.
Thanks for reading and happy coding! 😎