将您的 Discourse 实例迁移到不同的服务器

:bookmark: 本指南介绍了如何将您的 Discourse 实例从一台服务器迁移到另一台服务器,包括所有设置和数据。本指南适用于使用 Docker 的自托管 Discourse 实例。

:person_raising_hand: 所需用户级别:系统管理员

:warning: 此过程涉及域名和 DNS 更改。请确保您可以访问源服务器和目标服务器。

本指南将引导您完成将 Discourse 实例从一台服务器迁移到另一台服务器的过程,确保您的数据、设置和配置得以保留。

@pfaffman 2025-09-12T05:00:00Z 添加的免责声明。

现在这些说明不太好用,因为您现在使用的是 HTTPS 和 Let’s Encrypt,这要求新服务器的 DNS 指向它,以便它可以请求密钥。我建议遵循使用 rsync 将 Discourse 站点移动到另一台 VPS(可能使用 --exclude postgres*,然后从命令行备份和恢复数据库。)这很巧妙,因为如果您知道如何操作,您可以调整本地 DNS 指向新服务器,以便在互联网其余部分仍然看到旧站点时测试它是否正常工作。

摘要

您将在此指南中执行以下关键步骤:

  1. 备份您当前的 Discourse 实例(源服务器)。
  2. 将备份文件传输到您的目标 Discourse 实例(目标服务器)。
  3. 在目标服务器上恢复备份。
  4. 更新 DNS 设置(如果适用)。

调整 DNS 设置(需要时)

如果您对新服务器使用相同的域名,请提前降低 DNS 条目的 TTL(生存时间)。这确保了更新的 DNS 记录传播期间的停机时间最少。如果您将使用新的域名,则可以跳过此步骤。

登录并准备源服务器

  1. 使用具有管理员权限的帐户登录到您的源 Discourse 实例。
  2. 确保源服务器和目标服务器都使用:
    • 相同的 Discourse 版本
    • 相同的插件集
  3. 访问 /admin/upgrade 来升级两台服务器上的 Discourse 版本。

:exclamation: 避免将较新的备份恢复到较旧的 Discourse 版本或不兼容的 PostgreSQL 版本上,因为这可能会导致错误。

创建和下载备份

  1. 在您的源 Discourse 实例上导航到 /admin/backups
  2. 单击 Backup(备份)按钮来创建一个备份:
  3. 出现提示时,单击 Yes(是)确认。
  4. 备份完成后,转到 Backup files(备份文件)选项卡,找到新创建的备份。
  5. 单击 Download(下载)以下载一个包含下载链接的电子邮件。单击电子邮件中的链接将备份文件保存到本地。

:warning: 在继续之前,请检查您的 app.yml 文件,以确保任何可选设置(例如 CDN 配置、已安装的插件或 HTTPS 支持)在源服务器和目标服务器之间保持一致。

在目标服务器上恢复备份

:bulb: 要通过命令行恢复备份,请参阅相关文档

  1. 登录到您的目标 Discourse 实例并使用管理员凭据。
  2. 导航到 /admin/backups/settings,并启用 allow restore(允许恢复)设置。
  3. 转到 /admin/backups 并单击 Backup files(备份文件)选项卡。通过单击 Upload(上传)按钮上传您之前下载的备份文件:
  4. 上传完成后,单击上传的备份旁边的 ⋮(更多选项)菜单,然后单击 Restore(恢复):
  5. 出现提示时,单击 Yes(是)确认。

恢复过程将开始。这可能需要一些时间,具体取决于您的数据库大小。过程完成后,系统将自动注销您。

收尾和登录

  1. 使用您的管理员凭据登录到您的目标 Discourse 实例。
  2. 如果站点是使用 HTTPS 备份的,请确保新服务器上启用了 HTTPS。如果配置不正确,请使用 Rails 控制台暂时禁用“强制 HTTPS”设置。
  3. 通过编辑 app.yml 文件并重建实例来重新启用任何可选配置。这可能包括:
    • 启用 CDN 支持。
    • 安装其他插件。
    • 设置 HTTPS 配置。

常见问题和解决方案

备份文件无法恢复

  • 检查源服务器和目标服务器之间的 Discourse 和 PostgreSQL 版本是否匹配。

恢复后无法登录(启用了 HTTPS)

  • 使用 Rails 控制台通过运行以下命令暂时禁用 force https
    SiteSetting.force_https = false
    
74 个赞
How to migrate Discourse to new server
How to migrate my Discourse instance to a fresh new install
Move Discourse to a new server without setting up the web UI first?
Transfer from bitnami to normal discourse
Can I restore backups from older Discourse versions?
How to migrate the discourse container to another machine
Update from 2.9.0 beta2 to beta4 failed (my site is down)
Images lost when migrating to self-hosting
How to downgrade a Digital Ocean Virtual
How to backup and restore a whole /var/discourse app folder?
Exporting an AWS instance
Preserving user sessions when migrating between hosts
Postgres failing to update?
Migrate from VPS to a Dedicated
Site migration and plugins
How to migrate Discourse from one server to another with the same DNS name
Migrate a NodeBB forum with MongoDB to Discourse
Migrate a Ning forum to Discourse
Migrate a Phorum forum to Discourse
Migrate a PunBB forum to Discourse
Migrate from another forum to Discourse
Migrate a Kunena 3 forum to Discourse
Preserve user sessions when migrating to a new host
How do I move the discourse installed server to another server without loss?
Can snapshots be used when upgrading the host OS?
Unknown Primary Key
How to switch Discourse servers?
" undefined method `deprecated?' for nil:NilClass" on rebuild
How to switch Discourse servers?
Some settings aren't saving
Steps involved to downgrade from 2GB to 1GB on DO?
Moving to Another VPS Provider
Getting "permission denied" on new VPS install
How Do I transfer Discourse between servers?
Multi-instance migration failed when adding a new instance
Help Needed Migrating Discourse Forum to New Shanghai Server – db:migrate Error
Plesk server migration
Seeing "welcome to nginx" after backup restore
Issues while migrating from Kunena
Moving to New Server woes
Error: Can't notify admin while restoring backup during a migration to a fresh install
How to migrate from one Digitalocean Droplet to a another Droplet in a different Digitalocean account
How might we better structure #howto?
Trouble with postgre(maybe)
Move Digital Ocean 1-Click install to Standard supported install
Can I retain my forum content if I change its original IP?
Server upgrade from ubuntu 18 to 20
How to move Discourse to a different server when using Digital Ocean's Volumes (Block Storage)
How to migrate Discourse Forum data (Topics, Chat, and Configuration) to another server
How to clone Discourse server to a new server?
Move from standalone container to separate web and data containers
How do I move the discourse installed server to another server without loss?
Migrate a phpBB3 forum to Discourse
Migrate a vBulletin 4 forum to Discourse
Migrate from GetSatisfaction to Discourse
Migrate a NodeBB forum with Redis to Discourse
Migrate a MyBB forum to Discourse