Laravel 10 Store Backup on Dropbox using Spatie Tutorial

Step 1: Install Laravel

composer create-project laravel/laravel dropboxProject

Step 2: Configure Dropbox as Driver 

 composer require spatie/flysystem-dropbox

app/Providers/AppServiceProvider.php

<?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
            );
        });
    }
}

Now, let's add new driver on config/filesystems.php file.

config/filesystems.php

&lt;?php
  
return [
        ...
        ...
        'disks' => [
                'dropbox' => [
                    'driver' => 'dropbox',
                    'key' => env('DROPBOX_APP_KEY'),
                    'secret' => env('DROPBOX_APP_SECRET'),
                    'authorization_token' => env('DROPBOX_AUTH_TOKEN'),
                ],
        ],
    ]

Step 3: Get Dropbox API Key & Secret & Access Token

In this step, we will need to dropbox api key, secret and access token to store files on Dropbox Account.

1. You need to go here Dropbox App Console and you need to create new app .

2. After click on "Create App" button, you need to add name of App.

3. Add "files.content.write" permission to your app.

4. Here you need to get API Key, API Secret and Access token from here and need to set on .env file.

You need to set all configuration on your .env file.

.env

DROPBOX_APP_KEY=wx0qfff2ly...
DROPBOX_APP_SECRET=gqdi00g...
DROPBOX_AUTH_TOKEN=sl.Bc5_aUxtGFDZP6... 

Step 4: Install spatie/laravel-backup

composer require spatie/laravel-backup 

a command to publish the Spatie package separately.

php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"

For instance, set dropbox name to disks property; this is the disk name that will store your backup.

config/backup.php

<?php
      
return [
        ...
        ...
        'destination' => [
            /*
             * The disk names on which the backups will be stored.
             */
            'disks' => [
                'dropbox',
            ],
        ]

Step 5: Backup Laravel App

Now, we are ready to take back of all laravel application.

php artisan backup:run