Laravel 10 Backup Store On DropBOX using Spatie Example

Laravel 10 Backup Store On DropBOX using Spatie Example

If you want to keep backup of your Laravel application on cloud server for free. So you can keep backup of your Laravel web application on dropbox. So, In this tutorial, you will learn how to store backup on dropbox using spatie/laravel-backup package.

How To Store Backup On Dropbox In Laravel 10

By using the following steps, you can save or store Laravel 10, 9, 8 application backup on dropbox storage:

  • Step 1 – Create and Setup Dropbox App
  • Step 2 – Create New Laravel 10 Project
  • Step 3 – Setup Database with Laravel Project
  • Step 4 – Installing spatie/laravel-backup
  • Step 5 – Setup Filesystem with DropBox
  • Step 6 – Setup Dropbox with Laravel Project
  • Step 7 – Take Backup By Command

Step 1 – Create and Setup Dropbox App

Go to Dropbox Console. And create a new project as following in below picture:

Now, fill in the form and click “Generate” button to generate an access token.

Now, you have got Access token from dropbox. Please save it in any text file. Because you need to update these values in the .env file of your Laravel 10 app.

Step 2 – Create New Laravel 10 Project

Once you have created dropbox application. Now, you need to open command prompt or terminal.

Then execute the following command into it download or install Laravel 10 new setup in your server:

composer create-project --prefer-dist laravel/laravel Blog

Step 3 – Setup Database with Laravel Project

Once you have installed laravel project in your server. Then you need to setup database with laravel project.

So, visit to the root directory to download laravel app. And open .env file. And setup database details like the following:

 DB_CONNECTION=mysql 
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=here your database name here
DB_USERNAME=here database username here
DB_PASSWORD=here database password here

Step 4 – Installing spatie/laravel-backup

In this step, execute the following command on terminal or cmd to install spatie/laravel-backup package in Laravel 10 project:

composer require spatie/laravel-backup

Then execute the following command on terminal to publish this installed package:

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

Note that, it will publish the configuration file in config/backup.php. Now, configure your backup according to your requirement.

Now, you need to add dropbox details in the disk option in the config/backup.php.

<?php
   
return [
   
    // ...

    'destination' => [
  
        // ...

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

Step 5 – Setup Filesystem with DropBox

In this step, you need to execute the following command on terminal to install a Filesystem adapter for Dropbox. So, run the following command in your terminal:

composer require spatie/flysystem-dropbox
php artisan make:provider DropboxServiceProvider

Then, inside the boot() method add the Dropbox for the Laravel filesystem:

<?php
 
namespace App\Providers;
 
use Storage;
use League\Flysystem\Filesystem;
use Illuminate\Support\ServiceProvider;
use Spatie\Dropbox\Client as DropboxClient;
use Spatie\FlysystemDropbox\DropboxAdapter;
 
class DropboxServiceProvider extends ServiceProvider
{
    // ...
    public function boot()
    {
        Storage::extend('dropbox', function ($app, $config) {
            $client = new DropboxClient(
                $config['authorization_token']
            );
 
            return new Filesystem(new DropboxAdapter($client));
        });
    }
}

Once you have created provider in laravel project. Now, you need to register the service provider by adding the following line in the providers array of config/app.php.

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

Step 6 – Setup Dropbox with Laravel Project

In this step, configure Dropbox app with this laravel app. So, open your Laravel 10 project in any text editor. Then navigate the config directory and open filesystem.php file and add the client id, secret and callback url:

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

And also you need to update .env file of Laravel 10 app. So, open .env file and add the following Dropbox auth token:

DROPBOX_AUTH_TOKEN=<your token>

Step 7 – Take Backup By Command

In this step, open your terminal or cmd and execute the following command to take the backup of your laravel project:

php artisan backup:run

Conclusion

Laravel 10 store backup on dropbox example tutorial, you have learned how to store Laravel 10 app backup on dropbox using spatie/laravel-backup.

Recommended Laravel Posts

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *