How to Set Up Daily Laravel Backups on Google Drive for Free
Posted By
kamlesh paulon
Dec 10, 2024When it comes to Laravel backups, not every project needs to rely on premium storage services like Amazon S3. For developers seeking a cost-effective solution, Laravel backups on Google Drive for free provide an excellent alternative. Google Drive offers secure storage at no cost, making it ideal for daily backups in smaller Laravel projects. In this guide, we’ll show you step-by-step how to set up daily Laravel backups on Google Drive using two powerful packages: Spatie Laravel Backup for generating backups and Laravel Google Drive Storage to connect Laravel to Google Drive.
Table of Contents
- Step 1: Install Spatie Laravel Backup
- Step 2: Install and Configure Laravel Google Drive Storage
- Setup Google Keys
- Step 3: Configure Spatie Backup to Use Google Drive
- Step 4: Schedule the Backup
- Step 5: Test the Backup
Step 1: Install Spatie Laravel Backup
The Spatie Laravel Backup package helps in creating and managing backups for Laravel projects.
- Run the following command to install it via Composer:
- Publish the package configuration:
- Configure the
config/backup.php
file to set backup preferences like the files to include and the backup frequency.
Step 2: Install and Configure Laravel Google Drive Storage
This package allows Laravel to store files on Google Drive by defining it as a filesystem disk.
- Install the package:
- Add your credentials in the
.env
file:
- Update
config/filesystems.php
by adding a new disk configuration:
Setup Google Keys
Step 3: Configure Spatie Backup to Use Google Drive
Now, set up the backup configuration to use Google Drive as the storage location.
- Open
config/backup.php
. - Update the disk setting under
backup.destination
to point to the Google Drive disk:
- Update the disk setting under
monitor_backups.disks
to point to the Google Drive disk:
Step 4: Schedule the Backup
To automate backups, schedule the backup command in Laravel’s scheduler.
- Open
app/routes/console.php
. - Add the following to the schedule method:
- Ensure your server’s cron job is set up to run Laravel’s scheduler every minute:
Step 5: Test the Backup
Manually run the backup command to ensure everything is working:
Check Google Drive to confirm that the backup has been successfully uploaded.