Setup Automatic Laravel Daily Backup Tutorial
Laravel does not offer a database backup as part of their core functionality so new Laravel developers don’t get to work with that while reading Laravel articles or building a Laravel application.
Prerequisites
This tutorial motive, I take that you have a Laravel application installed on a web server. My setup is:
- Laravel 5.5
- Google Drive API
- MySQL Database
For backing up your Laravel files and database, you need to install this package first into your application. Open the SSH terminal and initiate the installation by entering the following command:
composer require spatie/laravel-backup
Now, to actually start working with backup, we need first to configure it. And for that we need to publish this package’s vendor file:
php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"
As you would have noticed, it publishes a backup.php
file to config/backup.php
namespace. Open this file and have a good look at available settings that you can apply to backup your Laravel application.
Take Backup
This package provides numerous commands, let us try and test few of them:
- To backup all the files and database:
php artisan backup:run
To backup only database:
php artisan backup:run --only-db
- To backup application files only:
php artisan backup:run --only-files
Conclusion:
Backups are essential for any application in production. For this, we installed a third party library and configured it. We also saw various backup commands it provides.
Visit here to learn automated the Laravel backup by cron scheduling it.