Being curious by nature, I wanted to see how to backup and restore Discourse in what some people might call the "traditional unix way"
In a nutshell, I just confirmed that we can use docker save
(for the base and the app containers) and tar
for the /var/discourse
directory, and completely save, transfer (backup), and restore the app this way.
I'm nearly certain (99.99%) that this method is not officially supported
by Discourse but this is an interesting backup and recovery method for any Discourse application.
Basically, here are the steps, in summary:
- Save your containers with
docker save
.
For example, if you are running a standalone app, you can save the base and the app container, like this (based on your configuration):
docker save -o /tmp/my.discourse.docker.app.tar discourse/base:2.0.20200512-1735
and also:
docker save -o /tmp/my.discourse.docker.app.tar local_discourse/app:latest
- You can also tar up the
/var/discourse
directory , as you mentioned:
cd /var/
tar -cvzf /tmp/my.var.discourse.tar.gz discourse
and then gzip your docker tar files if you wish and archive them:
gzip /tmp/my.discourse.docker*.tar
- .... and you can move these files to another server, archive them on the same server, whatever you wish, reverse the steps, and start the Discourse app without an issue.
I just confirmed this by "doing it", and deleting all container images and the /var/discourse
directory. Basically, I wiped out everything and rebuilt from the backups.
For example, to restore, you can take the saved docker images above and load the images, for example:
gzip -d /tmp/my.discourse.docker.app.tar.gz
docker load -i /tmp/my.discourse.docker.app.tar
gzip -d /tmp/my.discourse.docker.base.tar.gz
docker load -i /tmp/my.discourse.docker.base.tar
- Then, untar your original
/var/discourse
directory
cd /var
tar -xvzf /tmp/my.var.discourse.tar.gz
- Next, you need to look at your images to make sure they are properly labeled:
docker images
- and if the images are not properly labeled, make sure you tag them correctly, for example for your app image:
docker tag 58ffc74989af local_discourse/app:latest
- Then, you just do this:
cd /var/discourse
./launcher start app
and it works just fine. I just tested it (twice).
Hope this helps.
FWIW: I tried this method two different ways, doing the backup method above, wiping out all docker containers, images, and the /var/discourse
directory (totally destroying all, each time).
In each case, I was able to load my saved docker images, untar the /var/discourse
directory, run ./launcher start app
and Discourse started up flawlessly and to prove it, I could do a normal backup
from the UI, proving all was good.
Regarding the question of just tarring
up the app as a backup, and restoring, the answer is yes but you must use not only archive the /var/discourse
directory, but you must also docker save
your images. The answer is that you must archive both your folder and your docker images (like in the example above) using docker save for the images (to backup), and docker load to restore.
Keep in mind that this method is not officially supported; but out of curiosity, I wanted to see how to do it from the sys admin perspective, and found out it was easier than my replies earlier indicated.
Here is a screen capture from today, to illustrate, backing up this production Discourse site:
This results in the full archive for this site which can be complete restored and restarted from these files.
gzipping
the docker save files saves a lot of space:
Before:
After:
Be careful with how many full backups you have, as these files are huge to add to the master tar file:
In fact, you might want to move all these backups from your directory (or multiple backup directories) before you tar everything up.
See, for example, how much disk space this method takes, this case: 61 GB