In this guide, we’ll walk you through the process of backing up a Laravel application and saving the backup to Dropbox.
By following Laravel 11 Store Backup on Dropbox using Spatie Tutorial, you’ll learn how to integrate Dropbox with Laravel to store your application’s backups, using the Spatie package to facilitate the process.
Step 1: Create a Dropbox Account
Visit Dropbox’s app creation page to create a new console application. Once created, retrieve the secret key, app ID, and access token.
Step 2: Add Credentials to .env File
Open your .env
file and add the Dropbox credentials:
DROPBOX_APP_KEY=your_app_key_here
DROPBOX_APP_SECRET=your_app_secret_here
DROPBOX_AUTH_TOKEN=your_auth_token_here
Step 3: Install and Configure Spatie Flysystem-Dropbox
Execute the following command to install the spatie/flysystem-dropbox
package, which will enable Dropbox integration:
composer require spatie/flysystem-dropbox
Next, modify the app/Providers/AppServiceProvider.php
file to include the following code:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\Filesystem;
use Spatie\Dropbox\Client as DropboxClient;
use Spatie\FlysystemDropbox\DropboxAdapter;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Storage::extend('dropbox', function (Application $app, array $config) {
$adapter = new DropboxAdapter(new DropboxClient(
$config['authorization_token']
));
return new FilesystemAdapter(
new Filesystem($adapter, $config),
$adapter,
$config
);
});
}
}
Edit the config/filesystems.php
file to configure the Dropbox file system:
<?php
return [
...
'disks' => [
...
'dropbox' => [
'driver' => 'dropbox',
'key' => env('DROPBOX_APP_KEY'),
'secret' => env('DROPBOX_APP_SECRET'),
'authorization_token' => env('DROPBOX_AUTH_TOKEN'),
],
],
];
Step 4: Install spatie/laravel-backup
Run the following command to add the spatie/laravel-backup
package to your application:
composer require spatie/laravel-backup
Step 5: Test the Backup Functionality
Execute the backup command to create a backup of your Laravel application on Dropbox:
php artisan backup:run
Check your Dropbox account to verify that the backup has been successfully created.