Migrar un foro FluxBB a 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 Me gusta
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 Me gusta

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

Here, everything step-by-step.

¿Está roto este importador en las versiones modernas de Discourse?

Estoy ejecutando una instancia de Discourse instalada usando el discourse/docs/INSTALL.md at main · discourse/discourse · GitHub (también conocido como “Las únicas instalaciones de Discourse admitidas oficialmente”).

Configuré una base de datos MariaDB dentro del contenedor Docker, importé mi volcado del foro allí, etc., porque cualquier otro enfoque es muy difícil de configurar. Todo lo que hice fue dentro del shell cd /var/discourse/ &amp;&amp; ./launcher enter app.

Ejecutar bundle exec ruby script/import_scripts/fluxbb.rb bbcode-to-md falla con:

/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
': No pudimos encontrar tu base de datos: discourse. La cual se puede encontrar en el archivo de configuración de la base de datos ubicado en config/database.yml. (ActiveRecord::NoDatabaseError)

Ejecutar sudo -u postgres psql discourse en el mismo shell me conecta a la base de datos “discourse” sin problemas.

Disculpa la suposición negativa, fue simple:

El script debe ejecutarse con el usuario discourse, no como root en el contenedor, que es lo que hice.

Aparte de que algunos códigos BB no se han convertido, esto parece haber funcionado bien. ¡Gracias!

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 parece ser una buena PR con correcciones a la conversión de códigos BB.

Advertencia importante:

Este importador ignora los permisos.

Todos tus foros se publicarán como públicos.

Si tenías foros configurados para que solo los moderadores pudieran leerlos, cualquiera podrá leerlos después de usar este importador.

1 me gusta

Puedes modificar los permisos de las categorías manualmente después de la importación. Probablemente no sea un trabajo muy grande arreglarlos manualmente.

Añadir soporte para importar los permisos es probablemente un trabajo mayor que hacerlo manualmente.

1 me gusta

Gracias por informar de esto, he añadido una advertencia al respecto en la guía.

2 Me gusta