Why Automated Backups Are Non-Negotiable for Laravel Apps (Plus Step-by-Step Setup)
One bad database migration, accidental deletion, or server crash can wipe out years of customer data. Relying on manual database dumps or basic hosting snapshots leaves dangerous gaps in your disaster recovery plan.
Using a dedicated Laravel backup package—most notably the industry-standard spatie/laravel-backup—solves this by automating your entire backup pipeline directly inside your codebase.
5 Advantages of Using a Laravel Backup Package
Full-Stack Redundancy: It archives both your database (MySQL, PostgreSQL, SQLite) and your critical application files (such as user-uploaded media and environment configurations) into a single compressed file.
Multi-Cloud Storage Support: Automatically push encrypted backups to off-site destinations like AWS S3, Google Cloud, DigitalOcean Spaces, or Dropbox so a single server failure never destroys your backups.
Automated Health Checks and Alerts: Instead of hoping your backups work, the package monitors backup freshness and storage limits, immediately alerting your team via Slack, Email, or Discord if a backup fails.
Smart Cleanup Retention: Old backups consume expensive cloud storage. Automated retention rules keep daily backups for a week, weekly backups for a month, and yearly archives without manual intervention.
Version-Controlled Configuration: Because your backup rules live inside
config/backup.php, your disaster recovery setup is tracked in Git alongside your application code.
Step-by-Step: How to Install and Configure Spatie Laravel Backup
Step 1: Install the Package via Composer
Open your terminal in your Laravel project root and run the following command:
composer require spatie/laravel-backupStep 2: Publish the Configuration File
Publish the default configuration file so you can customize which files and databases get backed up:
php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"This creates a new config/backup.php file in your project.
Step 3: Configure Source Files and Cloud Storage Disks
Open config/backup.php and define your source files, database connection, and off-site storage disk (make sure your S3 or cloud disk is already configured in config/filesystems.php):
'backup' => [
'name' => env('APP_NAME', 'laravel-app'),
'source' => [
'files' => [
'include' => [
base_path(),
],
'exclude' => [
base_path('vendor'),
base_path('node_modules'),
],
],
'databases' => [
'mysql',
],
],
'destination' => [
'disks' => [
's3',
],
],
],Step 4: Set Up Instant Failure Notifications
In config/backup.php, add your engineering team's email address or Slack webhook under the notifications array so you are alerted the second a backup fails or runs out of disk space:
'notifications' => [
'notifications' => [
\Spatie\Backup\Notifications\Notifications\BackupHasFailedNotification::class => ['mail', 'slack'],
\Spatie\Backup\Notifications\Notifications\HealthyBackupWasFoundNotification::class => [],
],
'mail' => [
'to' => 'devops@yourcompany.com',
],
],Step 5: Test Your Backup Manually
Before automating the schedule, run a manual backup to verify that your database dump utility (mysqldump or pg_dump) and cloud storage permissions work properly:
php artisan backup:runStep 6: Automate with Laravel's Scheduler
Schedule the cleanup, backup, and health monitor commands inside routes/console.php (for Laravel 11, 12, and 13+):
use Illuminate\Support\Facades\Schedule;
Schedule::command('backup:clean')->daily()->at('01:00');
Schedule::command('backup:run')->daily()->at('01:30');
Schedule::command('backup:monitor')->daily()->at('03:00');Make sure your production server's cron job is active and running php artisan schedule:run every minute.