Use rclone to sync backups to Dropbox or Google Drive

There is a plugin that allows you to sync your discourse backups to various cloud storage providers. Unfortunately, it currently doesn’t work with Dropbox and Google Drive. If you nevertheless want to store your backup on your Dropbox or Google Drive follow the steps below. I will use dropbox as an example but the instructions will also work with any other backend supported by rclone.

Disclaimer: The instructions have been tested on Ubuntu 16.04. and they work for me but I am not an expert at this, so there may be better ways of doing this. Feel free to correct me and I’ll be happy to update this post.

Install rclone

sudo curl | sudo bash

If the above command fails, you may be asked to install an unzipping tool:

sudo apt-get install unzip

Grant access to dropbox

This is the trickiest part because you need a browser to grant rclone access to your dropbox and that is not easy, to say the least, when you’re ssh-ing into a VPS. So you need to proceed in two steps:

On your server, do

sudo rclone config

and follow the instructions. At some point you will be asked

Use auto config?

And you answer N

Now you have to switch to your desktop machine to obtain the authentication token. This means you need to install rclone on your desktop machine (Rclone for WIndows is here: Rclone downloads) and follow the instructions for Remote Setup.

Once you have obtained your token and pasted it into the ssh prompt that was waiting for it, you can verify that everything worked as intended by getting a list of all directories in your dropbox:

rclone lsd drobo:

where drobo is the name you assigned to your dropbox earlier.

Copy your backups to dropbox

Locate your backup files. Usually, you will find them in /var/discourse/shared/standalone/backups/default. If you are using a two container setup, they will probably be at /var/discourse/shared/web-only/backups/default

The command to copy your backups to the backups directory in your dropbox will be

sudo rclone copy /var/discourse/shared/standalone/backups/default --exclude tmp/ drobo:backups

Setup a cron job to copy your backups to Dropbox

To copy the backups every day at 6 pm add the following to your crontab do:

crontab -e

and add

0 18 * * * rclone copy /var/discourse/shared/standalone/backups/default --exclude tmp/ drobo:backups

You can run it more frequently if you want as only new files will be copied over anyway.

Note that the the copy option will add more and more backups to your dropbox even when the ones on your server get deleted. If you only want to keep only ones that are also kept on your server, use sync instead of copy.


Advice for those who often (for example, daily) sync their backups on Google Drive through a cron job and don’t have a lot of free space on their drive, I’d recommend adding the flag --drive-use-trash=false to their rclone command.


rclone sync /var/discourse/shared/standalone/backups/default --drive-use-trash=false --exclude tmp/ discourse:

With this flag, rclone will delete outdated backups from Google Drive instead of sending them to the trash, where they lay 30 days before being automatically deleted. It can save a lot of Drive storage.