将帖子从一个 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"
Easiest way to export a single topic?
Saving a Conversation
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?
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

我将再次尝试一下。

有没有一种简单的方法可以同时迁移相关的上传和主题?

不算有。一种大部分有效的方法是,如果你获取了所有这些上传文件,并将原始文件的 URL 粘贴到你正在迁移到的站点的任何帖子中,那么应该会发生的是,这些上传文件将被创建,具有相同的 SHA,并且它会“正常工作”。

所以你会做那个将帖子中的内容转换为 URL 的事情来获取那些 URL。(我总是记不住怎么做,所以每次都得弄清楚)。

嗯——我还是有点不明白。你是说这个会起作用吗?

  1. 从第一个网站抓取所有上传文件
    • 怎么抓?
  2. 将它们放入一个主题
  3. 它们将生成与旧网站上相同的相对链接,然后神奇地完成!

或者你的意思是这个?

  1. 从旧网站抓取你感兴趣的类别中的所有绝对 URL
  2. 将它们粘贴到主题中
  3. 它们都将以相同的 SHA 下载到新网站,并且现有链接将神奇地全部起作用

或者完全是别的东西?

我认为其中任何一个都应该可以工作。但是,您可以将这些图像获取到新站点,它们应该会生成相同的 sha,这样现有的主题链接就能神奇地生效。

也许你可以这样做:

cat_id=123
Topic.where(category_id: cat_id).each do| t|
  Post.where(topic_id: t.id) do |p|
      p.cooked.match(image url)....
         puts(the match)

我认为如果你这样做,并将这些链接粘贴到你网站上的任何帖子中,它应该会将所有这些图像下载到本地并生成相同的 sha,这样链接就可以使用了。你可以手动尝试几个看看。

现在是深夜。你的体验可能会有所不同。

1 个赞

您好,我不确定这个教程是否是我想要的,但在此提出疑问。

如果我在服务器上安装了 Discourse,但由于增长需要迁移到更强大的服务器,这些是步骤吗?

例如,备份选项会怎样?我不能这样做,在另一台服务器上安装 Discourse,然后从该选项恢复另一个实例的备份副本吗?

我期待您的澄清,因为我想知道在需要时如何迁移,并且不丢失我最近所做的工作。

不。要迁移到更大的服务器,只需进行简单的备份和恢复即可。您还可以使用 rsync 将 Discourse 站点迁移到另一台 VPS