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.
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
In this step, we will install the laravel 9 application using the following command.
composer create-project --prefer-dist laravel/laravel laravel-9-dropbox
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',
],
],
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.
In this step, we will install spatie/flysystem-dropbox package using the following command.
Read more: spatie/flysystem-dropbox.
composer require spatie/flysystem-dropbox
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>
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: