コマンドラインからバックアップを復元する

:bookmark: このガイドでは、Discourse の Web UI を使用せずに、コマンドラインから Discourse のバックアップを復元する方法を説明します。
:person_raising_hand: 必要なユーザーレベル: 管理者
:wrench: コンソールアクセスが必要です

ここでは、Discourse の Web UI を起動することなく、コマンドラインから Discourse のバックアップを復元する方法を説明します。これは、サーバーを移行する際に便利です。

前提条件

始める前に、次の手順を完了していることを確認してください。

  1. ソースの Discourse インスタンスから最新のバックアップファイルをダウンロードします。
  2. ./discourse-setup を実行するか、既存の app.yml をコピーして、宛先の Discourse インスタンスをブートストラップします。
  3. 宛先の Discourse インスタンスが最新バージョンであることを確認します。必要に応じて更新します。

バックアップの転送

  1. 宛先サーバーに SSH 接続するか、そこにバックアップフォルダーを作成します。

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

  1. バックアップファイルを宛先サーバーにアップロードします。

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

パス、ファイル名、サーバー名を、使用しているものに置き換えてください。ただし、バックアップファイルは次の場所に配置する必要があります。

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

:mega: Google Drive、Dropbox、OneDrive などの一般的な Web ストレージ サイトから Discourse のバックアップファイルをアップロードおよびダウンロードすることもできます。好みの Web ストレージプロバイダーに基づいて、特定のコマンドライン手順を確認する必要があります。

:warning: バックアップのファイル名を変更しないでください! Discourse はバックアップファイル名をメタデータとして扱うため、ファイル名を変更すると復元が機能しなくなります。元のファイル名を維持してください。

/path/to/backup/discourse-xyz.tar.gz をバックアップファイルのローカルパスに置き換え、\u003cserver_ip_address\u003e を宛先サーバーの IP アドレスに置き換えます。

:bulb: Nginx をリバースプロキシとして使用している 場合は、すべてのバックアップパスがコンテナによって読み取れ、Nginx が .sock ファイルを読み取れることを確認してください。

バックアップの復元

  1. 宛先サーバーにアクセスし、Discourse フォルダーに移動します。
cd /var/discourse
  1. Discourse Docker アプリコンテナに入ります。
./launcher enter app
  1. 復元機能を有効にします。
discourse enable_restore
  1. バックアップファイルを復元します。
discourse restore sitename-2019-02-03-042252-v20190130013015.tar.gz

:bulb: ヒント: ファイル名を指定せずに discourse restore を実行すると、利用可能なすべてのバックアップファイルが一覧表示されます。

:warning: サイトの backup_location 設定が S3 を使用するように構成されているが、バックアップファイルをローカルファイルシステムに手動でアップロードした場合は、--location local を指定する必要があります。

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

同様に、ダウンロードせずに S3 バックアップから直接復元するには、--location s3 を使用します。

  1. Discourse Docker アプリコンテナを終了します。
exit

リビルド

バックアップを復元した後、すべての設定と構成が正しく適用されていることを確認するために、宛先インスタンスをリビルドすることを選択できます。

:mega: ここで、/var/discourse/containers/app.yml を完全な HTTPS、追加のプラグイン、または CDN 構成で更新する良い機会です。両方のインスタンスの app.yml 構成を比較して確認してください!

cd /var/discourse
./launcher rebuild app

Eメールの有効化

バックアップが復元されると、スタッフ以外のユーザーの送信メールが無効になります。テストサーバー、新しいサーバー、または何らかの理由でバックアップを復元したばかりのサーバーがユーザーにメールを送信し始めることは望ましくありません。disable_emails サイト設定を「no」に変更して、メールを再度有効にします。

:tada: これで完了です。Discourse サーバーは正常に復元されました。

「いいね!」 78
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
How to migrate Discourse from one server to another with the same DNS name
Best Practices for Backups
Problem upgrading Discourse
Upgrading v2.2.0.beta4 forum with unknown local changes
Set up file and image uploads to S3
Quick question about site backups
My install broke after updating, how can I fix it?
Is there any way to restore your site from backup in the terminal?
Migrating Discourse from one DigitalOcean droplet to another without downtime
Restore backup right away after installing Discourse
Unable to migrate to S3, therefore unable to restore from backup
Restore Failure - S3 (compatible) backup
"EXCEPTION: psql failed: DETAIL: Key (post_id)=(36946) is duplicated."
Migrate from another forum to Discourse
My install is 16,359 commits behind! Advice?
Trying to recover an installation
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
Migrating to a new server that has a new DB and new S3 buckets for backup and uploads
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
"Key is stored in legacy trusted.gpg keyring" warning
"Key is stored in legacy trusted.gpg keyring" warning
Discourse broken after moving servers
Stuck and lost updating forum, problems with PG migration
How to manually migrate s3 files to local?
Index_users_on_username_lower error during database restore: import failed
How can I get the current version information from my backup?
Backup Prod -> Snap -> Build Test -> Change Address
How to properly package discourse as an image
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

これらの手順でバックアップから復元できましたが、discourse restore コマンドを次のように変更する必要がありました。

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

(私の例では、上記の例のファイル名を使用しています)これにより、復元で /var/discourse/shared/standalone/backups/default ディレクトリに配置したバックアップ(s3に保存されていたバックアップとは対照的に)を見つけることができました。

「いいね!」 2

リストア後の再構築は必要ですか?

また、NGINXリバースプロキシがあり、それがアップストリームのDiscourseに渡される新しいサーバーにリストアしました。そのため、DiscourseのSSLを無効にしましたが、リストア中に次のメッセージに気づきました。

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

これはすべての内部リンクをリマッピングしていますか?これを元に戻すのは discourse remap http://example.com https://example.com と同じくらい簡単ですか?

いいえ。

そうみたいですね。はい、再マッピングできます。

force_https 変数を設定する必要があります。

「いいね!」 1

バックアップが15GBの場合、復元にはどのくらいのスペースが必要ですか?

「いいね!」 1

それはデータベースだけですか、それともアップロードもですか?

おそらくその3〜5倍でしょう。

「いいね!」 1

データベース+アップロードで15GB、60GBのHDに20GBの空き容量がありますが、毎回リストアが失敗します。リストアするには少なくとも50〜60GBの空き容量が必要ですか?

「いいね!」 1

バックアップ、アップロード、および非圧縮データベースのために十分なスペースが必要です。

最初にデータベースのみのバックアップを復元してから、rsyncで手動でアップロードをコピーすることを試すことができます。

「いいね!」 2

セルフホストで管理者アカウントを認証し、.tar.gz ではなく .sql.gz バックアップをアップロードしました。

UI での復元はうまくいかないため、コマンドラインから「バックアップを復元する」を実行しましたが、discourse restore プロセスの最後に [FAILED] と表示されました。公式ホスティングからの入力ファイルが .tar.gz であることが、プロセスを通過させる原因となる可能性がありますか?

私の公式ホスティングは数日前に開始したもので、セルフホストは container.yml で SMTP 値を変更した後、本日正常に動作し始めました (SMTP 値の変更)。

「いいね!」 1

エラーの内容を含める必要があります。ファイル名にはバージョン情報が含まれているため、ファイル名を変更した場合は、ファイル名の先頭の単語を変更するだけで、元の名前に戻す必要があるでしょう。

「いいね!」 1

discourse restore のドキュメントはどこかにありますか?--location local スイッチがあるようなので、S3用のものもあるのだと思います。

S3に保存されているバックアップからリストアしたいのですが、事前に手動でダウンロードする必要を避けたいです。

追記:気にしないでください。discourse restore --location s3 $filename は問題なく動作することがわかりました。

「いいね!」 2

app.yml で S3 を有効にしたため、純粋な discourse restore <filename> で問題なく動作しました。

backup restore s3 で検索すると、適切な投稿が見つかると思います。

「いいね!」 2

こんにちは、s3(-cli)scp として使用し、送信メールプロバイダーをMailGunからBrevoに変更してこのプロセスを完了しました。

リストア後、バナーを削除する方法が見つかりません。

バナーを削除する最も簡単な方法は、サイト設定でメールを有効にすることです。

「いいね!」 3

右。CSSで非表示にすることもできます!:joy:

「いいね!」 1

本当です。Air theme hides "outgoing email disabled" warning を思い出す必要があったため、少し慎重にこれをお勧めしました。

「いいね!」 1

**バックアップを復元するたびに、スタッフ以外のユーザーのメールは自動的に無効になります。**これは、テストサーバーに復元された後に、存在を知られるべきではないサーバーの通知をユーザーに大量送信し始めたため、コードに追加されたのだと想像します。

OPをそれに応じて更新しました。

「いいね!」 2

ハウツーの注記:

テスト目的で定期的にバックアップを復元し、テストサーバーが正しく設定されている場合、メールをデバッグメールサービス(GitHub - maildev/maildev: 📫 SMTP Server + Web Interface for viewing and testing emails during development. など)に送信するには、スクリプト経由でメールを有効にしたい場合があります。

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

その場合、app.yml で DISCOURSE_DISABLE_EMAILS を no に設定することをお勧めします。(また、DISCOURSE_ENABLE_RESTORE も設定して復元を容易にしてください。)

「いいね!」 1