(已取代)如何从SMF2迁移/导入到Discourse

:mega: 本文档现已由另一篇 SMF2 指南取代:Migrate an SMF2 forum to Discourse

我们非常希望将我们熟悉的老牌 SMF2 论坛迁移到 Discourse。我们拥有 1000 多名成员,约 20,000 篇帖子,分布在约 2,000 个主题中。
在 SMF2 上,我们没有使用投票或附件——实际上,甚至不是每个人都有头像。不过,有些帖子严重依赖“高级”BBCode。

以下是我们完成迁移的方法。

先决条件

只需按常规方式安装 Discourse。
我还添加了 Discourse BBCode 插件,以便开箱即用地处理列表、大小、颜色等。

如果您无法远程连接到 SMF2 的 MySQL 数据库,则必须将数据从转储文件导入到一个临时的 Docker 容器中。

如果您的数据库接受远程连接,或者运行在同一主机上,您可以跳过此步骤。

临时的 Docker MySQL 容器

转储您的数据库:

cd /tmp/
mysqldump –u[用户名] –p[密码] [数据库名] > sqldump.sql

创建临时的 Docker MySQL 容器:

cd /tmp/
docker run -d -e MYSQL_ROOT_PASSWORD=pass -e MYSQL_USER=user -e MYSQL_PASSWORD=pass -e MYSQL_DATABASE=db -v "$PWD":/backup --name=mysql mysql

然后进入该容器:

docker exec -it mysql bash

导入您的数据库转储文件:

mysql -uuser -ppass db < /backup/sqldump.sql

如果出现以下错误:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

只需等待一分钟,让容器完全启动。

为了数据库兼容性,我不得不更改临时数据库的身份验证插件,但您的情况可能有所不同:

mysql -uuser -ppass db

使用以下查询:

ALTER USER user
IDENTIFIED WITH mysql_native_password
BY 'pass';

然后退出并检查您的 MySQL 实例 IP 地址:

exit
docker inspect mysql | grep IPAddress

现在您就有了 SMF2 数据库的可运行副本。

临时的 Discourse 导入容器

让我们基于默认的 app.yml 容器创建一个名为"import"的新容器:

cd /var/discourse
cp containers/app.yml containers/import.yml

nano containers/import.yml

mysql-dep 模板添加到您的新导入容器中:

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"
## 如果您想添加 Lets Encrypt (https),请取消注释这两行
  #- "templates/web.ssl.template.yml"
  #- "templates/web.letsencrypt.ssl.template.yml"
  - "templates/import/mysql-dep.template.yml"

然后只需执行:

/var/discourse/launcher stop app
/var/discourse/launcher rebuild import

导入到 Discourse

一旦导入容器重建完成,我们就必须进入它进行我们的最新调整

/var/discourse/launcher enter import
cd /var/www/discourse/ # 脚本必须从该确切目录启动,但您应该已经到达那里了
su discourse -c "bundle exec ruby script/import_scripts/smf2.rb -h 172.17.0.3 -u user -p pass -d db -f smf_ -t Europe/Paris"
  • -h: 您的 SMF2 MySQL 数据库主机名(此处为 Docker 容器的 IP);
  • -u: SMF2 MySQL 用户;
  • -p: SMF2 MySQL 密码;
  • -d: SMF2 MySQL 数据库;
  • -f: SMF2 表前缀;
  • -t: SMF2 时区。

清理

如果您创建了它,请停止并删除临时的 MySQL Docker 容器:

docker stop mysql
docker rmi mysql

停止 Discourse "import"容器,并使用 launcher 进行清理:

/var/discourse/launcher destroy import
/var/discourse/launcher cleanup

我实际上成功销毁了我的主容器 :slight_smile: 没什么大不了的:

/var/discourse/launcher rebuild app

导入后的 Discourse 设置

一些默认设置可能会导致导入的帖子和权限出现问题。请根据您的需求从 Discourse 设置面板中更改这些设置:

  • 最小主题标题长度:我将其改为 3——标题太短的主题很难处理(无法移动等);
  • 标题美化:我不得不将其关闭——标题不以大写字母开头的主题很难处理(无法移动等)。

参考文献

10 个赞

Thanks for providing this. Maybe @marcozambi can use this for the guide he was planning to write after his successful import (including attachments)?

See here:

Also can anybody from the Discourse team let us know what happened to the old topic that was a guide for SMF2 imports? I can no longer find it via search.

1 个赞

Still determined to contribute, as soon as all the details will be in place. I’m taking notes of everything and I’ll write someting asap

1 个赞

poke @codinghorror @sam @HAWK

I think we can combine what @_vincent has compiled here, what was in the “missing” topic, and a few notes from @marcozambi’s migration to make a pretty comprehensive guide for migrating SMF2 to Discourse.

I have undeleted it here: https://meta.discourse.org/t/importer-for-simple-machines-2-forums/17656

I am assuming it was deleted because it contained info that is no longer up to date so grab what you need from it and we’ll remove it again to avoid future confusion.

1 个赞

Thanks! For the most part it was up-to-date. I did a migration with it a couple months ago and I would have been lost as f*$# without it.

I think the guide isn’t the problem, so much as the importer itself could use a little attention in a few areas. Also, if possible, we should change some of the MySQL settings in the Discourse docker container when it gets created to prevent connection timeouts. That would probably take care of everything IMO.

1 个赞

Ok, it’s out. SMF2 to Discourse - The Ultimate Guide
I hope the Guide is readable enough, as I am not a native english speaker. It goes without saying that any constructive feedback is more than welcome.

3 个赞

Hello guys,

Let me start that you did a wonderful job with [SMF2 to Discourse - The Ultimate Guide] and this migration tool.

I could migrate a huge SMF instante (61k members, 400k posts, 350k, topics).
I did a dry run and everything worked as it should.

My question is: will this script override Discourse specific settings like the ones in /admin/site_settings/ ? - I’m asking this as I want to make a final migration of the content that came up in the meantime on the SMF site, but I would not want to overwrite the settings already configured in /admin/site_settings/.

Thank you

1 个赞

No it should not override any of the site settings.

1 个赞

Thank you so much.

I don’t have the expertise to “read” the script and what exactly it is copying over. I was hoping the same

感谢您提供的指南。

我在您提到以下内容后卡住了:

为了数据库兼容性,我不得不更改我们的临时数据库身份验证插件,但您的情况可能有所不同:

我收到了以下错误:

Plugin caching_sha2_password could not be loaded: /usr/lib/x86_64-linux-gnu/mariadb19/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory (Mysql2::Error::ConnectionError)

不知您能否指点我如何修复此问题?这想必与更改“数据库身份验证插件”有关?如果是,请问该如何操作?

谢谢!

接下来,我尝试将数据库导入到 Docker 外部的独立 MySQL 数据库中。该数据库运行在 localhost 上。

现在,当我运行脚本时,在之前相同的位置出现了以下错误:

from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in initialize' /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in connect’: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) (Mysql2::Error::ConnectionError)

我已按照指南中的建议等待一段时间后重新运行,但遗憾的是,结果始终相同。请问有人能帮我吗?

谢谢

这是一张截图 https://drive.google.com/file/d/1z8TLY4zBr0KzrL9aJDQTG4NKG5Dhbg11/view?usp=drivesdk