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 Count Days Excluding Weekends And Holidays In Laravel 9
How To Count Days Excluding We...

In this article, we will see how to count days excluding weekends and holidays in laravel 9. Here, we will learn to...

Read More

Jan-24-2023

How to Remove Elements From JavaScript Array
How to Remove Elements From Ja...

Today we will learn how to remove elements from javascript array, you can use diffrents javascript array...

Read More

Apr-07-2021

Helper Function Example in Laravel 8
Helper Function Example in Lar...

Hello All, In this post we will see helper function example in laravel, Laravel provide in-buit global "hel...

Read More

Jun-22-2021

Laravel 8 Remove/Hide Columns While Export Data In Datatables
Laravel 8 Remove/Hide Columns...

In this article, we will see how to remove/hide columns while export data in datatables in laravel 8. When we are u...

Read More

Oct-13-2020