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
Laravel 10 AJAX CRUD Operations Example
Laravel 10 AJAX CRUD Operation...

In this article, we will see the laravel 10 ajax crud operations example. Here, we will learn about ajax crud operation...

Read More

Feb-27-2023

Laravel 10 Create AJAX Pagination Example
Laravel 10 Create AJAX Paginat...

In this article, we will see laravel 10 create an ajax pagination example. Here, we will learn about how to create...

Read More

Apr-17-2023

How to Get Request Header in Laravel 10
How to Get Request Header in L...

Ever wondered how to access request headers in your Laravel 10 application? Join me as I guide you through a quick and s...

Read More

Dec-11-2023

How To Import CSV File In MySQL Using Node.js
How To Import CSV File In MySQ...

In this tutorial we will see how to import CSV file in MySQL using Node.js. Import and export CSV/EXCEL file in Nod...

Read More

Jul-30-2021