How To Store Backup On Dropbox In Laravel 9

Websolutionstuff | Jan-16-2023 | Categories : Laravel PHP MySQL

In this article, we will see how to store the backup on dropbox in laravel 9. Here, we will learn to store database backup on dropbox in laravel 8 and laravel 9 using spatie. Laravel's Flysystem integration provides support for several "drivers" out of the box. You can create a custom driver if you want to use it.

Dropbox is easy to use, reliable, private, and secure. Dropbox is a file hosting service operated by the American company Dropbox, Inc. It can provide cloud storage, file synchronization, personal cloud, and client software.

So let's see, laravel 9 backup store on dropbox, laravel 9 dropbox store backup using spatie, spatie/flysystem-dropbox tutorial.

dropbox integration in laravel 9

 

Step 1: Install Laravel 9

Step 2: Install spatie/laravel-backup

Step 3: Get Access Token From Dropbox

Step 4: Install spatie/flysystem-dropbox

Step 5: Configure Dropbox FileSystem

Step 6: Run Laravel 9 Application

 

Step 1: Install Laravel 9

In this step, we will install the laravel 9 application using the following command.

composer create-project --prefer-dist laravel/laravel laravel-9-dropbox

 

Step 2: Install spatie/laravel-backup

Now, we will install spatie/laravel-backup package using the composer command.

Read More: spatie/laravel-backup.

composer require spatie/laravel-backup

Now, run the following command and publish the spatie package.

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

After running this command, Automatically create a new backup.php file. So, in this file we will set up the dropbox configuration.

config/backup.php

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

 

Step 3: Get Access Token From Dropbox

Now, get the access token from dropbox. So, you can go to the dropbox search console and create a new account, and set up a project. Click on the generate button and get the access token from dropbox.

access_token_dropbox

 

Step 4: Install spatie/flysystem-dropbox

In this step, we will install spatie/flysystem-dropbox package using the following command.

Read more: spatie/flysystem-dropbox.

composer require spatie/flysystem-dropbox

 

Step 5: Configure Dropbox FileSystem

Now, we will create DropboxServiceProvider using the following command.

php artisan make:provider DropboxServiceProvider

Open the app.php file and add the provider class to the array.

app/config/app.php

'providers' => [
    ...
    ...
    ...
    App\Providers\DropboxDriveServiceProvider::class,
];

Open the DropboxServiceProvider.php file, and update the boot function inside the provider class.

app/Providers/DropboxServiceProvider.php

<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;

class DropboxServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        Storage::extend('dropbox', function ($app, $config) {
            $client = new DropboxClient(
                $config['authorization_token']
            );
  
            return new Filesystem(new DropboxAdapter($client));
        });
    }
}

Add Dropbox Access Key

In this step, we will add a key and secret key to the filesystem.php file.

config/filesystem.php

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

Now, add the dropbox access token to the .env file.

DROPBOX_AUTH_TOKEN=<dropbox_auth_token>

 

Step 6: Run Laravel 9 Application

Now, we will config cache using the following command and run how to store the backup on dropbox in laravel 9.

php artisan config:clear

After that, we will run the backup command.

php artisan backup:run

Also, you can schedule automatic database backups like the below code.

app/Console/Kernal.php

protected function schedule(Schedule $schedule)
{
    $schedule->command('backup:run')->daily()->at('11:00');
}

 


You might also like:

Recommended Post
Featured Post
How To Validate Form In React JS
How To Validate Form In React...

In this article, we will see how to validate a form in react js. We will validate the input type email, phone numbe...

Read More

Sep-07-2022

Laravel 9 Group By Query Example
Laravel 9 Group By Query Examp...

In this article, we will see laravel 9 group by query example. how to use group by in laravel 9. As you might expec...

Read More

Mar-29-2022

Creating Modular Laravel Applications with Domain-Driven Design (DDD)
Creating Modular Laravel Appli...

In this guide, I’ll explain how to structure a Laravel project using Domain-Driven Design (DDD) principles to crea...

Read More

Sep-27-2024

How to Create Trait in Laravel 10 Example
How to Create Trait in Laravel...

Hello developers! 👋 Today, let's dive into the wonderful world of Laravel 10 and explore one of its handy featu...

Read More

Feb-09-2024