How to backup your Laravel sites and apps

In this tutorial I will show you how to easily backup your Laravel application.

Spatie made a great package called Laravel Backup which we will utilize for setting up automated backups for our Laravel application. This will be a very brief tutorial, as the documentation for the package already covers most of what you need.

Start with a fresh Laravel installation, and then install the following:

// Install spatie backup package, install league S3 driver and install the slack channel driver
composer require spatie/laravel-backup && composer require league/flysystem-aws-s3-v3 && composer require laravel/slack-notification-channel

After installing the spatie/laravel-backup package, publish the the config file and edit the necessary values, for me this was the 'name' and the 'disks' as well as the slack webhook url.

After configuring the package, test out the installation by running php artisan backup run

Last step for the Laravel installation is to schedule the commands (use the below as an example configuration)

protected function schedule(Schedule $schedule)
{
    $schedule->command('backup:clean')->daily()->at('04:00');
    $schedule->command('backup:run')->daily()->at('04:05');
    $schedule->command('backup:monitor')->daily()->at('04:15');
}

And the last (last) step is to login to forge and setup the scheduler to run, I already covered this here