Use-case example: Making scheduled database backups using a Worker Cron Job.
- Setup Laravel locally
- Create App on fortrabbit
- Setup Laravel on fortrabbit.
- Make sure you configured the database
- Make sure you configured the storage
- Make sure the composer package
league/flysystem-aws-s3-v3
is installed
There are a couple of solutions available. My favorite is spatie/laravel-backup. So start by installing the package locally:
composer require spatie/laravel-backup
Now add the new service provider to config/app.php
:
'providers' => [
...
'Spatie\Backup\BackupServiceProvider',
...
],
Next export the configuration:
php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"
Finally set S3 as storage backend in the configuration in config/laravel-backup.php
:
// ..
'destination' => [
// ..
'filesystem' => [isset($_SERVER['APP_SECRETS']) ? 's3' : 'local'],
// ..
]
// ..
That's it from the Laravel-side of things. Now you can push everything and head over to the Dashboard.
If you haven't booked the Worker component, yet, now is the time. Once that's done go to App > Settings > Worker jobs and click on Add a new Cron Job. In the following dialog set
- Name: database-backup (or the like)
- Command: artisan backup:run --only-db
- Interval: every day (or what you prefer)
Save an done.