This is a Python script that will backup all files and databases on Laravel Forge servers to an S3 compatible endpoint.
This backup script will work with all Laravel Forge plans, no matter if you have the Business plan or not. Unlike the built in Forge backup, this script will backup all your files, and not just the database.
- Automated backup of Laravel Forge managed servers
- YAML configuration
- Database backup with support for different PHP applications (Laravel, WordPress, Invision Power Board)
- Backup to S3-compatible storage (like Cloudflare R2)
- Discord notifications
- Retention policy management
- Comprehensive logging and error handling
-
SSH into your Forge server as the
forgeuser. -
cd /home/forge && git clone https://github.com/alexmck/laravel-forge-complete-backup.git && cd laravel-forge-complete-backup
-
Run the installation script:
chmod +x install.sh ./install.sh
To run this automatically at 3:00 AM every day via cron, add an entry like this (update the absolute paths to match your system). You can either use
crontab -evia SSH to add this, or you can add it as a scheduled job via the Laravel Forge web interface.0 3 * * * /home/forge/laravel-forge-complete-backup/venv/bin/python /home/forge/laravel-forge-complete-backup/backup.py >> /home/forge/laravel-forge-complete-backup/cron.log 2>&1
The script uses the config.yaml file. See the config.yaml.example file and copy it as necessary.
source venv/bin/activate
python3 backup.pycd /home/forge/laravel-forge-complete-backup
git pull origin mainboto3: AWS S3 clientPyYAML: YAML configuration parsingrequests: HTTP requests for Discord notifications