Backup discourse from the command line

:bookmark: This guide covers how to back up and restore your Discourse site using command line tools, specifically designed for self-hosted environments.

:person_raising_hand: Required user level: Administrator

:information_source: 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:
./launcher enter app
  1. Run the backup:
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)
./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:
scp =FILENAME= =USER=@=HOST=:/var/discourse/shared/standalone/backups/default/
  1. Enter the container and start the restore:
./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.

:information_source: 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.

Last edited by @SaraDev 2024-08-23T20:50:17Z

Check documentPerform check on document:
「いいね!」 38

このコマンドは、クラウドサーバーのターミナルで実行する必要がありますか、それともローカルマシンで実行する必要がありますか?
どちらで実行しても、「Permission denied」というエラーが発生します。

ローカルマシンで実行してください。

接続にSSHキーを使用していますか?エラーはそれに関連しています。

コマンドは次のようになります。

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 .

Discourseのインストールを全く新しいサーバーに移行したいシナリオがあります。
私の計画は以下の通りでした。

  1. 新しい空のDiscourseインストールを作成する
  2. 古いDiscourseをバックアップし、バックアップを新しいサーバーにscpで転送してリストアする
  3. すべてのS3(画像など)を別アカウントの新しいS3にコピーする

リストアプロセスは、S3を探し始めるところまで順調に進みますが、アクセス権がないために失敗します。古いDiscourseと同じS3バケット名を検索しようとしているのだと思いますが、新しい方には存在せず、作成することもできません。

推奨される解決策はありますか?

古いDiscourseのS3バケット名を(バックアップを実行する前に)変更し、リストア時に新しいS3バケットを期待するようにすればどうかと考えました。しかし、単に存在しないバケットに切り替えた場合に、古いDiscourseに何が起こるか心配です。

バックアップに S3 ファイルをダウンロードして保存する隠し設定があります。

アップロード用の S3 互換オブジェクトストレージプロバイダーの設定 にあるように、yml ファイルで S3 を設定する必要があります。

その後、バックアップを復元すると、アップロードが新しいバケットにプッシュされます。

「いいね!」 1

この問題は解決しましたか?

Configure an S3 compatible object storage provider for uploadsに記載されているとおりに、環境変数でs3を設定する必要があります。

特に、新しいサーバーでs3の設定が異なる場合は、なおさらです。s3の値をデータベースに保存すると、多くの問題が発生する可能性があります。

しかし、リストアコマンドには、さまざまな部分の間で一時停止させるスイッチがあります。これは役立つ場合があります。