Backup discourse from the command line


These are some simple instructions on how to backup the persistent storage of the docker container. And then how to restore them.

Backing up

First find out where your container is configured to save your persistent storage, for this open the containers/app.yml file and look for a section that looks like this

## The Docker container is stateless; all data is stored in /shared
  - volume:
      host: /var/discourse/shared/standalone
      guest: /shared
  - volume:
      host: /var/discourse/shared/standalone/log/var-log
      guest: /var/log

The volume which is mounted under /shared in guest is the one we want to backup. So now run

$ rsync -avzh /var/discourse/shared/standalone/ /var/discourse/shared/standalone.backup

to backup your files. Be aware, that your container is still running and the database might have changes which haven’t been written to disk yet. Therefore we quickly stop the container.

$ ./launcher stop app

Rsync any changes made to the persistent storage

$ rsync -avzh /var/discourse/shared/standalone/ /var/discourse/shared/standalone.backup

And start it again

$ ./launcher start app


Stop the container

$ ./launcher stop app

Delete current state

rm -r /var/discourse/shared/standalone/

Restore the backup

$ rsync -avzh /var/discourse/shared/standalone.backup/ /var/discourse/shared/standalone

And start the container again

$ ./launcher start app

How to restore data by ssh?
How to move my Discourse instance LOCALLY? Or at least the big files?
502 Bad Gatewayafter messing with host files
Bulk deleting / mass modifying users
(Alan Tan) #2

You could backup Disocourse from the command line using this script as well

The downside to this approach is there is downtime involved since you’re stopping the container.

(Roland) #3

I just tried this from the command line. But the only backup tar I see available was one i made a few days ago. Is there a way to get this so I can move back to another server?


The rsync command only creates an exact copy of the folder at /var/discourse/shared/standalone.backup/. If you want to move that folder to another server I bet you will find lots of tutorials how to use the tar command on the internet.

(Roland) #5


SO does anyone else know how to create a backup properly that I can get from the backups/default folder?

(Eli the Bearded) #6

From the command line? Not sure. It looks like you could create a rake job for that easily, based on the optional backup in the clean up uploads task. Look at lib/tasks/uploads.rake: