# Backup discourse from the command line

**URL:** https://meta.discourse.org/t/backup-discourse-from-the-command-line/64364
**Category:** Self-Hosting
**Tags:** backups, how-to
**Created:** [6월 12, 2017, 3:59오후 UTC](https://meta.discourse.org/t/backup-discourse-from-the-command-line/64364 "2017-06-12T15:59:45Z")
**Posts on this page:** 13
**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: [6월 12, 2017, 3:59오후 UTC](https://meta.discourse.org/t/backup-discourse-from-the-command-line/64364/1 "2017-06-12T15:59:45Z")

</div>

> 🔖 This guide covers how to back up and restore your Discourse site using command line tools, specifically designed for self-hosted environments.
> 
> 🙋 Required user level: Administrator

> ℹ You can use the below placeholders to automatically fill out the command line prompts in this guide:

## Backing up

To create a backup of your Discourse site, follow these steps:

1. Enter the container:

```plaintext
./launcher enter app

```

1. Run the backup:

```plaintext
discourse backup
exit

```

This will print out the final filename of your backup. Download the backup and container configuration (if needed) to your local machine:

```
scp =USER=@=HOST=:/var/discourse/shared/standalone/backups/default/=FILENAME= .
scp =USER=@=HOST=:/var/discourse/containers/app.yml .

```

## Restoring

To restore a Discourse backup, follow these steps:

1. Install a Discourse site on the server you are restoring to.

If you’re testing this procedure multiple times, you can wipe the data on your test server.

> **Wipe Discourse data (optional)**
>
> ```plaintext
> ./launcher stop app
> ./launcher destroy app
> rm -r /var/discourse/shared/standalone/
> mkdir -p /var/discourse/shared/standalone/backups/default/
> 
> ```
> 
> * * *

1. Upload the backup file:

```plaintext
scp =FILENAME= =USER=@=HOST=:/var/discourse/shared/standalone/backups/default/

```

1. Enter the container and start the restore:

```plaintext
./launcher enter app
discourse enable_restore
discourse restore =FILENAME=

```

If you happen to forget what the filename was, run the “discourse restore” command by itself to get a list of available backup files.

> ℹ For a two-container setup, use `./launcher enter web_only` and replace `standalone` with `web-only` in the path to backups.

For additional information about restoring Discourse backups, see [Restore a backup from the command line](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034).

> Last edited by @SaraDev 2024-08-23T20:50:17Z
> 
> > **Check document**
> >
> > Perform check on document:

---

<div class="post-metadata">

### Author: ![th21](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/th21/32/211915_2.png) [@th21](https://meta.discourse.org/u/th21)
#### Post date: [1월 2, 2025, 7:48오후 UTC](https://meta.discourse.org/t/backup-discourse-from-the-command-line/64364/31 "2025-01-02T19:48:15Z")

</div>

> [@Discourse](#):
>
> `scp root@18.177.57.246:/var/discourse/containers/app.yml .`

이 명령어는 어디서 실행해야 하나요? 클라우드 서버 터미널에서 실행해야 하나요, 아니면 로컬 머신에서 실행해야 하나요?  
어디서 실행해도 권한 거부(permission denied) 오류가 발생합니다.

 ![A screenshot of a terminal window showing an unsuccessful ssh login attempt with the message "Permission denied (publickey)." (Captioned by AI)](https://global.discourse-cdn.com/meta/original/4X/e/b/c/ebc14549258cf31f25c5273c22b90d027099c8e0.png)

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [1월 2, 2025, 8:08오후 UTC](https://meta.discourse.org/t/backup-discourse-from-the-command-line/64364/32 "2025-01-02T20:08:18Z")

</div>

> [@th21](#):
>
> 이 명령어를 어디서 실행해야 하나요?

로컬 머신에서 실행하세요.

SSH 키를 사용하여 연결하고 계신가요? 에러와 관련이 있습니다.

그렇다면 명령어는 다음과 같아야 합니다:

```bash
scp -i /path_to_your_key/your_key.pem root@147.43.15.199:/var/discourse/shared/standalone/backups/default/discourse-2024-12-25-033740-v20241211222608.tar.gz .

```

---

<div class="post-metadata">

### Author: ![Alon1](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alon1/32/197167_2.png) [@Alon1](https://meta.discourse.org/u/Alon1)
#### Post date: [2월 17, 2025, 8:56오후 UTC](https://meta.discourse.org/t/backup-discourse-from-the-command-line/64364/33 "2025-02-17T20:56:10Z")

</div>

새 서버로 Discourse 설치 환경을 마이그레이션하려는 시나리오가 있습니다.  
제 계획은 다음과 같습니다:

1. 새로운 빈 Discourse 설치 환경 생성
2. 기존 Discourse를 백업하고, `scp`를 사용하여 백업 파일을 새 서버로 전송한 후 복원
3. 모든 S3 파일(이미지 등)을 다른 계정에 있는 새 S3로 복사

복원 과정은 S3를 찾으려고 할 때까지 순조롭게 진행되지만, 이후 접근 권한이 없어 실패합니다. 기존 Discourse와 동일한 S3 버킷 이름을 새 S3에서 찾으려는 것 같은데, 해당 버킷은 새 환경에 존재하지 않으며 생성할 수도 없습니다.

권장되는 해결책이 있을까요?

백업을 수행하기 전에 기존 Discourse의 S3 버킷 이름을 변경하면, 복원 시 새 S3 버킷을 기대하게 될 것 같았습니다. 하지만 기존 Discourse를 존재하지 않는 버킷으로 단순히 변경하면 어떤 문제가 발생할지 걱정됩니다.

---

<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: [2월 18, 2025, 2:18오전 UTC](https://meta.discourse.org/t/backup-discourse-from-the-command-line/64364/34 "2025-02-18T02:18:16Z")

</div>

백업에 s3 파일을 다운로드하고 포함시키는 숨겨된 설정이 있습니다.

[업로드를 위한 S3 호환 객체 저장소 제공자 구성](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916) 문서에서와 같이 yml 파일에서 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: [10월 28, 2025, 7:58오전 UTC](https://meta.discourse.org/t/backup-discourse-from-the-command-line/64364/35 "2025-10-28T07:58:25Z")

</div>

> [@Alon1](#):
>
> 복원 과정은 S3를 찾게 될 때까지 순조롭게 진행되지만, 이후 접근 권한이 없어 실패합니다. 기존 Discourse의 동일한 S3 버킷 이름을 접근하려고 시도하는 것 같지만, 새 Discourse에는 해당 버킷이 존재하지 않으며 제가 생성할 수도 없습니다.
> 
> 권장되는 해결 방법이 있을까요?
> 
> 백업을 수행하기 전에 기존 Discourse의 S3 버킷 이름을 변경하면, 복원 시 새로운 S3 버킷을 기대할 것이라고 생각했습니다. 하지만 단순히 존재하지 않는 버킷으로 전환할 경우 기존 Discourse에 어떤 일이 발생할지 우려됩니다.

결국 해결하셨나요?

---

<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: [10월 28, 2025, 11:23오후 UTC](https://meta.discourse.org/t/backup-discourse-from-the-command-line/64364/36 "2025-10-28T23:23:01Z")

</div>

업로드용 S3 호환 객체 저장소 제공자 구성에 대한 [설명](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916)에 따라 환경 변수로 s3를 설정해야 합니다.

새 서버에서 s3 설정이 다른 경우 특히 중요합니다. s3 값을 데이터베이스에 저장하면 여러 문제가 발생할 수 있습니다.

하지만 restore 명령어에는 각 단계 사이에 일시 정지를 수행하도록 하는 옵션이 있습니다. 이 옵션이 도움이 될 수 있습니다.

---

<div class="post-metadata">

### Author: ![Jonathan5](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jonathan5/32/197134_2.png) [@Jonathan5](https://meta.discourse.org/u/Jonathan5)
#### Post date: [5월 17, 2026, 9:11오후 UTC](https://meta.discourse.org/t/backup-discourse-from-the-command-line/64364/37 "2026-05-17T21:11:52Z")

</div>

여기서 최종적으로 얻게 되는 파일이 포럼 웹사이트에서 백업할 때 얻게 되는 파일과 동일한지 다시 확인해도 될까요?

저는 항상 커맨드 라인에서 재구성을 하지만, 그 전에 웹사이트를 통해 백업합니다. 이번에는 백업을 깜빡했습니다! 두 작업 모두 커맨드 라인으로 하면 도움이 될 것 같네요 🙂 행운을 빕니다.

---

<div class="post-metadata">

### Author: ![Jonathan5](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jonathan5/32/197134_2.png) [@Jonathan5](https://meta.discourse.org/u/Jonathan5)
#### Post date: [5월 17, 2026, 9:32오후 UTC](https://meta.discourse.org/t/backup-discourse-from-the-command-line/64364/38 "2026-05-17T21:32:27Z")

</div>

백업 스크립트는 다음과 같이 표시되었습니다:

```plaintext
Finished!
[SUCCESS]
Backup done.
Output file is in: /var/www/discourse/public/backups/default/FILENAME.tar.gz

```

처음에는 그 파일을 다운로드하려고 했는데, 경로가 잘못되어 있었습니다. 다른 곳에서 파일을 찾은 후에야 이 주제에 있는 명령어들이 정확하다는 사실을 깨달았습니다…

---

<div class="post-metadata">

### Author: ![dennisjbr](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dennisjbr/32/444916_2.png) [@dennisjbr](https://meta.discourse.org/u/dennisjbr)
#### Post date: [7월 22, 2026, 11:06오후 UTC](https://meta.discourse.org/t/backup-discourse-from-the-command-line/64364/39 "2026-07-22T23:06:17Z")

</div>

안녕하세요! 업로드 없이 백업하려면 다음 명령어를 사용하세요:

`discourse backup --sql-only`

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [7월 22, 2026, 11:13오후 UTC](https://meta.discourse.org/t/backup-discourse-from-the-command-line/64364/40 "2026-07-22T23:13:43Z")

</div>

좋은 지적입니다. 이 내용(그리고 몇 가지 다른 정보)을 원 게시글에 추가해야 합니다.

---

<div class="post-metadata">

### Author: ![dennisjbr](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dennisjbr/32/444916_2.png) [@dennisjbr](https://meta.discourse.org/u/dennisjbr)
#### Post date: [7월 23, 2026, 12:14오전 UTC](https://meta.discourse.org/t/backup-discourse-from-the-command-line/64364/42 "2026-07-23T00:14:59Z")

</div>

안녕하세요 @supermathie! 만나서 반갑습니다. 혹시 저 기억하시나요? 얼마 전에 면접을 봤었거든요.

그리고 `discourse backup` 명령을 실행한 후에 `--help` 파라미터가 작동하면 좋겠어요. 대신에 백업 파일 이름이 "–helpXXX"로 지정되거든요. :lolsob:

감사합니다!

---

<div class="post-metadata">

### Author: ![dennisjbr](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dennisjbr/32/444916_2.png) [@dennisjbr](https://meta.discourse.org/u/dennisjbr)
#### Post date: [7월 23, 2026, 12:28오전 UTC](https://meta.discourse.org/t/backup-discourse-from-the-command-line/64364/43 "2026-07-23T00:28:56Z")

</div>

일부 AI의 도움으로 **discourse** 명령어의 하위 명령어에 대한 포괄적인 목록을 정리했습니다.  
`discourse` CLI(`script/discourse`를 통해 Thor gem으로 구현됨)는 **백업 및 복구** , **사이트 관리 및 모드** , **데이터베이스 유틸리티** , \*\*데이터 마이그레이션(가져오기/내보내기)\*\*으로 분류된 13개의 핵심 하위 명령어를 제공합니다.

* * *

## 명령어 빠른 참조

| 카테고리 | 하위 명령어 | 주요 기능 |
| --- | --- | --- |
| **백업 및 복구** | `backup` | 전체 또는 데이터베이스 전용 백업 아카이브 생성. |
| | `restore` | `.tar.gz` 백업 파일을 인스턴스로 복구. |
| | `enable_restore` | 복구 명령 실행 권한 부여. |
| | `disable_restore` | 복구 수행 권한 취소. |
| | `rollback` | 실패한 복구 후 데이터베이스 상태를 되돌림. |
| **사이트 모드** | `enable_readonly` | 사이트 전체에 대한 임시 읽기 전용 모드 전환. |
| | `disable_readonly` | 읽기 전용 모드 해제하여 정상적인 사이트 쓰기 복구. |
| | `request_refresh` | 모든 활성 연결된 클라이언트에 브라우저 새로고침 프롬프트 트리거. |
| **데이터베이스 작업** | `remap` | 데이터베이스 테이블 전체에서 글로벌 텍스트 검색 및 치환 수행. |
| **데이터 마이그레이션** | `export_category` | 단일 카테고리, 해당 토픽 및 관련 사용자 내보내기. |
| | `import_category` | 카테고리 아카이브를 현재 포럼으로 가져오기. |
| | `export_topics` | ID를 기반으로 특정 토픽 및 작성자/답변자 계정 내보내기. |
| | `import_topics` | 토픽 아카이브를 현재 포럼으로 가져오기. |

* * *

## 상세 하위 명령어 문서

### 1. 백업 및 복구 명령어

#### `discourse backup [FILENAME]`

- **설명:** 포럼 데이터베이스와 자산의 완전한 백업을 생성합니다.

- **플래그:**

- `--sql-only`: (불리언, 기본값: `false`) 로컬 업로드 파일은 건너뛰고 PostgreSQL 데이터베이스만 덤프합니다.

- `--s3-uploads`: (불리언, 기본값: `false`) S3에 저장된 자산을 백업 아카이브에 포함하도록 강제합니다(`--sql-only`가 설정된 경우 무시됨).

- **예시:**

```bash
discourse backup
discourse backup --sql-only

```

#### `discourse restore [FILENAME]`

- **설명:** `/var/www/discourse/public/backups/default`에 위치한 로컬 `.tar.gz` 아카이브에서 포럼 백업을 복구합니다.
- **선행 조건:** 먼저 `discourse enable_restore`를 실행해야 합니다.
- **예시:**

```bash
discourse restore discourse-2026-07-22-120000-v2026xxxx.tar.gz

```

#### `discourse enable_restore` & `discourse disable_restore`

- **설명:** 콘솔/웹 기반 복구 작업을 허용하거나 제한하는 애플리케이션 플래그를 전환합니다.
- **사용 순서:**

```bash
discourse enable_restore
discourse restore <filename>
discourse disable_restore

```

#### `discourse rollback`

- **설명:** 실패한 복구 실행 이전 시점으로 데이터베이스 스키마와 상태를 되돌립니다.

* * *

### 2. 사이트 상태 및 클라이언트 제어

#### `discourse enable_readonly` & `discourse disable_readonly`

- **설명:** Redis의 `READONLY_MODE_KEY`를 설정하거나 해제합니다.
- **상세 정보:**
- 사용자가 사이트를 읽을 수 있도록 유지하면서 데이터베이스 쓰기를 동결합니다.
- 터미널 세션이 충돌하더라도 사이트가 영구적으로 잠금되지 않도록 활성 상태 동안 갱신되는 짧은 수명(TTL) 루프를 사용합니다.

#### `discourse request_refresh`

- **설명:** MessageBus를 통해 시스템 메시지를 전송하여 온라인 웹 세션이 웹 페이지를 다시 로드하도록 지시합니다. 자산 업데이트나 글로벌 테마 변경 후 배포 시 유용합니다.

* * *

### 3. 데이터베이스 재매핑

#### `discourse remap [OPTIONS] FROM TO`

- **설명:** 데이터베이스의 텍스트 컬럼에서 직접 문자열 검색 및 치환을 수행합니다. 도메인 이름, CDN 경로 또는 이미지 업로드 접두사를 업데이트할 때 중요합니다.

- **플래그:**

- `--global`: (불리언) 표준 콘텐츠 테이블이 아닌 모든 테이블을 스캔하고 재매핑합니다.

- `--regex`: (불리언) `FROM` 매개변수를 리터럴 문자열이 아닌 정규 표현식으로 평가합니다.

- **예시:**

```bash
discourse remap "old-domain.com" "new-domain.com"
discourse remap --global "/uploads/default/" "/cdn-uploads/"

```

* * *

### 4. 선택적 데이터 가져오기 및 내보내기

#### `discourse export_category [CATEGORY_ID]`

- **설명:** 모든 중첩된 토픽, 게시물 및 참여 사용자 프로필을 포함하여 단일 카테고리를 JSON 아카이브 파일로 직렬화합니다.

#### `discourse import_category [FILE_PATH]`

- **설명:** `export_category`로 생성된 아카이브를 읽고 카테고리 데이터를 대상 인스턴스에 병합합니다.

#### `discourse export_topics [TOPIC_IDS...]`

- **설명:** 하나 이상의 공백으로 구분된 토픽 ID를 받아 토픽, 게시물 및 관련 사용자 계정을 내보냅니다.
- **예시:**

```bash
discourse export_topics 102 105 210

```

#### `discourse import_topics [FILE_PATH]`

- **설명:** `export_topics`로 생성된 JSON 아카이브를 대상 Discourse 인스턴스로 가져옵니다.
