# Migrare un forum Kunena 3 a Discourse

**URL:** <https://meta.discourse.org/t/migrate-a-kunena-3-forum-to-discourse/43776>\
**Category:** Sysadmins\
**Tags:** how-to\
**Created:** [6 Maggio 2016, 5:25am UTC](https://meta.discourse.org/t/migrate-a-kunena-3-forum-to-discourse/43776 "2016-05-06T05:25:00Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![tarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tarek/32/124831_2.png) [@tarek](https://meta.discourse.org/u/tarek)\
**Post date:** [6 Maggio 2016, 5:25am UTC](https://meta.discourse.org/t/migrate-a-kunena-3-forum-to-discourse/43776/1 "2016-05-06T05:25:00Z")

</div>

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](https://meta.discourse.org/t/beginners-guide-to-install-discourse-on-mac-os-x-for-development/15772), [Ubuntu](https://meta.discourse.org/t/beginners-guide-to-install-discourse-on-ubuntu-for-development/14727) or [Windows](https://github.com/discourse/discourse/blob/master/docs/VAGRANT.md).

2. Install MySQL or MariaDB

```bash
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

```bash
echo "gem 'mysql2'" >> Gemfile
bundle install

```

1. Create MySQL user, grants and table.

```bash
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

```bash
mysql -u kunena -pkunena < mykunena.sql

```

### Readying the Script for the import

Copy and paste these lines into your shell:

```bash
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 ⬆ and ⬅ 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 ⬆ 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:

- Kunena3 attachments have a URL like this:

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:

```bash
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:

```plaintext
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](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](https://meta.discourse.org/t/move-your-discourse-instance-to-a-different-server/15721).

## @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! 🎉

---

_[View the full topic](https://meta.discourse.org/t/migrate-a-kunena-3-forum-to-discourse/43776)._
