You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel自动备份问题求助:除spatie/laravel-backup外的可行方案

Alternative Methods for Automatic Laravel Backups

Sorry to hear you hit a roadblock with spatie/laravel-backup! Let’s walk through some reliable, flexible alternatives to set up automatic backups for your Laravel project—each with its own strengths depending on your needs:

1. Custom Artisan Command + Laravel Task Scheduling

This approach gives you full control over exactly what gets backed up and how. Here’s a step-by-step breakdown:

  • Generate a new Artisan command: php artisan make:command BackupApplication
  • In the command’s handle() method, add logic to:
    • Dump your database using mysqldump (or pg_dump for PostgreSQL, etc.)
    • Compress critical app files (like storage/, .env, and core app/ directories)
    • Store backups in a secure location (local disk, S3, FTP, or even a cloud storage service)
    • Optional: Add cleanup rules to delete old backups after a set retention period
  • Register the command in app/Console/Kernel.php
  • Schedule it to run automatically in the same file’s schedule() method, for example:
    $schedule->command('app:backup')->dailyAt('02:00')->sendOutputTo(storage_path('logs/backup.log'));
    

2. Laravel Forge’s Native Backup Tool

If you’re hosting your app on Laravel Forge, take advantage of its built-in backup feature—no custom code required:

  • Navigate to your server in Forge, open the "Backups" tab
  • Configure backup frequency (daily/weekly), select which databases and files to include, and choose a storage destination (Forge’s cloud storage, AWS S3, Dropbox, etc.)
  • Forge handles scheduling and execution automatically, so you can set it and forget it.

3. Backup Manager Package

The backup-manager/laravel package is a flexible alternative that supports multiple databases and storage drivers:

  • Install via Composer: composer require backup-manager/laravel
  • Publish the config file: php artisan vendor:publish --provider="BackupManager\Laravel\BackupManagerServiceProvider"
  • Configure your database connections and storage preferences in config/backup-manager.php
  • Schedule the backup command in your Kernel:
    $schedule->command('backup:run')->daily();
    
    It works with MySQL, PostgreSQL, SQLite, and storage options like S3, FTP, and local disks.

4. Shell Script + Cron Job

For a lightweight, framework-agnostic solution, create a shell script and schedule it with Cron:

  • Write a script (e.g., laravel-backup.sh) that:
    1. Dumps your database using native CLI tools
    2. Zips your important app directories
    3. Uploads backups to remote storage (use awscli for S3, rclone for other cloud services)
    4. Cleans up outdated backups to save space
  • Make the script executable: chmod +x laravel-backup.sh
  • Add a Cron job to run it on your desired schedule, e.g., daily at 2 AM:
    0 2 * * * /path/to/laravel-backup.sh >> /var/log/laravel-backup.log 2>&1
    

Each method has its perks: custom commands offer maximum control, Forge is perfect for managed hosting, Backup Manager is a plug-and-play package, and shell scripts are great for simple, low-overhead setups. Pick the one that aligns best with your hosting environment and project requirements!

内容的提问来源于stack exchange,提问作者zaster

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:03:59