Migrate a FluxBB forum to 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 Likes
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 Likes

Вот, все по шагам.

Is this importer broken in modern Discourse versions?

I am running a Discourse instance installed using the discourse/docs/INSTALL.md at main · discourse/discourse · GitHub (aka “The only officially supported installs of Discourse”).

I did set up a MariaDB DB inside the Docker container, imported my forum dump there, etc because any other approach is very hard to set up. Everything I did was inside the cd /var/discourse/ && ./launcher enter app shell.

Running bundle exec ruby script/import_scripts/fluxbb.rb bbcode-to-md fails with:

/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)

Running sudo -u postgres psql discourse in the same shell logs me into the “discourse” database just fine.

Sorry for the negative assumption, it was simple:

The script is meant to be run with the discourse user, not as root in the container which is what I did.

Apart from some BB codes not being converted this seems to have worked well. Thank you!

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 seems to be a nice PR with fixes to the BB code conversion.

Huge warning:

Permissions are ignored by this importer.

All your forums will be posted as public.

If you had forums that were set to be only readable by moderators, they will be readable by anyone after you used this importer.

1 Like

You can modify the permissions of the categories by hand after import. It’d likely not that big a job to fix them up by hand.

Adding support for importing the permissions is likely a bigger job than doing it by hand.

1 Like

Thank you for reporting this, I’ve added a warning about this in the guide.

2 Likes