Skip to content

Instantly share code, notes, and snippets.

@ukautz
Last active January 4, 2019 17:25
Show Gist options
  • Save ukautz/7aac0af8c064942b1f56 to your computer and use it in GitHub Desktop.
Save ukautz/7aac0af8c064942b1f56 to your computer and use it in GitHub Desktop.
Workers with Laravel on fortrabbit

Workers with Laravel on fortrabbit

Use-case example: Making scheduled database backups using a Worker Cron Job.

Prerequisites

Setup Laravel

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.

Dashboard configuration

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment