I really wanted to migrate our good ol’ SMF2 forum to Discourse. We have 1000+ members and ~20k posts in ~2k topics.
On SMF2, we did not use polls nor attachments – actually, not everyone even had an avatar. Some posts heavily relied on “advanced” BBCode, though.
Here’s how we pulled this off.
If you can’t open a remote connection to your SMF2 MySQL database, you will have to import your data from a dump into a temporary Docker container.
If your database accepts remote connections – or runs on the same host, you can skip this step.
A temporary Docker MySQL container
Dump your database:
cd /tmp/ mysqldump –u[user name] –p[password] [database name] > sqldump.sql
Create the temporary Docker MySQL container:
cd /tmp/ docker run -d -e MYSQL_ROOT_PASSWORD=pass -e MYSQL_USER=user -e MYSQL_PASSWORD=pass -e MYSQL_DATABASE=db -v "$PWD":/backup --name=mysql mysql
Then enter it:
docker exec -it mysql bash
Import your database dump:
mysql -uuser -ppass db < /backup/sqldump.sql
If you get the following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Just wait a minute for the container to be fully booted.
For database compatibility, I had to change our temporary database authentification plugin, but I suppose your mileage may vary:
mysql -uuser -ppass db
Use this query:
ALTER USER user IDENTIFIED WITH mysql_native_password BY 'pass';
Then logout and check your MySQL instance IP address:
exit docker inspect mysql | grep IPAddress
You now have a working copy of your SMF2 database.
A temporary Discourse import container
Let’s create a new container called “import”, based off the default app.yml container:
cd /var/discourse cp containers/app.yml containers/import.yml nano containers/import.yml
Add the mysql-dep template to your new import container:
templates: - "templates/postgres.template.yml" - "templates/redis.template.yml" - "templates/web.template.yml" - "templates/web.ratelimited.template.yml" ## Uncomment these two lines if you wish to add Lets Encrypt (https) #- "templates/web.ssl.template.yml" #- "templates/web.letsencrypt.ssl.template.yml" - "templates/import/mysql-dep.template.yml"
/var/discourse/launcher stop app /var/discourse/launcher rebuild import
Importing into Discourse
Once the import container is rebuilt, we have to enter it for our latest tweak:
/var/discourse/launcher enter import cd /var/www/discourse/ # the script has to be launched from that precise directory, but you should have landed there anyway su discourse -c "bundle exec ruby script/import_scripts/smf2.rb -h 172.17.0.3 -u user -p pass -d db -f smf_ -t Europe/Paris"
- -h: your SMF2 MySQL database hostname (here, a Docker container’s IP) ;
- -u: SMF2 MySQL user;
- -p: SMF2 MySQL password;
- -d: SMF2 MySQL database;
- -f: SMF2 tables prefix;
- -t: SMF2 timezone.
If you created it, stop and remove the temporary MySQL Docker container:
docker stop mysql docker rmi mysql
Stop the Discourse “import” container and use the launcher to cleanup:
/var/discourse/launcher destroy import /var/discourse/launcher cleanup
I actually managed to destroy my main container No biggies:
/var/discourse/launcher rebuild app
Discourse settings after import
Some default settings might cause problems with imported posts and permissions. Change these according to your needs from the Discourse settings panel:
- min topic title length: I changed it to 3 – topics which title were too short proved very hard to work with (couldn’t be moved, etc.) ;
- title prettify: I had to turn it off – topics which title didn’t start with an uppercase letter proved very hard to work with (couldn’t be moved, etc.).
- How to use the bbpress import script - or any other import script with mysql dependency (lead4good, May 2017) ;
- “Authentication plugin ‘caching_sha2_password’ cannot be loaded” (meow, April 2018).