Backup your Laravel 5 App to Dropbox

Backup your Laravel 5 App to Dropbox

Want a free way to backup your laravel app and database to dropbox? This guide should help!

Packages used

Step 1

Follow the steps to install spatie/laravel-backup and thephpleague/flysystem-dropbox

Step 2

Create a file name DropboxFilesystemServiceProvider.php in app/Providers/. Then add  App\Providers\DropboxFilesystemServiceProvider::class to your providers in config/app.php

Below is a copy of my DropboxFilesystemServiceProvider.php. Take a look at  $config[‘accessToken’] and $config[‘appSecret’]. You’ll get these when you create a dropbox app. You can set these values in your .env file.


namespace App\Providers;

use Storage;
use League\Flysystem\Filesystem;
use Dropbox\Client as DropboxClient;
use League\Flysystem\Dropbox\DropboxAdapter;
use Illuminate\Support\ServiceProvider;

class DropboxFilesystemServiceProvider extends ServiceProvider
    public function boot()
        Storage::extend('dropbox', function ($app, $config) {
            $client = new DropboxClient($config['accessToken'], $config['appSecret']);

            return new Filesystem(new DropboxAdapter($client));

    public function register()

Step 3

Create a Dropbox API App

Make sure you generate an access token. Save the access token and app secret in your .env file. Generating an access token will create a folder Apps in your Dropbox folder. This is where your backups will be saved.

Step 4

Edit config/laravel-backup.php and set ‘disks’ => [‘dropbox’] for destination and monitorBackups. If you do not have a laravel-backup.php file in your config folder, run php artisan vendor:publish –provider=”Spatie\Backup\BackupServiceProvider”

Step 5

Add a dropbox filesystem to config/filesystems.php

'dropbox' => [
 'driver' => 'dropbox',
 'accessToken' => env('DROPBOX_ACCESS_TOKEN'),
 'appSecret' => env('DROPBOX_APP_SECRET'),

Step 6

Edit kernel.php in app Console/. This will run your backup and cleanup old backups. You can define how many backups you save in config/laravel-backup.php.

// app/Console/Kernel.php

protected function schedule(Schedule $schedule)

Step 7

Setup scheduler to run your backup. You can do this from a cron job or if you’re using Forge, you can set it up there. More documentation here.

Screen Shot 2015-07-09 at 9.47.32 PM

That’s It!

These same steps can be used to backup your app to several other cloud services. To use other FileSystems, check out Flysystem.

Hope these steps help you setup your own Laravel backup. Please leave a comment below if you have any issues.

28 thoughts on “Backup your Laravel 5 App to Dropbox

  1. It doesn’t seem to work for me. My scheduler log on Forge only returns:

    Start backing up
    Database dumped
    Start zipping 1 files…
    Zip created!
    Start uploading backup to dropbox-filesystem…

    Call to undefined method League\Flysystem\Filesystem::createDropboxDriver

    Any ideas? I followed the instructions precisely.

    1. Just figured it out. Forgot to add this too the ‘providers’ in config/app.php:


  2. Hi Tim

    I followed all the steps, but got this when trying to update :

    $ php artisan backup:run
    PHP Warning: The use statement with non-compound name 'Auth' has no effect in /var/www/app/app/Http/helpers.php on line 4
    Start backing up
    Database dumped
    Determining which files should be backed up...
    Start zipping 375 files...
    Zip created!
    Start uploading backup to dropbox-filesystem...

    Call to undefined method League\Flysystem\Filesystem::createDriver

    Backup to local filesystem works, using the dropbox filesystem also works.

    This is in my composer.json :

    "graham-campbell/flysystem": "*",
    "spatie/laravel-backup": "^2.5",
    "league/flysystem-dropbox": "^1.0"

    and in config/app.php :


    all other files were updated/created following your instructions.

    Any ideas would be much appreciated !


  3. hi Tim, thanks for replying. My helpers.php contains some functions to help build forms. There was a useless “use Auth;” at line 4, which I removed, so the artisan’s warning is gone.

    When I run php artiusan backup:run, this shows up in the log file :

    [2015-08-25 10:15:49] local.ERROR: exception 'BadMethodCallException' with message 'Call to undefined method League\Flysystem\Filesystem::createDriver' in /var/www/app/vendor/league/flysystem/src/Plugin/PluggableTrait.php:85
    Stack trace:
    #0 [internal function]: League\Flysystem\Filesystem->__call('createDriver', Array)
    #1 [internal function]: League\Flysystem\Filesystem->createDriver(NULL)
    #2 /var/www/app/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php(347): call_user_func_array(Array, Array)
    #3 [internal function]: Illuminate\Filesystem\FilesystemAdapter->__call('createDriver', Array)
    #4 [internal function]: Illuminate\Filesystem\FilesystemAdapter->createDriver(NULL)
    #5 /var/www/app/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php(251): call_user_func_array(Array, Array)
    #6 /var/www/app/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php(100): Illuminate\Filesystem\FilesystemManager->__call('createDriver', Array)
    #7 /var/www/app/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php(100): Illuminate\Filesystem\FilesystemManager->createDriver(NULL)
    #8 /var/www/app/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php(83): Illuminate\Filesystem\FilesystemManager->resolve('dropbox')
    #9 /var/www/app/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php(72): Illuminate\Filesystem\FilesystemManager->get('dropbox')
    #10 /var/www/app/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(210): Illuminate\Filesystem\FilesystemManager->disk('dropbox')
    #11 /var/www/app/vendor/spatie/laravel-backup/src/Commands/BackupCommand.php(217): Illuminate\Support\Facades\Facade::__callStatic('disk', Array)
    #12 /var/www/app/vendor/spatie/laravel-backup/src/Commands/BackupCommand.php(217): Illuminate\Support\Facades\Storage::disk('dropbox')
    #13 /var/www/app/vendor/spatie/laravel-backup/src/Commands/BackupCommand.php(44): Spatie\Backup\Commands\BackupCommand->copyFileToFileSystem('/tmp/laravel-ba...', 'dropbox')
    #14 [internal function]: Spatie\Backup\Commands\BackupCommand->fire()
    #15 /var/www/app/vendor/laravel/framework/src/Illuminate/Container/Container.php(502): call_user_func_array(Array, Array)
    #16 /var/www/app/vendor/laravel/framework/src/Illuminate/Console/Command.php(150): Illuminate\Container\Container->call(Array)
    #17 /var/www/app/vendor/symfony/console/Command/Command.php(259): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #18 /var/www/app/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #19 /var/www/app/vendor/symfony/console/Application.php(878): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #20 /var/www/app/vendor/symfony/console/Application.php(195): Symfony\Component\Console\Application->doRunCommand(Object(Spatie\Backup\Commands\BackupCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #21 /var/www/app/vendor/symfony/console/Application.php(126): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #22 /var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(100): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #23 /var/www/app/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #24 {main}

    I started looking at the code mentioned in the log, but it didn’t make much sense to me 🙂

  4. I solved it by removing backup and dropbox, then reinstalling. I guess it might have had something to with file permissions (but I don’t really know). My application was recently updated from 5.0 to 5.1..maybe that had something to do with it. Anyways, all is well now 🙂

  5. I got this error.
    Call to undefined method League\Flysystem\Filesystem::createDriver

    is cause by previously this array in config/filesystem.php outter level.

    The fix, this dropbox array should be inside “disk” array. Same level with other providers.
    ‘dropbox’ => [
    ‘driver’ => ‘dropbox’,
    ‘accessToken’ => env(‘DROPBOX_ACCESS_TOKEN’),
    ‘appSecret’ => env(‘DROPBOX_APP_SECRET’),

  6. Thanks for the tuto !

    Everything works but when I try a deploy on my Forge server I’ve this error

    Generating autoload files
    > php artisan clear-compiled
    Fatal error: Class ‘App\Providers\DropboxFilesystemServiceProvider’ not found

    Script php artisan clear-compiled handling the post-install-cmd event returned with an error

    Error Output:

    Any idea why ?

  7. On Forge getting:
    There are no commands defined in the “backup” namespace.
    Anybody knows solution?

  8. First of thanks for such a nice tutorial… Its of great help.

    I tried to follow your instructions and am good to go. I can now run artisan commands and get the backups done and copied to local as well as dropbox.

    At the time being I am using Dropbox_Token that is generated for a user that I have kept in .env file.

    My goal is to provide a feature in my app where admin can allow access to his dropbox and then the laravel app would keep storing the backups in his dropbox. I would like to show if there is any dropbox account linked and the ability to change it and link another (one at a time only). Thanks in advance

  9. Copying .zip file failed because: Could not connect to disk dropbox because: exception ‘Exception’ with message ‘The Dropbox SDK uses 64-bit integers, but it looks like we’re running on a version of PHP that doesn’t support 64-bit integers (PHP_INT_MAX=2147483647). Library: “/home/vagrant/projects/calmacons_master/vendor/dropbox/dropbox-sdk/lib/Dropbox/RequestUtil.php”‘ in /home/vagrant/projects/calmacons_master/vendor/dropbox/dropbox-sdk/lib/Dropbox/RequestUtil.php:22

Leave a Reply

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