Courses

[NEW] Laravel Project PROCESS: From Start to Finish

DB Backups: Automate and TEST Them

Summary of this lesson:
- Setting up Spatie backup package
- Configuring backup schedules
- Adding S3 storage for backups
- Testing backup and restore process

Now that we have some features and the project is coming along - we should think about the worst...

What if we lose the data?

Like with the code in GitHub - we should also create database backups!

Seriously, backups are one of those things we don't think about until it's too late. So, let's get ahead of the curve and add backups to our project.


Adding Backups

For our backups, we will use the good old Spatie Backups package. It's tested, reliable, and easy to use.

First, let's install the package:

composer require spatie/laravel-backup

Then publish the configuration file:

php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"

And that's it for the installation. Now, we need to configure the package.


Configuring Backups

We need to edit the config/backup.php file to configure our backups. In this case, we want to add s3 as an additional disk to store our backups:

config/backup.php

// ...
 
/*
* The disk names on which the backups will be stored.
*/
'disks' => [
'local',
's3',
],
 
// ...

Note: Don't forget to configure your S3 credentials in the .env file.

Other settings are personal preference, but we could recommend...

The full lesson is only for Premium Members.
Want to access all 16 lessons of this course? (105 min read)

You also get:

  • 69 courses (majority in latest Laravel 11)
  • Premium tutorials
  • Access to repositories
  • Private Discord