Migrate a NodeBB forum with Redis to Discourse

This tutorial will show you how to use the NodeBB Importer to migrate NodeBB forum to Discourse platform. If your NodeBB forum uses MongoDB as backend then follow this tutorial. 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:

From now on I will be referring to this environment as Discourse server

:bulb: Please, use this guide if you have any trouble setting up Discourse.

Exporting Production Database Dump (from NodeBB Server):

Shut down your forum. This recommended by NodeBB

$ cd /path_to_nodebb
$ ./nodebb stop

You should also shut down Redis:

$ 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:

$ 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

:bulb: If your Redis server requires password use AUTH YOUR_PASSWORD

:bulb: 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:

$ 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:

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

Now you need to stop Redis server (important).

Linux based:

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

Mac OS:

$ 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.

$ 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:

$ ls -la /var/lib/redis

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

$ 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:

# 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:

$ 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:

ATTACHMENT_DIR = '/absolute_path/uploads'

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

db: 0

Run the importer with clean Discourse:

$ 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:

$ bundle exec rails server

Start Sidekiq to process the migrated data:

$ 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.

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

9개의 좋아요

여러 스레드에서 마이그레이션에 대해 계속 질문하고 있네요 :smiley:

NodeBB와 Redis를 사용한 포럼을 운영하고 있으며, 개발 환경에서는 오류 없이 마이그레이션을 완료했습니다. 다만 몇 가지 질문이 있습니다:

  • 마이그레이션 스크립트에서 이미지와 포럼 파일이 있는 절대 경로를 올바르게 지정했습니다. 마이그레이션을 완료한 후 확인해 보니 스레드에서 이미지가 보이지 않습니다. Discourse에서는 URL에 assets/uploads로 링크되어 있는 것으로 보이지만, 해당 경로에는 아무것도 없습니다.

    개발 환경에서는 심볼릭 링크를 만들어서 이 문제를 해결했습니다:
    ln -s path/to/images public/assets

    하지만 프로덕션 환경에서는 docker 내부의 assets/upload에서 이전 이미지를 넣은 폴더로 링크를 만들기 위해 무엇을 해야 하나요?

  • 모든 포럼 스레드가 올바르게 마이그레이션된 것으로 보이지만, 사용자 간의 직접 메시지(DM)는 보이지 않습니다… 마이그레이션에 포함되지 않는 건가요?

  • 스크립트가 사용자 아바타를 감지하지 못했습니다.

  • 마지막으로, 새로운 포럼에서 YouTube 비디오나 트윗 임베딩이 보이지 않습니다. 이를 위해 플러그인을 설치해야 하나요?

도움 주셔서 감사합니다.

이것은 필요하지 않을 것입니다. 원본 이미지가 ATTACHMENT_DIR에 구성된 경로에 있다면, Discourse는 path-to-your-install/discourse/public/uploads/default/에 업로드(실제로는 파일의 복사본)를 생성합니다. Uploads 테이블을 확인하면 다음과 같이 보일 것입니다:

[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",

맞습니다. nodebb 스크립트가 개인 메시지를 마이그레이션하지 않는 것으로 보입니다. 개인 메시지가 어떻게 가져오는지 확인하려면 다른 스크립트를 살펴보세요. 예를 들어 Vanilla 스크립트를 확인할 수 있습니다.

아바타가 올바르게 업로드되지 않고 있는 것 같습니다. 아마도 위에서 언급한 문제와 동일한 원인일 가능성이 높습니다.

플러그인은 필요하지 않습니다. 게시물을 다시 베이킹(rebake)해야 할 가능성이 높습니다. sidekiq가 자동으로 처리하도록 기다릴 수도 있고, 콘솔에서 전체 재베이킹을 실행할 수도 있습니다:

rake posts:rebake

nodebb 스크립트는 몇 년 동안 업데이트되지 않았기 때문에, 일부 부분이 구식이 되어 데이터를 처리하려면 수정이 필요할 것 같습니다. 도움이 되길 바랍니다!

1개의 좋아요