In this tutorial you will learn about the Laravel 8 Backup Store On DropBOX Tutorial and its application with practical example.
In this Laravel 8 Backup Store On DropBox tutorial I will show you how to take laravel site backup in DropBox. In this tutorial I will also show you how to integrate DropBox in laravel 8 to store backup on DropBox. In this example we will learn DropBox integration in Laravel 8. In this example we will be using spatie/laravel-backup package to take backup in DropBox.
Laravel 8 Backup Store On DropBOX Tutorial
In this step by step Laravel 8 Backup Store On DropBox Example I will demonstrate you how to integrate DropBox in laravel site to take site backup. Please follow instructions given below:
- Step 1 – Install Laravel 8 App
- Step 2 – Connecting App to Database
- Step 3 – Install spatie/laravel-backup
- Step 4 – Setup Dropbox as Filesystem in Laravel
- Step 5 – Configure Dropbox Details
- Step 6 – Execute Backup Command
- Step 7 – Conclusion
Step 1 – Install Laravel 8 App
First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command
1 |
composer create-project --prefer-dist laravel/laravel Blog |
Step 2 – Connecting App to Database
Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.
1 2 3 4 5 6 |
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 3 – Install spatie/laravel-backup
In this step run the following command to install spatie/laravel-backup package in laravel 8:
1 |
composer require spatie/laravel-backup |
Now, run the following command to publish this installed package:
1 |
php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider" |
Now, you need to add dropbox
details in the disk option in the config/backup.php
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?php return [ // ... 'destination' => [ // ... /* * The disk names on which the backups will be stored. */ 'disks' => [ 'dropbox', ], |
Step 4 – Setup Dropbox as Filesystem in Laravel
Now, you need to run the following command to install a Filesystem adapter for DropBox:
1 |
composer require spatie/flysystem-dropbox |
1 |
php artisan make:provider DropboxServiceProvider |
Then, inside the boot()
method add the Dropbox for the Laravel filesystem:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?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)); }); } } |
After this, register the service provider by adding the following line in the
providers
array of config/app.php
.
1 2 3 4 |
'providers' => [ // ... App\Providers\DropboxDriveServiceProvider::class, ]; |
Step 5 – Configure Dropbox Details
Now you need to configure Dropbox app with this laravel app. Go to the config directory and open filesystem.php file and add the client id, secret and callback url:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php return [ // ... 'disks' => [ // ... 'dropbox' => [ 'driver' => 'dropbox', 'authorization_token' => env('DROPBOX_AUTH_TOKEN'), ], ], ]; |
And also you need to update
.env
file of laravel 8 app. In this environment file you need to add the following Dropbox auth token:
1 |
DROPBOX_AUTH_TOKEN=<your token> |
Step 6 – Execute Backup Command
In this step we are ready to take backup run the following command to check the backup file is created or not:
1 |
php artisan backup:run |