Restore a backup from the command line

:bookmark: This guide explains how to restore a Discourse backup from the command line without using the Discourse web UI.

:person_raising_hand: Required user level: Administrator

:wrench: Console access required

Here’s how to restore a Discourse backup from the command line, without ever booting the Discourse web UI. This is handy when you’re moving servers.

Prerequisites

Before you start, make sure you complete the following steps:

  1. Download the latest backup file from the source Discourse instance.
  2. Bootstrap the destination Discourse instance by running ./discourse-setup or copying your existing app.yml.
  3. Ensure the destination Discourse instance is on the latest version. Update it if necessary.

Transfer the backup

  1. SSH into the destination server, or otherwise create the backup folder there:

mkdir -p /var/discourse/shared/standalone/backups/default

  1. Upload your backup file to the destination server.

scp /path/to/backup/backup.tar.gz root@192.168.1.1:/var/discourse/shared/standalone/backups/default

Be sure to replace the paths, filenames, and server names with the ones you are using – but you do want the backup file to end up in:

/var/discourse/shared/standalone/backups/default

:mega: You can also upload and download your Discourse backup file from popular web storage sites such as Google Drive, Dropbox, OneDrive, etc – you’ll need to look up the specific command line instructions based on your preferred web storage provider.

:warning: DO NOT CHANGE THE FILENAME OF THE BACKUP! Discourse treats the backup filename as metadata, so if you change the filename, restoring will not work. Stick with the original file name.

Replace /path/to/backup/discourse-xyz.tar.gz with the local path of your backup file, and replace <server_ip_address> with the IP address of destination server.

:bulb: If Nginx is used as reverse proxy make sure all paths to the backup are readable by the container and Nginx can read the .sock file.

Restore the backup

  1. Access your destination server and navigate to the Discourse folder:
cd /var/discourse
  1. Enter the Discourse Docker app container:
./launcher enter app
  1. Enable restore functionality:
discourse enable_restore
  1. Restore the backup file:
discourse restore sitename-2019-02-03-042252-v20190130013015.tar.gz
  1. Exit the Discourse Docker app container:
exit

Rebuild

After restoring the backup, you may choose to rebuild the destination instance to ensure all settings and configurations are applied correctly.

:mega: Now is a good time to update /var/discourse/containers/app.yml with full HTTPS, additional plugins or CDN configuration. Compare the app.yml configuration of both instances to make sure!

cd /var/discourse
./launcher rebuild app

Enable Email

When a backup is restored, outgoing mail for non-staff is disabled. You don’t want your test server, new server, or server that you just restored a backup for some other reason to start emailing your users! Change site setting “disable_emails” to re-enable email.

:tada: That’s it. Your Discourse server is successfully restored.

78 Likes
Move your Discourse Instance to a Different Server
Any other way to take backup and restore?
How easy is it to move to another server?
HELP! My Discourse just deleted everything?
Restore backup is broken
Best Practices for Backups
How to migrate Discourse from one server to another with the same DNS name
Problem upgrading Discourse
Quick question about site backups
Is there any way to restore your site from backup in the terminal?
Migrating Discourse from one DigitalOcean droplet to another without downtime
Restore Failure - S3 (compatible) backup
Set up file and image uploads to S3
Unable to migrate to S3, therefore unable to restore from backup
Upgrading v2.2.0.beta4 forum with unknown local changes
Restore backup right away after installing Discourse
My install broke after updating, how can I fix it?
"EXCEPTION: psql failed: DETAIL: Key (post_id)=(36946) is duplicated."
Migrate from another forum to Discourse
My install is 16,359 commits behind! Advice?
Index_users_on_username_lower error during database restore: import failed
Migration failed: relation "user_required_fields_versions" already exists
How can I manually verify via the CLI and bypass the Congratulations, you installed Discourse! screen?
Configuring automatic backups
Intended path to migrate S3 to local
Problem when updating Discourse Forum
Failed to restore from the backup
Steps involved to downgrade from 2GB to 1GB on DO?
Forum offline: Restore is not working through web
Forum offline: Restore is not working through web
Testing Restore - not working
Entire site is a blank page after upgrade
"discourse: command not found" when trying to restore a backup from the command line
Stuck with 500 error after weird bugs and a rebuild
Plesk server migration
Discourse broken after moving servers
Stuck and lost updating forum, problems with PG migration
How to manually migrate s3 files to local?
How to properly package discourse as an image
How can I get the current version information from my backup?
Backup Prod -> Snap -> Build Test -> Change Address
Trying to recover an installation
2FA with OTP broken after restoring from Backup
I'm trying to migrate an old discourse by creating a new discourse, but I'm having trouble
Recover from filesystem backup: can't rebuild nor start
Error: Can't notify admin while restoring backup during a migration to a fresh install
MKJ's Opinionated Discourse Deployment Configuration
Migrate from AWS to Digital Ocean with 2 containers, spaces and 2 CDNs
Cannot restore database: sql key is duplicated
Finding UI generated backup and restoring site
Backup discourse from the command line
Migration to a Self-Hosted solution from Kubernetes
How to download the backup file without SMTP function?
Redis Problems? (Forum broken after upgrade)
Can't upload backup
Can't upload backup
Can't upload backup
Rate limiter issues when uploading a backup file / can't disable rate limiter
Help restoring - system hung at midnight
Help restoring - system hung at midnight
Uploads missing after restore
My install is 16,359 commits behind! Advice?
Issues Rebuilding After Upgrade to Ubuntu 22.04