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 https://rclone.org/install.sh | 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.

16개의 좋아요

크론 작업을 통해 매일(또는 자주) Google Drive로 백업을 동기화하지만, 드라이브의 여유 공간이 많지 않은 분들을 위한 조언입니다. rclone 명령에 --drive-use-trash=false 플래그를 추가하는 것을 권장합니다.

예시:

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

이 플래그를 사용하면 rclone은 Google Drive에서 오래된 백업을 휴지통으로 보내는 대신 바로 삭제합니다. 휴지통에 있는 파일은 30일 후에 자동으로 삭제되지만, 이 플래그를 활용하면 Drive 저장 공간을 많이 절약할 수 있습니다.

4개의 좋아요