# Restore a backup from the command line

**URL:** https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034
**Category:** Self-Hosting
**Tags:** how-to
**Created:** [January 31, 2019, 4:36pm UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034 "2019-01-31T16:36:07Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [January 31, 2019, 4:36pm UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/1 "2019-01-31T16:36:07Z")

</div>

> 🔖 This guide explains how to restore a Discourse backup from the command line without using the Discourse web UI.
> 
> 🙋 Required user level: Administrator
> 
> 🔧 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`

> 📣 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.

> ⚠ **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.

> 💡 If [Nginx is used as reverse proxy](https://meta.discourse.org/t/running-other-websites-on-the-same-machine-as-discourse/17247) 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:

```plaintext
cd /var/discourse

```

1. Enter the Discourse Docker app container:

```plaintext
./launcher enter app

```

1. Enable restore functionality:

```plaintext
discourse enable_restore

```

1. Restore the backup file:

```plaintext
discourse restore sitename-2019-02-03-042252-v20190130013015.tar.gz

```

> 💡 **Tip:** If you run `discourse restore` without a filename, it will list all available backup files.

> ⚠ If your site’s `backup_location` setting is configured to use S3, but you manually uploaded the backup file to the local filesystem, you need to specify `--location local`:
> 
> ```plaintext
> discourse restore --location local sitename-2019-02-03-042252-v20190130013015.tar.gz
> 
> ```
> 
> Similarly, use `--location s3` to restore directly from an S3 backup without downloading it first.

1. Exit the Discourse Docker app container:

```plaintext
exit

```

## Rebuild

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

> 📣 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!

```plaintext
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 the `disable_emails` site setting to “no” to re-enable email.

🎉 That’s it. Your Discourse server is successfully restored.

> Last edited by @pfaffman 2025-05-18T19:32:40Z
> 
> > **Check document**
> >
> > Perform check on document:

---

<div class="post-metadata">

### Author: ![gregcaporaso](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gregcaporaso/32/383703_2.png) [@gregcaporaso](https://meta.discourse.org/u/gregcaporaso)
#### Post date: [May 4, 2024, 1:20pm UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/59 "2024-05-04T13:20:34Z")

</div>

These instructions worked for us to restore from backup, but we had to modify the `discourse restore` command to:

```shell
discourse restore --location local sitename-2019-02-03-042252-v20190130013015.tar.gz

```

(my example uses the filename from the example above) to get the restore to find the backups that we had put in the `/var/discourse/shared/standalone/backups/default` directory (as opposed to backups that were stored on s3).

---

<div class="post-metadata">

### Author: ![Isambard](https://avatars.discourse-cdn.com/v4/letter/i/858c86/32.png) [@Isambard](https://meta.discourse.org/u/Isambard)
#### Post date: [July 1, 2024, 11:08pm UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/60 "2024-07-01T23:08:59Z")

</div>

Is the rebuild after restore necessary?

Also, I restored to a new server where there is an NGINX reverse proxy which then passes onto the upstream discourse. I therefore disabled SSL on discourse, but I noticed that during the restore:

`Remapping 'https://example.com' to 'http://example.com'`

Is this remapping all internal links? Is undoing this as simple as `discourse remap http://example.com https://example.com`?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 2, 2024, 1:06pm UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/61 "2024-07-02T13:06:35Z")

</div>

> [@Isambard](#):
>
> Is the rebuild after restore necessary

No.

> [@Isambard](#):
>
> Is this remapping all internal links?

Looks like it. Yes you can remap them.

You should set the force\_https variable.

---

<div class="post-metadata">

### Author: ![pinder99](https://avatars.discourse-cdn.com/v4/letter/p/dfb087/32.png) [@pinder99](https://meta.discourse.org/u/pinder99)
#### Post date: [August 29, 2024, 9:20pm UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/62 "2024-08-29T21:20:18Z")

</div>

if backup is 15gb , how much space is needed to restore ?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [August 29, 2024, 9:34pm UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/63 "2024-08-29T21:34:14Z")

</div>

Is that just the database or uploads too?

Probably 3-5x that much.

---

<div class="post-metadata">

### Author: ![pinder99](https://avatars.discourse-cdn.com/v4/letter/p/dfb087/32.png) [@pinder99](https://meta.discourse.org/u/pinder99)
#### Post date: [August 30, 2024, 6:03am UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/64 "2024-08-30T06:03:57Z")

</div>

it is database+upload 15gb , i have 20gb space on 60gb HD but still restore fail each time , i need atleast 50-60gb space to restore ?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [August 30, 2024, 8:53am UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/65 "2024-08-30T08:53:18Z")

</div>

You need enough space for the backup, the uploads, and the uncompressed database.

You might try to restore a database only backup first and then copy the uploads by hand with rsync.

---

<div class="post-metadata">

### Author: ![Ethsim2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ethsim2/32/522255_2.png) [@Ethsim2](https://meta.discourse.org/u/Ethsim2)
#### Post date: [November 7, 2024, 4:53pm UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/66 "2024-11-07T16:53:20Z")

</div>

I’ve verified my admin account on self host, and uploaded a `.sql.gz` backup, not a `.tar.gz`.

Restoring on the UI isn’t fruitful so i performed from “Restore the backup” at the command line, giving `[FAILED]` at the end of the `discourse restore` process, might the input file from an official hosting being `.tar.gz` cause process to pass?

My official hosting is a few days old, and my self host started working properly today after [changing SMTP values](https://meta.discourse.org/t/troubleshoot-email-on-a-new-discourse-install/16326) in `container.yml`

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [November 7, 2024, 7:02pm UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/67 "2024-11-07T19:02:44Z")

</div>

You’ll need to include what error you got. The filename has version in formation in it, though, so if you’ve renamed the file, you’ll likely need to name it back, changing just the words at the beginning of the filename.

---

<div class="post-metadata">

### Author: ![helmi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/helmi/32/114772_2.png) [@helmi](https://meta.discourse.org/u/helmi)
#### Post date: [February 15, 2025, 11:18am UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/68 "2025-02-15T11:18:42Z")

</div>

Is there a documentation for `discourse restore`somewhere? as there seems to be a `--location local`switch I assume there would also be one for S3?

I’m looking to restore from S3 located backups and avoiding having to download them manually beforehand.

EDIT: nvmd. I just found out that `discourse restore --location s3 $filename` seem to work just fine.

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [February 15, 2025, 12:48pm UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/69 "2025-02-15T12:48:31Z")

</div>

Because I have enabled S3 in app.yml, just pure `discourse restore <filename>` worked just fine.

I think if you’ll seach for `backup restore s3` you find the right post.

---

<div class="post-metadata">

### Author: ![Ethsim2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ethsim2/32/522255_2.png) [@Ethsim2](https://meta.discourse.org/u/Ethsim2)
#### Post date: [May 18, 2025, 12:34pm UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/70 "2025-05-18T12:34:33Z")

</div>

Hi, i’ve completed this process using `s3(-cli)` as my `scp` and a change in outgoing mail provider from MailGun to Brevo

Since the restore i can’t find a way to remove the banner?

 ![IMG_8574](https://global.discourse-cdn.com/meta/original/4X/8/7/4/8747c985dd6e1c139f3ab412ae4a06cac63c65b5.jpeg)

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [May 18, 2025, 1:07pm UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/71 "2025-05-18T13:07:37Z")

</div>

> [@Create, download, and restore a backup of your Discourse database](https://meta.discourse.org/t/create-download-and-restore-a-backup-of-your-discourse-database/122710/1):
>
> The restore process automatically sets the `disable emails` setting to “non-staff”, so emails aren’t sent to your site’s users until you’re ready.

The easiest way to remove the banner is to enable emails in the site settings

 ![Disable emails](https://global.discourse-cdn.com/meta/original/4X/3/7/a/37a1ab8cce325c0bb3b474b2c9fe5f3bebcde976.jpeg)

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [May 18, 2025, 3:16pm UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/72 "2025-05-18T15:16:36Z")

</div>

> [@Moin](#):
>
> The easiest way to remove the banner is to enable emails in the site settings

Right. You could also hide it with css! 😂

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [May 18, 2025, 6:07pm UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/73 "2025-05-18T18:07:51Z")

</div>

True. I was a bit cautious recommending this because I had to think of [Air theme hides "outgoing email disabled" warning](https://meta.discourse.org/t/air-theme-hides-outgoing-email-disabled-warning/238957)

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [May 18, 2025, 7:30pm UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/74 "2025-05-18T19:30:04Z")

</div>

> [@Moin](#):
>
> I was a bit cautious recommending this because I had to think of [Air theme hides “outgoing email disabled” warning](https://meta.discourse.org/t/air-theme-hides-outgoing-email-disabled-warning/238957)

**Every time you restore a backup, email is automatically disabled for non-staff.** I imagine this was added to the code just a couple times after a restore was made to a testing server that started flooding its users with notifications for a server that they weren’t supposed to know existed.

I updated the OP accordingly:

> [@Discourse](#):
>
> ## 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.

---

<div class="post-metadata">

### Author: ![thoka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thoka/32/115652_2.png) [@thoka](https://meta.discourse.org/u/thoka)
#### Post date: [May 18, 2025, 10:05pm UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/75 "2025-05-18T22:05:18Z")

</div>

Note for the how-to:

If you restore backups regularly for testing purposes and your test server is properly configured, to send emails to a debug email service (like [GitHub - maildev/maildev: 📫 SMTP Server + Web Interface for viewing and testing emails during development. · GitHub](https://github.com/maildev/maildev)) you may want to enable emails via scripting:

```bash
docker exec -it app /bin/bash --login \
-c "rails runner 'SiteSetting.disable_emails=\"no\";'"

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [May 18, 2025, 10:22pm UTC](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034/76 "2025-05-18T22:22:02Z")

</div>

In that case you might want to set DISCOURSE\_DISABLE\_EMAILS to no in your app.yml. (and also DISCOURSE\_ENABLE\_RESTORE to make restore easier to)
