将帖子从一个 Discourse 实例迁移到另一个

需要将一些内容从一个 Discourse 实例迁移到另一个实例吗?

有一个命令行工具可以导出主题、一组主题或整个分类,在另一端还可以导入它们。

主题导出/导入

  • 一个或多个主题及其回复
  • 在主题中发帖的用户

分类导出/导入

  • 该分类及其所有子分类
  • 其安全设置
  • 安全设置中提到的自定义组
    • :warning: 如果任何组启用了“成员资格请求”,它将崩溃。请在导出之前禁用此功能
  • 分类和子分类中的所有主题和帖子
  • 所有发帖用户,并将他们分配到组中

开始:识别 ID

首先,确定要导出的 =Export= 的 ID。你可以在访问它的 URL 末尾找到它。

  • https://meta.discourse.org/t/how-to-contribute-to-discourse/53797

  • https://meta.discourse.org/t/how-to-contribute-to-discourse/53797/12
    (在这种情况下,你在主题中间——获取第一个数字)

  • https://meta.discourse.org/c/howto/faq/4

分类或主题 ID

多个主题

你可以通过添加用空格分隔的 ID 来选择多个主题;这在上面的字段中有效(我认为这不适用于分类):

  • 53797 200943 124096

运行导出脚本

该工具可以作为 root 用户在容器内运行:

cd /var/discourse
./launcher enter app

运行此命令:

discourse export_=Export= =ID=

输出应该看起来像这样:

正在开始导出 =Export=…

新用户都从哪里来?
导出已保存到 =Export=-export-2021-08-27-015437.json

完成

移动导出的文件

导出的 .json 文件需要从执行导出的应用程序容器内部移动到接收实例的容器内部。这需要几个步骤。

复制到“外部”

如果尚未退出,请退出容器

exit

现在应该会看到如下提示:

root@yourserver:/var/discourse

使用 docker 将文件从容器中复制出来(我认为你不能移动它)

docker cp app:/var/www/discourse/=FileName= .

移动到另一个实例

这超出了本指南的范围,但这可能会帮助你:

将其复制到接收实例的容器中

以 root 用户 SSH 登录到你的接收实例并进入 Discourse 目录:

cd /var/discourse

再次使用 docker 将文件复制到另一个容器中

docker cp =FileName= app:/var/www/discourse

导入内容

进入接收实例中的容器:

./launcher enter app

运行导入脚本

discourse import_=Export= =FileName=

:cake: 完成!

你可能需要整理一些收尾工作,但希望一切都已完成。

高级提示

缺少 Ruby Gem

在执行复杂的分类导入时,我的实例缺少 ‘Listen’ Ruby。
通过执行以下操作解决了这个问题:(在容器内使用 Discourse 用户)

./launcher enter app
su discourse
bundle config --delete without
bundle config --delete with
bundle install
exit
exit

这破坏了 rails 控制台,之后需要重建

./launcher rebuild app

多站点

在多站点环境中,使用 RAILS_DB 环境变量。

RAILS_DB=xxxmoves discourse export_=Export= =ID=
RAILS_DB=dancerehab discourse import_=Export= =FileName=

请在 bug 分类中报告错误,并在 #feature 分类中请求增强功能。


相关主题


上次由 @SaraDev2022-07-13T00:00:00Z 审核*

44 个赞
UI: Topic and Category Export/Import
CLI command to migrate a single category
Moving topics between sites?
Category/Topic export fails with error "database "discourse_development" does not exist"
Saving a Conversation
Easiest way to export a single topic?
Migrate user custom fields to another instance
How to export user data from a category on a hosted site
Error Importing Categories from a Discourse Instance to Another
Import CSV User Activity from one Discourse to Another
How use API to convert topic in discourse1.com to discourse2.com
Can sub-forums of the same instance split up and move to new independent servers (or discourse instances)?
Help migrating category from one instance to another without admin on the source instance
Adding default sets of topics, categories and users to a new Discourse
How to download Comments and Topics
Downloading Content
Can we combine 2 separate discourse sites?
Tracking and resolving a schema drift cause
Merge two Discourse forums into one
Moving topics from a forum on one website to a forum on another website
Transfer topics between forums?
Forum Aquisition
Transfering inbox group messages to another instance?
Transfering inbox group messages to another instance?
Imported categories are not in parent category
I wonder how to add hundreds of users into a group? Is there any api?
Selective backups skipping settings and config
Test driving admin/moderation features
Add backup to existing Discourse instance
Merging two Discourse forums
Migrating vBulletin onto existing and live Discourse instance
Migrate topics from one discourse instance to another?
A system where people have to start at lesson 1, and cannot see the other lessons?
How to divide my community into 2 parts