将 MyBB 论坛迁移到 Discourse

在本教程中,我们将学习如何使用官方 MyBB 导入脚本 将 MyBB 论坛迁移到 :discourse: 平台。

可迁移的内容

  • 分类
    • 根分类 => 根分类
    • 子分类 => 子分类
    • 根论坛 => 子分类
    • 子论坛 => 子分类
  • 主题和回复 => 主题和帖子
  • 用户
    • 用户名
    • 邮箱
    • 权限状态
    • 加入状态
  • 重定向

我们的计划非常简单:

  • 搭建本地开发环境。
  • 导出生产数据库。
  • 将生产数据库导入 Discourse。
  • 运行 MyBB 导入脚本。

让我们开始吧 :slightly_smiling_face:

搭建本地开发环境

首先,您需要按照以下指南之一安装 Discourse 平台本身。如果遇到问题,请参阅 本指南

安装 MySQL 数据库服务器;

MacOS

$ brew install mysql@5.7
$ echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile

检查服务状态:

$ brew services list

您应该看到类似以下内容:

mysql@5.7         started

如果没有,请运行以下命令并重试:

$ brew services start mysql@5.7

Ubuntu 18.04

$ sudo apt update
$ sudo apt install mysql-server -y

完成 MySQL 安装后,检查其状态:

$ systemctl status mysql.service

如果未运行,请运行以下命令:

$ sudo systemctl start mysql

对于 Windows,您可以遵循官方 安装指南

我们将此环境称为:Discourse 服务器

导出生产数据库

通过运行以下命令导出/备份生产数据库(来自 MyBB 生产服务器):

$ mysqldump -u USER_NAME -p DATABASE_NAME > mybb_dump.sql
  • 将此数据库转储文件复制到 Discourse 服务器

:bulb: 您可以使用 scprsync 来复制数据库。

将生产数据库导入 Discourse

Discourse 服务器 上,创建一个数据库:

$ mysql -u root

:bulb: 如果您的数据库用户有密码,则应使用:mysql -u root -p,然后输入您的密码。

mysql> CREATE DATABASE mybb;

通过运行以下命令确保数据库已成功创建:

mysql> SHOW DATABASES;

您应该看到类似以下内容:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| mybb               |
| sys                |
+--------------------+

此时 mybb 数据库是空的。我们的下一步是将生产数据库导入其中。

$ mysql -u root mybb < mybb_dump.sql

稍后我们将需要表前缀。因此,趁现在在这里,让我们获取它。

$ mysql -u root
mysql> USE mybb;
mysql> SHOW TABLES;

您将看到类似以下内容:

+--------------------------+
| Tables_in_mybb           |
+--------------------------+
| mybb_adminlog            |
| mybb_adminoptions        |
| mybb_adminsessions       |
| mybb_adminviews          |
| mybb_announcements       |
| mybb_attachments         |
| mybb_attachtypes         |
| ...其余表...|
+--------------------------+

如输出所示,我们的表前缀是 mybb_

运行 MyBB 导入脚本

  • 首先安装导入器的依赖项。在 Discourse 服务器 上:
$ cd ~/discourse
$ echo "gem 'mysql2', require: false" >> Gemfile
$ bundle install

接下来,您应该配置脚本以使其正常运行。将以下内容复制并粘贴到您的 shell 中(如有需要请更改值):

export DB_HOST="localhost"
export DB_NAME="mybb"
export DB_PW=""
export DB_USER="root"
export TABLE_PREFIX="mybb_"

您还有另一种配置脚本的方法。使用您选择的任何编辑器打开 script/import_scripts/mybb.rb,并更改双引号内的值以适应您的需求:

  DB_HOST ||= ENV['DB_HOST'] || "localhost"
  DB_NAME ||= ENV['DB_NAME'] || "mybb"
  DB_PW ||= ENV['DB_PW'] || ""
  DB_USER ||= ENV['DB_USER'] || "root"
  TABLE_PREFIX ||= ENV['TABLE_PREFIX'] || "mybb_"

使用干净的 Discourse 实例运行导入器:

$ bundle exec rails db:drop
$ bundle exec rails db:create
$ bundle exec rails db:migrate
$ bundle exec ruby script/import_scripts/mybb.rb

导入器将连接到 MySQL 服务器,并将您的 MyBB 数据库迁移到 Discourse 数据库。

导入器完成后,通过运行以下命令启动 Discourse 实例:

$ bundle exec rails server

接下来,启动 Sidekiq(后台作业处理器)以处理迁移的数据:

$ bundle exec sidekiq

:bulb: 您可以在 http://localhost:3000/sidekiq/queues 监控 Sidekiq 进度。

按照本 教程 设置您的 Discourse 生产服务器。

按照本 教程 对 Discourse 平台(本地 Discourse 服务器)进行备份,并将其上传到您的 Discourse 生产服务器。

:tada:

如果您对该过程有任何疑问,我很乐意提供帮助。

祝迁移顺利 :grinning:

9 个赞

Hi - this looks like a great guide, except as a Cpanel rather than linux user, migrating from a shared host, I don’t have root access or ssh access to the original host, but I do have access to PhPMyAdmin in Cpanel from which I can export the Mybb database.
Will this do?
What if any special export settings are required? And into what directory on my Digital Ocean droplet should this database be copied? (I am using FileZilla)

Yes.

It does not matter, home directory works just fine.

3 个赞

Hi again - I can get up to this point in the tutorial

bundle install

and for me this falls over with error

'Don’t run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Your Gemfile has no gem server sources. If you need gems that are not already on
your machine, add a line like this to your Gemfile:
source ‘https://rubygems.org
Could not find gem ‘mysql2’ in any of the gem sources listed in your Gemfile.

Any suggestions?

Unfortunately I know nothing about ruby or linux or gemfiles and so am just literally plodding though various discourse cli setup tasks as the tutorials instruct by cutting and pasting commands via PuTTy, without any kind of understanding.

I am running Ubuntu and Discourse in a Digital Oceans Droplet, if that helps?

Also, I see a subsequent reference to pasting database export commands into ‘shell’ . For practical purposes is my current PuTTy connection to the server = ‘shell’, or is some other interface/console involved?

OK, in partial answer to my own question, random thrashing around on forums suggests

$ sudo apt-get install libmysqlclient-dev

will then allow mysql2 gem to install (whatever that is) - ignoring the warning about not doing this as root.

Getting past that and to the next step - typing

$ bundle exec rails db:drop

gives another error::::

bundler: failed to load command: rails (/usr/local/bin/rails)
Gem::Exception: can’t find executable rails for gem railties. railties is not currently included in the bundle, perhaps you meant to add it to your Gemfile?

Checking in /usr/local/bin/ and I can see a file named ‘rails’ is definitely there.

Typing $ sudo gem or $ gem install rails or $ sudo gem install rails does not help (per various suggestions stumbled across for this error).

Have even gone back and installed Ruby on Rails from scratch to try and ensure all normal dependencies are present How To Install Ruby on Rails with rbenv on Ubuntu 18.04 | DigitalOcean -and no improvement - whether I use version 2.51 or 2.61.

Well out of my depth here…

Well I can say categorically that following this guide as written does NOT work for anyone following the official steps for setting up local Dev environment under WSL2 installation of Ubuntu-18.04 under Windows 10 - at almost every step there will be some dependency missing or connection refused error or similar.

With a lot of pain and online research, I have managed to get up to the command:

$ bundle exec ruby script/import_scripts/mybb.rb

but this generates response:

mysql2/client.rb:90:in `connect’: Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2) (Mysql2::Error::ConnectionError)

This has been a brick wall - nothing I have found by searching online seems to offers a working solution to this

How do I solve this and progress to the next step? Any help much appreciated!

1 个赞

Hi, how can I upload database on my DigitalOcean droplet? I used installation 1click of DigitalOcean to install Discourse (Ubuntu).
On my PC I have Windows 10 Home 18362 build version.

Then I have installed Mysql but now I don’t know how “physically” upload Mybb database on the server. Isn’t there phpmyadmin where you can easily import the database? :frowning:

1 个赞

You need to upload the file using scp or similar. Then Something like

  mysql - u user - p password database < filename..sql
3 个赞

I’m stuck :frowning:

1 个赞

This guide should be updated to be compatible with running the import inside a Docker install instead of using a local development machine.

5 个赞

Really looking forward for the guide to run on a docker based environment :slight_smile:

2 个赞

I gave up on DIY in the end and got a developer on the job - referring him to all the great suggestions on this forum (which helped!) - and I believe he achieved this directly on my live Digital Ocean droplet rather than in a separate development environment (so I could review things easily as he worked - users were not impacted as forum not officially live yet.) - in other words I think it is possible.

After a few iterations, results are now pretty good - all the MyCode and strange character issues resolved, translated my MyBB post prefixes as Discourse tags, custom multi-select user profile fields imported successfully.

If he is willing, I will ask him to share any tweaks to standard import script, and other techniques used here.

4 个赞

In case it helps anyone, the developer @rahilqf I engaged completed the project including translation of custom MyBB user fields into Discourse custom user fields (which depends on having the multi-select-user-field plugin installed), MyBB post prefixes translated into Discourse tags, and stripping out of nearly all redundant MyCode tags from MyBB post text.

His customized import script version is shared here - Custom MyBB to Discourse Import Script.

He also successfully merged in a Yahoo Groups Mbox archive, using the standard Yahoo import script - though with this attachments seemed not to translate. In my case that was not a major problem.

3 个赞

我正在从 MyBB 数据库转换用户、帖子、主题等数据!

我遵循了这份指南:Install Discourse on Ubuntu or Debian for Development

http://localhost:3000/http://forum.omaggieconcorsi.com:3000/ 都无法访问。

不过,程序确实在进行转换,只是我不知道在哪里导出转换后的数据。
既然我无法通过 http://forum.omaggieconcorsi.com:3000/http://localhost:3000/ 访问 Discourse,那我该如何至少从旧的 MyBB 论坛导出包含帖子、用户等数据的数据库,然后将其导入到新的 Discourse 实例中呢?

谢谢!

你是在运行浏览器的同一台电脑上按照这些说明操作的吗?

1 个赞

是的,始终是同一台电脑

好的,我已在 Ubuntu 18.04 真实系统(安装在 PC 上)上按照该指南操作,localhost:3000 可以正常访问!

但现在遇到了 MySQL 数据库的问题 :frowning: 抱歉…

我输入了:

debby@debby-MS-7721: mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

:frowning:

编辑:我已使用以下命令为 root 用户设置了密码:ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

并在 DB_PW 中填写了 root 用户的密码。

……现在它正在创建用户!!

为我祈祷吧,经过数周的测试,这是否终于到了成功的时候?

1 个赞

我试图将数据库从 MyBB 导入到 Discourse。和 @Paul_King 一样,我在 DigitalOcean 服务器上无法让它正常工作。按照这份指南操作时,我不断遇到各种错误。

我卡在执行以下命令这一步:

$ bundle exec rails db:drop
bundler: 未找到命令:rails
请使用 `bundle install` 安装缺失的 gem 可执行文件

bundle install 显示已完成:

$ bundle install
您的 Gemfile 中多次列出了 gem mysql2 (>= 0)。
您应该只保留其中一个。
虽然现在不是问题,但如果您稍后更改其中之一的版本,可能会导致错误。
正在使用 bundler 1.16.1
正在使用 mysql2 0.4.10
Bundle 完成!2 个 Gemfile 依赖项,现已安装 2 个 gems。
使用 `bundle info [gemname]` 查看捆绑的 gem 安装位置。

尝试手动安装 rails 时出现以下错误:

$ gem install rails
正在构建原生扩展。这可能需要一些时间...
错误:安装 rails 时出错:
        错误:构建 gem 原生扩展失败。

    当前目录:/var/lib/gems/2.5.0/gems/racc-1.5.2/ext/racc/cparse
/usr/bin/ruby2.5 -r ./siteconf20210110-8155-1ms05r3.rb extconf.rb
mkmf.rb 无法在 /usr/lib/ruby/include/ruby.h 找到 ruby 的头文件

extconf 失败,退出代码 1

Gem 文件将保留在 /var/lib/gems/2.5.0/gems/racc-1.5.2 中以便检查。
结果已记录到 /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/racc-1.5.2/gem_make.out

这令人极度沮丧。


我让这篇帖子保持开放状态,并成功安装了 rails。随后又遇到了一堆其他错误,并设法逐一修复。错误。在。每。一。个。步。骤。上。

我从未对软件产生过如此纯粹的憎恨。Ruby 为什么会这样?这简直是一场噩梦。现在我卡在这个错误上:

$ bundle exec rails db:drop
回溯(最近一次调用最后):
        1: 来自 /usr/local/bin/bundle:23:in `\u003cmain\u003e'
/usr/local/bin/bundle:23:in `load': 无法加载文件 -- /usr/share/rubygems-integration/all/gems/bundler-1.16.1/exe/bundle (LoadError)

有人能帮忙吗?

1 个赞

没什么用,但我在本地开发环境(用于生成 Discourse 数据库文件/备份)和直接在 Digital Ocean Droplet 上部署时,也遇到了同样的难题。最终,在浪费了数十个小时后,我觉得人生苦短,便从 Fiverr 雇了一位开发者(他花了几周时间才搞定,但总算成功了)。
我怀疑,目前并没有足够的动力让任何人去简化这个过程。

祝你好运——如果你最终解决了问题,希望能在这里留下一些线索,供后来者参考!

1 个赞

你是如何安装 Rails 的?是否参考了某个开发指南?(例如 在 Ubuntu 上安装 Discourse 进行开发的初学者指南

关于在生产容器内运行安装脚本,有一些 操作指南文档(我通常这样做),你可以参考其中一份作为指南。