# Migrate a NodeBB forum with Redis to Discourse

**URL:** https://meta.discourse.org/t/migrate-a-nodebb-forum-with-redis-to-discourse/124897
**Category:** Sysadmins
**Tags:** how-to
**Created:** [August 5, 2019, 12:19pm UTC](https://meta.discourse.org/t/migrate-a-nodebb-forum-with-redis-to-discourse/124897 "2019-08-05T12:19:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![enigmaty](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/enigmaty/32/65626_2.png) [@enigmaty](https://meta.discourse.org/u/enigmaty)
#### Post date: [August 5, 2019, 12:19pm UTC](https://meta.discourse.org/t/migrate-a-nodebb-forum-with-redis-to-discourse/124897/1 "2019-08-05T12:19:19Z")

</div>

This tutorial will show you how to use the [NodeBB Importer](https://github.com/discourse/discourse/blob/master/script/import_scripts/nodebb/nodebb.rb) to migrate NodeBB forum to Discourse platform. If your NodeBB forum uses MongoDB as backend then follow [this tutorial](https://meta.discourse.org/t/importing-nodebb-mongodb-to-discourse/126553). Do not worry, It is an easy process. Let’s get started.

### The plan

- Preparing the development environment.

- Export database from production environment.

- Import the production DB to a Discourse instance.

- Run the importer script.

### What data can be migrated?

- Groups
- Categories
  - Root Category =\> Root Category
  - Sub Category & Sub-Sub-Category =\> Sub-Category

- Attachments
- Topics & Posts
  - pinned topic =\> pinned topic
  - topic views
  - all styles will be migrated just fine with mentions, emoji, and attachments.

- Users (with following attributes)
  - avatars (profile picture)
  - profile background
  - banned status
  - name
  - username
  - email
  - bio
  - admin
  - website
  - location
  - joining at status
  - group

### Preparing Local Development Environment

Set up your development environment by following one of these guides:

- [Ubuntu](https://meta.discourse.org/t/beginners-guide-to-install-discourse-on-ubuntu-for-development/14727)

- [Windows 10](https://meta.discourse.org/t/beginners-guide-to-install-discourse-on-windows-10-for-development/75149)

- [Mac OS](https://meta.discourse.org/t/beginners-guide-to-install-discourse-on-mac-os-x-for-development/15772)

From now on I will be referring to this environment as _Discourse server_

> 💡 Please, use [this guide](https://github.com/discourse/discourse/blob/master/docs/TROUBLESHOOTING.md) if you have any trouble setting up Discourse.

### Exporting Production Database Dump (from NodeBB Server):

Shut down your forum. This recommended by NodeBB

```plaintext
$ cd /path_to_nodebb
$ ./nodebb stop

```

You should also shut down Redis:

```plaintext
$ sudo service redis-server stop
$ sudo service redis-server status
# redis-server is not running

```

Your DB forum is all in one file. This file is auto-generated periodically by Redis. Usually this file is located in `/var/lib/redis/dump.rdb`. Also, you can get the path from Redis CLI:

```plaintext
$ redis-cli
127.0.0.1:6379> config get dir
# "/var/lib/redis"
127.0.0.1:6379> exit
$ ls -la /var/lib/redis
# -rw-rw-r-- 1 redis redis 2664346 Aug 4 16:24 dump.rdb

```

> 💡 If your Redis server requires password use `AUTH YOUR_PASSWORD`

> 💡 If for some reason you did not find your DB file in the expected path, you can generate it manually by running `SAVE` inside Redis CLI.

Now you need to copy the forum attachments:

```plaintext
$ cd /path_to_nodebb_root_folder/
$ tar -czf ./uploads.tar.gz ./public/uploads

```

Now that you have your DB and forum assets you need to copy them to _Discourse server_.

### Importing The Database

If you follow the instructions in installing Discourse you should have Redis server installed on _Discourse server_:

```plaintext
$ redis-server -v
# Redis server v=5.0.2...

```

Now you need to stop Redis server (important).

Linux based:

```plaintext
$ sudo service redis-server stop
$ sudo service redis-server status
# redis-server is not running

```

Mac OS:

```plaintext
$ brew services stop redis
$ brew services list
# redis stopped

```

What you need to do now is to copy the DB forum to our local Redis DB path. The importer needs to connect to Redis server and migrate the NodeBB DB to Discourse DB. This step assumes that you do not have anything important on your Redis DB, otherwise you should perform a backup.

```plaintext
$ redis-cli
127.0.0.1:6379> config get dir
# "/var/lib/redis"

```

Check if there are any files and take note about the current user and permission of dump.rdb:

```plaintext
$ ls -la /var/lib/redis

```

Copy the NodeBB DB (replace if there is one):

```plaintext
$ cp dump.rdb /var/lib/redis

```

Later when trying to connect to Redis server you may get `Fatal error loading the DB: Permission denied`, therefore you should alter the permission of dump.rdb:

```plaintext
# Replace the user with same as the note you take previously.
$ sudo chown redis:redis /var/lib/redis/dump.rdb
$ sudo chmod 660 /var/lib/redis/dump.rdb

```

Now you need to untar the uploads.tar.gz to any path of your choice:

```plaintext
$ tar xvzf uploads.tar.gz

```

### Running The Importer Script

Now that our database in place we are ready to run our importer script. Before that, we need to edit some configuration. You properly need to change just the following two lines.

This is the path of your NodeBB uploads folder:

```plaintext
ATTACHMENT_DIR = '/absolute_path/uploads'

```

This is the name of DB in Redis. The default is `0`:

```plaintext
db: 0

```

Run the importer with clean Discourse:

```plaintext
$ cd ~/discourse
$ bundle exec rake db:drop db:create db:migrate
$ bundle exec ruby script/import_scripts/nodebb/nodebb.rb

```

The importer will connect to the Redis server and migrate everything to Discourse Postgresql DB.

After the importer finishes, start Discourse platform:

```plaintext
$ bundle exec rails server

```

Start Sidekiq to process the migrated data:

```plaintext
$ bundle exec sidekiq

```

You can monitor the progress at `http://localhost:3000/sidekiq/queues`.

Perform a Discourse backup and upload it to your Discourse production server by following this [tutorial](https://meta.discourse.org/t/move-your-discourse-instance-to-a-different-server/15721).

By that, you should have successfully made a full migration from Nodebb to Discourse 🎉  
Please, if you have any questions I am happy to help 🙂

---

<div class="post-metadata">

### Author: ![lenkobeta](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lenkobeta/32/334656_2.png) [@lenkobeta](https://meta.discourse.org/u/lenkobeta)
#### Post date: [October 23, 2023, 9:10am UTC](https://meta.discourse.org/t/migrate-a-nodebb-forum-with-redis-to-discourse/124897/7 "2023-10-23T09:10:42Z")

</div>

I keep on nagging about my migration in different threads 😃

I have a forum on NodeBB with Redis and have been able to complete the process without errors in the development version, but I still have some questions:

- In the migration script I correctly put the absolute path where I had the images and forum files. When I finished the migration I see that the images are not visible in the threads. In Discourse they appear linked in the URL: assets/uploads, but there is nothing there.

- It seems that all the forum threads have been migrated correctly, but I don’t see the direct messages between users… are they not in the migration?

- The script has not detected any user avatars.

- And lastly, in the new forum I don’t see any embedding of Youtube videos or Twitts. Do I have to install a plugin for that?

Thanks a lot for your help.

---

<div class="post-metadata">

### Author: ![cocococosti](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cocococosti/32/231474_2.png) [@cocococosti](https://meta.discourse.org/u/cocococosti)
#### Post date: [November 17, 2023, 7:28pm UTC](https://meta.discourse.org/t/migrate-a-nodebb-forum-with-redis-to-discourse/124897/8 "2023-11-17T19:28:34Z")

</div>

> [@lenkobeta](#):
>
> But in the production version, what do I have to do to create a link from assets/upload inside the docker to the folder where I put the old images?

This shouldn’t be necessary. If you have your original images in a path, configured in ATTACHMENT\_DIR, Discourse will create an upload (essentially, a copy of the file) in `path-to-your-install/discourse/public/uploads/default/`. If you check the Uploads table it should look like this:

```plaintext
[1] pry(main)> Upload.last
  Upload Load (1.5ms) SELECT "uploads".* FROM "uploads" ORDER BY "uploads"."id" DESC LIMIT 1
=> #<Upload:0x0000000109a460a0
 id: 196,
 user_id: 251468,
 original_filename: "Screenshot 2023-11-17 at 11.52.39.png",
 filesize: 25174,
 width: 398,
 height: 248,
 url: "/uploads/default/original/1X/2e5f7a09ba3bcd3a3597285771c53c16f20b18dd.png",
 created_at: Fri, 17 Nov 2023 19:12:47.455954000 UTC +00:00,
 updated_at: Fri, 17 Nov 2023 19:12:47.484137000 UTC +00:00,
 sha1: "2e5f7a09ba3bcd3a3597285771c53c16f20b18dd",

```

> [@lenkobeta](#):
>
> I don’t see the direct messages between users… are they not in the migration?

Correct, looks like the nodebb script doesn’t migrate private messages. You can check other scripts to see how private messages are imported, check the [Vanilla one](https://github.com/discourse/discourse/blob/main/script/import_scripts/vanilla.rb#L257) for example.

> [@lenkobeta](#):
>
> The script has not detected any user avatars.

The avatars are probably not being uploaded correctly, probably for the same issue you mentioned above.

> [@lenkobeta](#):
>
> I don’t see any embedding of Youtube videos or Twitts. Do I have to install a plugin for that?

No need for a plugin. You probably need to rebake your posts. You can wait for sidekiq to do so automatically, or you can run a full rebake from the console:

```plaintext
rake posts:rebake

```

The nodebb script hasn’t been updated in a few years, so my guess is that some parts of it are outdated and need to be modified in order for it to work with your data. Hope this helps!
