How to back up and restore Discourse
This document shows how to back up and restore Discourse.
There are two ways to backup and restore Discourse. The first one is using the backup functionality provided by Discourse.
The second one consists in backing up and restoring the database directly, that can be done easily thanks to Charmed PostgreSQL and Charmed PostgreSQL K8s.
For this How-to, it is supposed that S3 has been configured (see how to configure S3. Running the Discourse Operator without S3 configured is not recommended as it will not work in HA mode and it is risky and data loss can happen if the workload container is restarted.
Backup and restore using Discourse backup functionality
It is recommended to configure the s3_backup_bucket
to a bucket that will store the
backups (see how to configure S3). If s3_backup_bucket
is not set,
the backups will be placed in one of the workload containers,
in the path /srv/discourse/app/public/backups/
. This will make HA deployments work incorrectly.
Besides, it will be necessary to get the backup files and put them in a more secure place,
using Discourse admin interface or juju scp.
A backup can be made by a site administrator using the web interface. See Create, download, and restore a backup of your Discourse database for the full process.
Backups can also be configured to be automatically created. See Configure automatic backups for Discourse for the full process.
Backup and restore using PostgreSQL
If the same S3 bucket can be used in the restored Discourse instance, then it is only necessary to backup the database.
This can be easily done with Charmed PostgreSQL and Charmed PostgreSQL K8s. See How to create and list backups in Charmed PostgreSQL or How to create and list backups in Charmed PostgreSQL K8s for the full procedure.
To restore Discourse, once it is deployed and configured as the Discourse instance to restore, it is only necessary to restore the database. The instructions, depending on the configuration, can be found in the next links:
- Charmed PostgreSQL. Local backup: Charmhub | Deploy Charmed PostgreSQL VM using Charmhub - The Open Operator Collection
- Charmed PostgreSQL. Migrate a cluster: https://charmhub.io/postgresql/docs/h-migrate-cluster-via-restore
- Charmed PostgreSQL K8s. Local backup: Charmhub | Deploy Charmed PostgreSQL K8s using Charmhub - The Open Operator Collection
- Charmed PostgreSQL K8s. Migrate a cluster: https://charmhub.io/postgresql-k8s/docs/h-migrate-cluster-via-restore
S3 and the backup and restore procedure
If S3 is configured, the S3 bucket contains all the uploaded files. This information should also be backed up, but it is not explained in this How-to.
If the S3 bucket used in the restored Discourse is not the same bucket as the original one, extra steps must be
done, see moving from one S3 bucket to another
for more information. You can run the remap command with: juju ssh --container discourse discourse-k8s/0 pebble exec --context=discourse --user=_daemon_ -w=/srv/discourse/app/ -- bundle exec /srv/discourse/app/script/discourse backup
and rake tasks with a command like: juju ssh --container discourse discourse-k8s/0 pebble exec --context=discourse --user=_daemon_ -w=/srv/discourse/app/ -- bundle exec rake posts:rebake
.