Automated backups help safeguard applications from data loss by providing daily saves, intelligent cleanup, remote storage options, and instant alerts for failures or missed backups.

Key Points

  • Daily backup routines reduce the chance of critical data loss by more than 90% overall.
  • More than 80% of developers depend on automated backup tools in their production server environments.
  • Real-time alerts detect 100% failed backups, enabling prompt action before problems worsen.

Keeping your Laravel application safe with automated backups is essential for security, stability, and long-term success. Whether you're managing client applications or running your platform, automating backups is a best practice that every developer or web development company should follow.

In this step-by-step guide, we’ll show you how to set up automatic database and file backups in Laravel using the powerful Spatie Laravel Backup package.

This solution is perfect for businesses offering website development services, teams involved in custom web development, and anyone looking to hire Laravel developer talent to ensure data security.

Step 1: Install Spatie Laravel Backup

Run the following Composer command to install the Spatie backup package:

composer require spatie/laravel-backup

This package automates:

  • Database dumping
  • File compression
  • Cloud/local storage
  • Notifications (Email, Slack)

It’s widely used in modern custom web development environments to streamline backup operations.

Step 2: Publish the Configuration and Migration Files

Next, publish the backup config files with this Artisan command:

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

This command generates the configuration file at:

                                        config/backup.php
                                    

Here you can customize:

  • What gets backed up (files, DB)
  • Where backups are stored
  • Retention settings
  • Notification preferences

This step is essential for Laravel apps managed by a web development company to meet project-specific requirements.

Step 3: Configure Backup Settings

Open the configuration file:

                                        config/backup.php
                                    

What to Back Up

                                        'include' => [
   base_path(), // Includes app files
],
'exclude' => [
   base_path('vendor'),
   base_path('node_modules'),
   storage_path(), // Optional
],
                                    

Database Backup

                                        'database' => [
   'connection' => config('database.default'),
],
                                    

This dumps the default database defined in your .env.

Where to Store

                                        'disks' => ['local'], // You can change to 's3', 'ftp', 'dropbox', etc.
                                    

Change the disk based on your project needs. Using cloud storage is common in enterprise-level website development services.

Step 4: Schedule Automatic Backups

Open the file:

                                        app/Console/Kernel.php
                                    

Then add the following to the schedule() method:

                                        $schedule->command('backup:run')->daily();        // Daily backup
$schedule->command('backup:clean')->weekly();     // Clean old backups
$schedule->command('backup:monitor')->daily();    // Monitor backup health
                                    

These commands will:

  • backup:run → Create a new backup
  • backup:clean → Remove old backups
  • backup:monitor → Check the latest backup’s status

Scheduling commands like these is a core practice in advanced custom web development workflows.

Step 5: Add CRON Job to Run Laravel Scheduler

To ensure Laravel’s scheduler runs, add a CRON job:

Run:

                                        crontab -e
                                    

Add:

                                        * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
                                    

Replace /path-to-your-project with your actual Laravel app path, such as /var/www/html/laravel-app.

This ensures Laravel checks every minute if scheduled commands need to run. It’s vital for teams who hire Laravel developer professionals to maintain production systems.

Step 6: Manually Run Backup (For Testing)

To test the backup process:

                                        php artisan backup:run
                                    

By default, backups are stored in:

                                        storage/app/laravel-backup/
                                    

Use this to verify that your database, files, and configuration backups are working as expected.

Step 7: (Optional) Set Up Email or Slack Notifications

In the file:

                                        config/backup.php
                                    

Locate and update the notifications section:

                                        'notifications' => [
   'notifications' => [
       \Spatie\Backup\Notifications\Notifications\BackupHasFailed::class => ['mail'],
       \Spatie\Backup\Notifications\Notifications\BackupWasSuccessful::class => ['mail'],
       // Other notifications
   ],

   'mail' => [
       'to' => 'admin@example.com',
   ],
],
                                    

This ensures you’ll receive an email if the backup fails or succeeds. Don’t forget to configure .env mail settings:

                                        MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
MAIL_FROM_ADDRESS=admin@example.com
MAIL_FROM_NAME="Laravel App"
                                    

Integrating notifications is a key quality marker when working with a web development company on production-grade apps.

Monitor and Clean Old Backups

You can clean and monitor backups manually as well:

Clean Old Backups

                                        php artisan backup:clean
                                    

Monitor Backup Health

                                        php artisan backup:monitor
                                    

These commands help manage disk space and ensure the latest backup is available—best practices for teams delivering high-end website development services.

Final Words

Setting up automatic database backups in Laravel is straightforward and critical for every Laravel project, whether you're an individual developer or part of a full-service web development company.

By leveraging Spatie Laravel Backup, you ensure:

  • Reliable daily backups
  • Safe long-term storage (local or cloud)
  • Real-time notifications
  • Retention policies for managing space

If you’re building applications for clients or planning your next big release, consider partnering with a team that offers custom web development or hire Laravel developer experts to keep your data and systems safe.

Tech Stack & Version

Frontend

  • Vue.js
  • Tailwind CSS

Backend

  • Laravel
  • PHP 8.1+

Deployment

  • Linux Server
  • MySQL
  • PostgreSQL
img

©2025Digittrix Infotech Private Limited , All rights reserved.