将 vBulletin 4 论坛迁移到 Discourse

本指南介绍如何使用位于 script/import_scripts/vbulletin.rb 的导入脚本,将 vBulletin 4 论坛迁移到 Discourse。

:warning: **请准备调整脚本。**每个 vBulletin 安装都有其特有的插件、自定义字段和 BBCode 怪异之处。大多数实际导入都需要对脚本进行小幅修改。在生产环境中操作之前,请先在开发机器上进行完整的测试导入。

我应该使用哪个导入器?

论坛 脚本
vBulletin 4 script/import_scripts/vbulletin.rb(本指南)
vBulletin 3 script/import_scripts/vbulletin3.rb(步骤相同,脚本名称不同)
vBulletin 5 script/import_scripts/vbulletin5.rb
超大型论坛(数百万帖子) script/bulk_import/vbulletin.rb(速度更快,但功能较少且更难自定义)

导入的内容

  • 群组
  • 用户(被封禁的用户变为被禁用的用户)
  • 论坛:每个父论坛和子论坛分别成为一个类别和子类别
  • 主题
  • 置顶帖子 → 固定主题
  • 关闭的帖子 → 关闭的主题
  • 软删除或审核中的帖子 → 未列出的主题
  • 帖子
  • 私信
  • 附件
  • 头像(仅当头像存储在数据库中时,请参见下文)
  • 主题的永久链接

注意事项

  • 您可以恢复中断的导入,并针对较新的数据库快照重新运行,以获取新内容。已经导入的内容不会用后来的编辑更新。

  • Discourse 支持两级类别。嵌套更深的论坛会被扁平化处理。

  • BBCode 列表([ul]、[ol]、[li])未完全转换,可能需要手动清理。

导出之前

如果 vBulletin 将头像存储在文件系统中,导入器将无法找到它们。请访问您 vBulletin 站点上的 /admincp/avatar.php?do=storage,并在导出之前将头像移入数据库。

然后在 vBulletin 服务器上导出数据库:

mysqldump -u USERNAME -p DATABASE_NAME | gzip > vb4_dump.sql.gz

将转储文件和附件文件夹复制到您将执行导入的计算机上(例如,使用 scp 或 rsync)。您的 vBulletin 管理员设置显示了附件的存储位置。

选项 A:在开发机器上导入(推荐)

本地导入可以让您快速迭代并丢弃失败的尝试。当结果看起来正确时,备份站点并在生产环境中恢复。

  1. 设置 Discourse 开发环境,请遵循 Ubuntu/Debian 或 macOS 指南。

  2. **安装 MariaDB。**它是 MySQL 的直接替代品,且 MySQL 5.7 包在当前发行版中不再可用。

    # Ubuntu/Debian
    sudo apt-get update
    sudo apt-get install mariadb-server libmariadb-dev
    sudo service mariadb start
    
     # macOS
     brew install mariadb
     brew services start mariadb
    
  3. **安装导入器 gems。**当设置了 IMPORT=1 时,会包含 mysql2。需要添加 php-serialize:

    cd ~/discourse
    echo "gem 'php-serialize', require: false" >> Gemfile
    IMPORT=1 bundle install
    
  4. 加载 vBulletin 数据库:

    sudo mysql -e "CREATE DATABASE vb4"
    gunzip < vb4_dump.sql.gz | sudo mysql vb4
    
  5. 从空的 Discourse 数据库开始:

    bin/rails db:drop db:create db:migrate
    
  6. **运行导入器。**您可以随时停止并重启它,因为它会跳过已经导入的内容。

    export DB_HOST="localhost"  
    export DB_NAME="vb4"
    export DB_USER="root"
    export DB_PW=""                                # MariaDB root 密码,如果您设置了一个
    export TABLE_PREFIX="vb_"                      # 您的表前缀,如果没有则为 ""
    export ATTACHMENT_DIR="/path/to/attachments"   # 您复制的附件文件夹
    export TIMEZONE="America/Los_Angeles"          # vBulletin 使用的时区
    
    IMPORT=1 bundle exec ruby script/import_scripts/vbulletin.rb
    
  7. **启动 Discourse 并让后台作业完成。**运行 bin/dev,并在第二个终端中运行 bundle exec sidekiq。在大型论坛上,帖子重新烘焙和图像处理可能需要很长时间。您可以通过 http://localhost:4200/sidekiq 跟踪进度。

  8. **迁移到生产环境。**请按照 将 Discourse 站点移动到另一个 VPS 进行备份并在生产站点上恢复。

选项 B:在生产容器内直接导入

  1. 安装 Discourse,请参见标准安装指南。

  2. 调整站点设置(请参见下文 推荐的站点设置)。

  3. 将转储文件和附件复制到主机上的 /var/discourse/shared/standalone/ 中。在容器内,它们显示在 /shared/ 下,那里的文件在容器重建后仍然存在。

  4. 进入容器并安装 MariaDB:

    cd /var/discourse
    ./launcher enter app
    apt-get update
    apt-get install -y mariadb-server libmariadb-dev
    service mariadb start
    
  5. 安装导入器 gems:

    cd /var/www/discourse
    echo "gem 'php-serialize', require: false" >> Gemfile
    su discourse -c 'bundle config set --local deployment false && bundle config set --local frozen false'
    su discourse -c 'IMPORT=1 bundle install'
    
  6. 加载 vBulletin 数据库:

    mysql -e "CREATE DATABASE vb4"
    gunzip < /shared/vb4_dump.sql.gz | mysql vb4
    
  7. **运行导入器。**在 tmux 或 screen 中运行它,这样 SSH 断开连接就不会终止它。

    cd /var/www/discourse
    su discourse -c 'DB_NAME=vb4 DB_USER=root DB_PW="" TABLE_PREFIX=vb_ \
    ATTACHMENT_DIR=/shared/attachments TIMEZONE=America/Los_Angeles \
    IMPORT=1 bundle exec ruby script/import_scripts/vbulletin.rb'
    
  8. **清理。**删除您复制到 /shared 中的文件,然后重建容器。重建将删除 MariaDB 和额外的 gems,并恢复原始的 Gemfile。

    exit
    cd /var/discourse
    ./launcher rebuild app
    

推荐的站点设置

请在导入之前设置这些。您也可以在 script/import_scripts/base.rb 中的 get_site_settings_for_import 中设置它们,这在您反复运行测试导入时很有帮助。

  • login_required:在导入完成并检查之前启用此选项。

  • slug_generation_method:如果您的论坛不是英文的,请设置为 encoded,以便主题 URL 保留其非 ASCII 标题。

  • download_remote_images_to_local:如果您不希望 Discourse 下载旧帖子中热链接的图片,请禁用此选项。

  • disable_system_edit_notifications:启用此选项,以便用户在系统处理图片编辑帖子时不会收到每次编辑的通知。

已知问题

  • **parse_timestamp 中出现 Integer values are not supported (ArgumentError)。**这影响在较新版本的 tzinfo 下运行的旧版脚本副本。请更新到最新的 Discourse,或将 parse_timestamp 更改为:

    def parse_timestamp(timestamp)
    return nil if timestamp.blank?
       Time.zone.at(@tz.utc_to_local(Time.at(timestamp.to_i)))
    end
    
  • **包含空格用户名或嵌套引用的引用未被转换。**请参见此回复以获取改进的正则表达式。

  • **Can't connect to local server through socket。**MariaDB 未运行。请使用 service mariadb start 启动它。

21 个赞

The script will now import avatars, but they must be embedded into the database. To do so, I’m told that you visit /admincp/avatar.php?do=storage and do something there. It seemed to work for the last client I did an import for.

Hey, @erlend_sh, make this a wiki and I’ll add to it in a few days when I submit a PR for this importer.

6 个赞

I was following your guide to import my vBulletin forum to Discourse. I am using a docker container for Discourse. I ran the following command:

I got a long list of errors:

sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
[...]
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified

Bundler::SudoNotPermittedError: Bundler requires sudo access to install at the moment. Try installing again, granting Bundler sudo access when
prompted, or installing into a different path.
An error occurred while installing rake (11.2.2), and Bundler cannot continue.
Make sure that `gem install rake -v '11.2.2'` succeeds before bundling.

I am new to ruby on rails and dockers. I do understand the concept of gems and Bundler.
What do these errors mean and how can I resolve them?

1 个赞

Ok so basically I had to install all the necessary gems.
The script worked quite well.

However, I am not able to login with one of the users I created on my vBulletin forum just before importing the database over to discourse.

1 个赞

You’ll need to set passwords. The script doesn’t import them (last I looked).

And even if it did, you’d need to install a plugin to make them work.

1 个赞

I am planning to write a script that will import the passwords for my case.
I know the mysql tables I need to consider for vBulletin. What is the table in PostgreSQL for Discourse that stores passwords and is used during login?

Prakarsh would you be able to share the forum url that you are trying to switch from? The vBulletin one. Will the Discourse one have the same URL?

Yes. Here it is: Brainstorm

Our plan is to keep the URL same for now. I cannot say when it will be live. Probably by end of next week if everything goes right :stuck_out_tongue:

1 个赞

Before you do that, you should read this topic.

You don’t want to directly touch the Discourse tables. You want a script like this. When I last used it and tried to import the passwords, it ran really slowly. I’m not sure why, but after reading this I decided that it’s probably not a bad idea to make people change their passwords.

3 个赞

@pfaffman - You mentioned you used import_pass field in your import script.
Where exactly do you put the import_pass field? And how do you use it?
If you could share it would be great help.

I have tried using this script but it failed 90% into the import of the users:

su discourse -c 'RAILS_ENV=production ruby script/import_scripts/vbulletin.rb'
root:XXXX@localhost wants vb4
loading existing groups...
loading existing users...
loading existing categories...
loading existing posts...
loading existing topics...

importing groups...
        6 / 19 ( 31.6%)  Failed to create group id 7 Moderators: ["Name has already been taken"]
       19 / 19 (100.0%)  
importing users
     2746 / 15319 ( 17.9%)  W, [2017-10-12T10:07:05.104837 #3578]  WARN -- : Bad date/time value "0000:00:00 00:00:00": mon out of range
W, [2017-10-12T10:07:05.106562 #3578]  WARN -- : Bad date/time value "0000:00:00 00:00:00": mon out of range
W, [2017-10-12T10:07:05.107305 #3578]  WARN -- : Bad date/time value "0000:00:00 00:00:00": mon out of range
    13901 / 15319 ( 90.7%)  script/import_scripts/vbulletin.rb:137:in `strip': invalid byte sequence in UTF-8 (ArgumentError)
        from script/import_scripts/vbulletin.rb:137:in `block (2 levels) in import_users'
        from /var/www/discourse/script/import_scripts/base.rb:226:in `block in create_users'
        from /var/www/discourse/script/import_scripts/base.rb:225:in `each'
        from /var/www/discourse/script/import_scripts/base.rb:225:in `create_users'
        from script/import_scripts/vbulletin.rb:133:in `block in import_users'
        from /var/www/discourse/script/import_scripts/base.rb:784:in `block in batches'
        from /var/www/discourse/script/import_scripts/base.rb:783:in `loop'
        from /var/www/discourse/script/import_scripts/base.rb:783:in `batches'
        from script/import_scripts/vbulletin.rb:117:in `import_users'
        from script/import_scripts/vbulletin.rb:78:in `execute'
        from /var/www/discourse/script/import_scripts/base.rb:45:in `perform'
        from script/import_scripts/vbulletin.rb:902:in `<main>'

Anyone have any suggestions regarding how to debug and fix this?

You have an encoding problem in your database.

The database claims is using one encoding, but some of the data is encoded some other way. A job I just did had a similar problem. UTF-8 likely does not exist when you started your forum.

This is probably a problem for stack exchange or a database person. It’s not a problem with the importer.

It’s the kind of problem that will take 10 minutes following a recipe that you don’t understand, ten hours looking for that recipe, or 100 hours fixing it by hand.

3 个赞

Cheers @pfaffman I was approaching the same conclusion… I started writing up the following before your comment…

It looks like it might be caused by non-ascii characters in usernames, so dumping the usernames into a text file and searching for UTF-8:

echo "select username from user" | mysql -p vb4 | grep --color='auto' -P -n "[^[:ascii:]]"

These were the entities this threw up:

’ ´ – é ã Ñ í ó 

So I used this page to generate encoded versions and updated the usernames in the database, for example:

UPDATE user SET username="&rsquo; &acute; &ndash; &eacute; &atilde; &Ntilde; &iacute; &oacute;" WHERE username="’ ´ – é ã Ñ í ó"

But the script still fails:

script/import_scripts/vbulletin.rb:137:in `strip': invalid byte sequence in UTF-8 (ArgumentError)
        from script/import_scripts/vbulletin.rb:137:in `block (2 levels) in import_users'
        from /var/www/discourse/script/import_scripts/base.rb:226:in `block in create_users'
        from /var/www/discourse/script/import_scripts/base.rb:225:in `each'
        from /var/www/discourse/script/import_scripts/base.rb:225:in `create_users'
        from script/import_scripts/vbulletin.rb:133:in `block in import_users'
        from /var/www/discourse/script/import_scripts/base.rb:784:in `block in batches'
        from /var/www/discourse/script/import_scripts/base.rb:783:in `loop'
        from /var/www/discourse/script/import_scripts/base.rb:783:in `batches'
        from script/import_scripts/vbulletin.rb:117:in `import_users'
        from script/import_scripts/vbulletin.rb:78:in `execute'
        from /var/www/discourse/script/import_scripts/base.rb:45:in `perform'
        from script/import_scripts/vbulletin.rb:902:in `<main>'

So I then dumped the whole users table into a text file:

echo "select * from user" | mysql -p vb4 > /tmp/allusers.txt

And then tried all the suggesting in this stackexchange thread for finding non-ascii characters and none were found, so now to search the whole database for the problem…

When I find a solution I’ll post it here in case it helps others…

2 个赞

The problem almost certainly exists in other tables.

You need to figure out what it’s encoded in and fix it.

Or, it could be that for some years it’s in one encoding and other years it’s another.

Best of luck. I was relieved they my client had engineers they solved the problem so I didn’t have to. I may have some notes that I’ll try to find when I get out of bed.

1 个赞

The database on the old server was UTF-8 but clearly it has some non-UTF-8 in it, the site has been in use for a long time and has 13k users… so taking care with dumping the old database:

mysqldump -uroot -p database -r dump.sql

And trying various methods to check the encoding (thanks to Stackexchange):

file dump.sql 
  dump.sql: ASCII text, with very long lines

apt install uchardet 
uchardet dump.sql
  UTF-8

iconv -f utf-8 -t utf-8 dump.sql > dump.utf-8.sql
  iconv: illegal input sequence at position 29618109

apt install moreutils
isutf8 dump.sql 
  dump.sql: line 2995, char 42, byte 29618109: Expecting bytes in the following ranges: 00..7F C2..F4.

And this is a image line:

INSERT INTO `customavatar` VALUES (6355,'ÿØÿà\0^PJFIF\0^A^A\0\0^A\0^A\0\0ÿþ\0;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 75

And before I delete the line using vim I need to increase the size of the partitions as it is a 1.4G file and I’m running out of space when editing it…

1 个赞

The problem was a user with &#55357;&#56444; in the username field, once the HTML entities were removed the import script ran, but there were a lot of errors like this:

ERR Error running script (call to f_b06356ba4628144e123b652c99605b873107c9be): @user_script:14: @user_script: 14: -MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error. 

Is this something that I should be concerned about and something that I should fix and then redo the import?

Are you out of disk space?

1 个赞

Yes! I’m now spinning up a new virtual server with a huge amount of disk space, CPUs and RAM and I’m going to start from scratch…

By the way, I’m following the instructions above for the Docker version and found that I needed to add an additional step in the container

echo "discourse ALL = NOPASSWD: ALL" >> /etc/sudoers

Before running:

su discourse -c 'bundle install --no-deployment --without test --without development'

In the non-docker instructions above there is this step to delete data from the database before doing the import:

  • Clear existing data from your local Discourse instance
cd ~/discourse
bundle exec rake db:drop db:create db:migrate

Was this omitted from the Docker instructions on purpose?

1 个赞

There are two, different, vbulletin import scripts, in the docker container:

cd /var/www/discourse
find ./ -name vbulletin.rb
./script/bulk_import/vbulletin.rb
./script/import_scripts/vbulletin.rb

The second one is twice the size of the first one and it is the one I have been using.