Migrate a Kunena 3 forum to Discourse

Want to migrate from Kunena3 to Discourse? Great! Let’s get started.

Note: @tarek’s fine work on this topic was replaced wholesale after @pfaffman made considerable changes to the importer. Do not blame @tarek for mistakes!

What data can be imported?

  • Users
  • Categories
  • Topics & Posts
  • Attachments

Prerequisites

  1. Set up Discourse development environment on OS X, Ubuntu or Windows.

  2. Install MySQL or MariaDB

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mariadb-server libmysqlclient-dev
sudo gem install mysql2
  1. Add MySQL to the Gemfile and install it
echo "gem 'mysql2'" >> Gemfile
bundle install
  1. Create MySQL user, grants and table.
MYSQLPASSWD=mysqlpassword
mysql -u root -p$MYSQLPASSWD <<EOF
CREATE USER 'kunena'@'localhost' IDENTIFIED BY 'kunena';
CREATE DATABASE kunena;
GRANT ALL PRIVILEGES ON kunena . * TO 'kunena'@'localhost';
FLUSH PRIVILEGES;
EOF
  1. Import your Kunena / Joomla installation
mysql -u kunena -pkunena < mykunena.sql

Readying the Script for the import

Copy and paste these lines into your shell:

export DB_HOST="localhost"
export DB_NAME="kunena"
export DB_USER="kunena"
export DB_PW="kunena"
export KUNENA_PREFIX="jos_" # "iff_" sometimes
export IMAGE_PREFIX="http://EXAMPLE.com/media/kunena/attachments"
export PARENT_FIELD="parent_id" # "parent" in some versions
  • Use :arrow_up: and :arrow_left: and to edit the DB variables appropriately.

  • The Kunena tables are prefixed with jos_ in some cases, and with iff_ in others. If the import script fails for you with an error like “unknown column”, hit the :arrow_up: and change the KUNENA_PREFIX variable to iff_. If that fails too, you will need to inspect the database tables to see what prefix yours uses. This grep command will give you a list of tables in the database:

    grep “CREATE TABLE” mykunena.sql

  • Kunena3 attachments have a URL like this:

    http://EXAMPLE.com/media/kunena/attachments/USERID/FILENAME

Edit that variable too.

  • Parent field. In some versions, the parent_id field of the category table was parent. If you get an error about an “unknown column”, change the PARENT_FIELD to “parent”.

This is really going to happen!

  1. Make sure that neither Discourse nor Sidekiq are running.

  2. Clear existing data from your local Discourse instance:

cd ~/discourse
rake db:drop db:create db:migrate
  1. Run the import script: ruby script/import_scripts/kunena3.rb

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

  3. Start your Discourse instance: RAILS_ENV=development 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

  • If you want Discourse to copy the images to its own database, in your Discourse settings, enable download remote images to local and change download remote images max days old to a sufficiently large value, then rake posts:rebake.
  1. Take backup of the data and upload it to on your production site by following this howto.

@tarek’s known issues (2016-05-05)

If, like us, you had a very old Kunena installation that spanned several generations, then you may run into two problems:

  1. Users are not properly imported for very old posts
  2. BBCode makes its way into the posts.

It was very time-consuming, but I hand-fixed these. There is some code in the PHPBB import scripts that addresses BBCode → MD conversion, but I didn’t spend much time on it.


Congratulations! You have successfully migrated your site from Kunena3 to Discourse! :tada:

9 Likes

Hi Tarek,

Thank you! I will be trying this asap!!!

/Kohhal

Ok, development environment installed (I had previously been trying the import on a DigitalOcean droplet)

First stumbling block in Step 2, “unknown command mysql2”

woops. That should read ‘gem install mysql2’ I’ll fix it now. Thank you for testing this!

I just reread the error. You are supposed to add it to the end of the file. I’ve now given an actual command for this using “echo”. Give it a try and see if it works.

echo "gem 'mysql2'" >> Gemfile

Thanks. I’m on holidays until next week - will test as soon as i return

2 Likes

Getting further, Step 4! - where/how do I need to put the .sql backup in order for this command to work?

You run the command in the directory of the script. Otherwise, set the location. e.g., if your current directory is /home/kohhal, and the file is at /home/kohhal/mykunena.sql, the command above is correct.

If you are in a separate directory, the command is:

mysql -u kunena -p kunena < /home/kohhal/mykunena.sql

Thanks, found the relevant directory on my machine. Is there a way to see if the sql import worked as I am getting an error on the script now as below but I’m sure the table name is correct :

‘kunena.iff_users’ doesn’t exist

Hi Kohhal,

This is relatively basic SQL stuff, so perhaps check a guide, ask on the MySQL IRC channels/forums or web search for answers on this one.

Tarek : )

1 Like

Based on this tutorial, should the host be ‘localhost’ ? I suspect/hope that is why my table is not found…

How to get the import script?

I came to step “Readying the Script for the import”

But when I go to:

cd /var/discourse/scripts/
ls -ls

I only see

4 -rwxr-xr-x 1 root root 150 Nov 11 12:32 docker-gc
4 -rwxr-xr-x 1 root root 1115 Nov 11 12:32 mk_swapfile

1 Like

I have the same question. I see them on GitHub here: https://github.com/discourse/discourse/tree/master/script/import_scripts

But I don’t see that in my Digital Ocean droplet. I feel pretty dumb, because the guides make this seem simple, so I guess I’m missing something obvious.

1 Like

Search here for #howto topics for other importers. It’s pretty much the same.

I did so before asking but I couldnt find it else I wouldnt ask…

Here’s one Importing from vBulletin 4

That link tells us to execute this line:

bundle exec ruby script/import_scripts/vbulletin.rb

We’re asking how to do that, because we don’t see a script directory. We only see a scripts directory, and it doesn’t contain the import scripts.

Those instructions say to install a development environment. If you had followed them, you’d see the import scripts.

If you want to try with a production docker container, you can enter the container and I think you’ll find it there,but that’s likely to cause other complications.

2 Likes

Thanks, I guess entering the container is the step I was missing. If I do that, then I can see the import scripts. Unfortunately I don’t have access to a Ubuntu or OS X machine, so I was really hoping to do this directly in Docker. But now I’m getting a bunch of other errors. Sigh. This was just a weekend experiment, so maybe I’ll just stop pursuing this option.

Thanks for your help. Feel free to delete these messages since they don’t really contribute to the actual conversation.

Hi all. My question is actually about the thread’s topic, Kunena, not about the vBulletin issue which hijacked this thread :slight_smile:

In the Kunena import script, has anybody tried importing the “Thank yous” that any user can give to other people’s posts? I actually think that’s an important part of the community status of people. It should translate into something in Discourse… badges? hearts? I’m not familiar with Discourse yet.

1 Like