Migrating a myBB forum to Discourse using Kubuntu in a VM

Summing up the (much longer than this post) :wink: journey:

NOTE: I used a Kubuntu distribution running in virtual machine for the process so please have in mind that it may not be the same on different OS or even distribution

0. installing Discourse dev environment

Following this post and running this script linked to in the post using

`bash <(wget -qO- https://raw.githubusercontent.com/discourse/install-rails/master/linux)` 

as described there plus cloning the sources

git clone https://github.com/discourse/discourse.git ~/discourse

1. Preparing MySQL database

Get dump of the original mybb database as described on top of the thread:

$ mysqldump -u USER_NAME -p DATABASE_NAME > mybb_dump.sql

and copy/move it over to the newly set development environment.

Install MySQL server

$ sudo apt-get install mysql-server

Authentication for mysql changed in more recent versions. You have to be root on the host if you want to be root on mysql these days so

$ sudo mysql

instead of

$mysql -u root

Of course you have to be a “sudoer” (administrator) first

$ sudo mysql
mysql> CREATE DATABASE mybb;
mysql> SHOW DATABASES;
mysql> CREATE USER 'nonrootuser'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON mybb.* TO 'nonrootuser'@'localhost';
mysql> quit
$ mysql -unonrootuser -ppassword mybb < mybb_dump.sql
<here you get warning about providing password on the command line not being a smart thing to do>

$ sudo mysql
mysql> USE mybb;
mysql> SHOW TABLES;
<here verify if all the tables are present - see the original post>

mysql> quit

2. Install Ruby gems

Checking the Gemfile in the current sources reveals that

$ echo "gem 'mysql2', require: false" >> Gemfile

is not really needed. It is enough to set the environment variable IMPORT to 1.
What is needed though are development files for MySQL clients, which is what the first line below is about

$ sudo apt-get install libmysqlclient-dev
$ cd ~/discourse
$ IMPORT=1 bundle install

2. Prepare Discourse (PostgreSQL database)

$ bundle exec rails db:drop
$ bundle exec rails db:create
$ bundle exec rails db:migrate
$ export DB_PW="password"
$ export DB_USER="nonrootuser"

3. Execute the actual import

The next line fixes a long deprecated and currently already removed method call in mybb.rb import script, which is still there at the time of writing and won’t change anything if this is already fixed

$ sed -i.original 's/File.exists?/File.exist?/' script/import_scripts/mybb.rb

Now check if Redis is still running. The Rails install script starts it but does not enable it as a permanent service so it doesn’t survive reboots, crashes, whatever, etc.

$ ps -aux |grep redis
silverdr    2808  0.3  0.3  89972 14512 ?        Ssl  05:25   2:04 redis-server *:6379
[…]

If you don’t see anything like the line above run

$ redis-server --daemonize yes

which is the very same command the above Rails installation script used the first time when installing.

Finally :pray: and

$ IMPORT=1 bundle exec ruby script/import_scripts/mybb.rb

If at this time the script didn’t stop with YAE (Yet Another Error) than it’s time to pop open that bottle :champagne:

A few things remain

  • OK - so the one obvious missing part are users’ passwords. Apparently, even though both applications store hash’n salt, judging by those hashes length “mybb” uses an older hashing algorithm. Therefore this is understandable and not a show-stopper. Everyone should be able to reset her password the first time.
  • Some bbcode stuff does not get converted. I have for example problem with code blocks, which have some tags around them setting monospaced Courier font and whatnot. I have no more stamina to try to automate this thing further. If you manage to do something about it please let me / us here know! :man_bowing:
2 Likes