将 FluxBB 论坛迁移到 Discourse

I created a migration script to import FluxBB database into Discourse. Now I’m going to explain how to do the import process in a step-by-step tutorial.

I tested this migration script with FluxBB v1.5.10 (which is current version now)

What data can be imported?

  • Users
  • Groups
  • Categories
    :warning: Permissions won’t be imported and all categories will be public. Right permissions must be set manually after the import.
  • Topics
  • Posts
  • Suspended users

Before starting the migration, set a development environment on your machine (or inside a virtual machine) . See the OS X or Ubuntu installation guide for development.

I used Ubuntu 16.04 LTS amd64 xenial image. I recommending using Ruby version 2.3.0 or above (at least 2.0.0). Because I had some compatability issues when installing mysql2 with older versions of Ruby.

To check Ruby version enter the command below

ruby -v

Mysql

Now we need mysql2 gem for ruby to connect with our old FluxBB database. Run the below commands to install libmysqlclient-dev dependency & mysql2 gem.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install libmysqlclient-dev
gem install mysql2

(optional) Importing MySQL dump into localhost

To install MySQL client and import mysql dump file (.sql) to your development machine follow the instructions below

sudo apt-get install mysql-server-5.5 mysql-client-5.5

Create MySQL user, grants and table

mysql -u root -p mysql
mysql> CREATE USER 'fluxbb'@'localhost' IDENTIFIED BY 'fluxbb';
Query OK, 0 rows affected (0.00 sec)
.
mysql> CREATE DATABASE fluxbb;
Query OK, 1 row affected (0.01 sec)
.
mysql> GRANT ALL PRIVILEGES ON fluxbb.* TO 'fluxbb'@'localhost';
Query OK, 0 rows affected (0.00 sec)
.
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
.
mysql> exit

Import your FluxBB database dump file

mysql -u fluxbb -p fluxbb < myfluxbb.sql

BBcode to Markdown

Discourse uses Markdown while FluxBB use BBCode. So we have to convert bbcodes to markdown in all posts. For that we are going to use the nlalonde/ruby-bbcode-to-md gem. Follow the steps below to install the ruby-bbcode-to-md gem.

cd
git clone https://github.com/nlalonde/ruby-bbcode-to-md.git
cd ruby-bbcode-to-md
gem build ruby-bbcode-to-md.gemspec
gem install ruby-bbcode-to-md-*.gem

After the successful installation of both mysql2 and ruby-bbcode-to-md go to your Discourse installation path and open Gemfile to edit.

cd ~/discourse
sudo nano Gemfile

Now insert the lines below at the end of the file to add mysql2 and ruby-bbcode-to-md gems to Discourse.

gem 'mysql2'
gem 'ruby-bbcode-to-md'

Before running the import script, paste these lines one by one into your shell. (use arrow keys to edit the values)

export FLUXBB_HOST="localhost"
export FLUXBB_DB="fluxbb"
export FLUXBB_USER="root"
export FLUXBB_PW=""
export FLUXBB_PREFIX=""

Now it’s time to run the import script. Run the below command to start migration.

bundle exec ruby script/import_scripts/fluxbb.rb bbcode-to-md

Wait until the import is done. You can restart it if it slows down to a crawl.

After all congratulations! Your database successfully migrated from FluxBB to Discourse :thumbsup:

Start your Discourse instance:

bundle exec rails server

Start Sidekiq and let it do its work:

bundle exec sidekiq -q critical,4 -q default,2 -q low

Depending on your forum size this can take a long time. You can monitor the progress at http://localhost:3000/sidekiq

Now take a backup from admin page /admin/backups and import it in your live Discourse website.

Last edited by @JammyDodger 2024-05-27T14:54:39Z

Check documentPerform check on document:
12 个赞
discourse@app-deb10-app:/var/www/discourse$ FLUXBB_HOST="localhost" FLUXBB_DB="flux" FLUXBB_USER="fluxbb" FLUXBB_PW="fluxbb" RAILS_ENV=production bundle exec ruby script/import_scripts/fluxbb.rb 
Loading existing groups...
Loading existing users...
Loading existing categories...
Loading existing posts...
Loading existing topics...

creating groups
Traceback (most recent call last):
	9: from script/import_scripts/fluxbb.rb:262:in `<main>'
	8: from /var/www/discourse/script/import_scripts/base.rb:47:in `perform'
	7: from script/import_scripts/fluxbb.rb:40:in `execute'
	6: from script/import_scripts/fluxbb.rb:50:in `import_groups'
	5: from script/import_scripts/fluxbb.rb:258:in `mysql_query'
	4: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rack-mini-profiler-2.3.2/lib/patches/db/mysql2/alias_method.rb:22:in `query'
	3: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `query'
	2: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `handle_interrupt'
	1: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `block in query'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `_query': Table 'flux.groups' doesn't exist (Mysql2::Error)

Looks like the tables don’t exist in the mySQL database. I’d check by logging in to the mySQL DB first and seeing what tables are there. You might need to modify the script to get it to work.

2 个赞

https://creio.github.io/fluxbb-discourse/

Here, everything step-by-step.

这个导入器在现代 Discourse 版本中是否已损坏?

我正在运行一个使用 https://github.com/discourse/discourse/blob/main/docs/INSTALL.md(又名“唯一官方支持的 Discourse 安装”)安装的 Discourse 实例。

我确实在一个 Docker 容器内设置了一个 MariaDB 数据库,并将我的论坛转储导入到那里,等等,因为任何其他方法都很难设置。我所做的一切都在 cd /var/discourse/ && ./launcher enter app shell 中完成。

运行 bundle exec ruby script/import_scripts/fluxbb.rb bbcode-to-md 会失败并出现以下错误:

/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/connection_adapters/postgresql_adapter.rb:81:in `rescue in new_client
': We could not find your database: discourse. Which can be found in the database configuration file located at config/database.yml. (ActiveRecord::NoDatabaseError)

在同一个 shell 中运行 sudo -u postgres psql discourse 可以正常登录到“discourse”数据库。

抱歉,我之前的假设是错误的,原因很简单:

该脚本应该使用 discourse 用户运行,而不是像我之前那样在容器内以 root 身份运行。

除了某些 BB 代码未转换外,其他一切似乎都运行良好。谢谢!

Tests, fixes, and a small (optional) feature to allow a FluxBB config to work by harry-wood · Pull Request #6 · nlalonde/ruby-bbcode-to-md · GitHub 似乎是一个不错的 PR,修复了 BB 代码转换问题。

重要警告

此导入程序将忽略权限设置。

您的所有论坛都将被设为公开

如果您有仅限版主阅读的论坛,在使用此导入程序后,任何人都可以阅读它们。

1 个赞

导入后,您可以手动修改分类的权限。手动修复它们可能不是什么大问题。

添加对导入权限的支持可能比手动执行要复杂。

1 个赞

感谢您报告此问题,我已在指南中添加了相关警告。

2 个赞