将 XenForo 论坛迁移到 Discourse

Hey guys so after trying for a week or so I decided to import the database on docker app which I hoped it will succeed without any issues. TBH I got some issues at first but it turned to be all easy to solve.

Now I would recommend doing this only once before you deploy your production site, after importing everything take a Discourse backup, wipe everything out and install new Discourse instance then restore the imported db.

Ok let’s begin:

  1. First lets backup your old database from your old server, sign in to your Discourse server then:

     ssh USER@XENFORO_SERVER_IP  # Use -p argument to specify custom port
     mysqldump -u XENFORO_DATABASE_USER -p XENFORO_DATABASE_NAME > xen_db.sql
     exit
    
  2. After installing Discourse start the app:

     ./launcher start app
    
  3. Now lets pull the database backup from xenforo server:

     scp USER@XENFORO_SERVER_IP:~/xen_db.sql /var/discourse/shared/standalone/xen_db.sql
    

    If you changed the ssh port use -P argument

     scp -P 2222 USER@XENFORO_SERVER_IP:~/xen_db.sql /var/discourse/shared/standalone/xen_db.sql 
    
  4. Login to docker machine, install and start mysql:

     docker exec -it app bash
     sudo apt-get update
     sudo apt-get upgrade
    

    During the installation you will be asked to set a root password for mysql

     sudo apt-get install mysql-server mysql-client libmysqlclient-dev
     service mysql start
    
  5. Login to mysql and create new database:

     mysql -u root -p
    

    Enter your mysql root password then

     create database xenforo_db;
     exit;
    
  6. Import your xenforo database into the new one:

     mysql -u root -p xenforo_db < /shared/xen_db.sql
     # Enter your mysql root password and wait until it finish
    
  7. Include the gem in discourse Gemfile:

     echo "gem 'mysql2'" >>Gemfile
    
  8. Run bundle install:

     bundle install --no-deployment
    
  9. Edit the importer script and change the following:

    vi /var/www/discourse/script/import_scripts/xenforo.rb
    XENFORO_DB = "xenforo_db"
    @client = Mysql2::Client.new(
      host: "localhost",
      username: "root",
      password: "Your mysql root password",
      database: XENFORO_DB
    )
    
  10. You are set to go now, run the importer:

    RAILS_ENV=production bundle exec ruby script/import_scripts/xenforo.rb

  11. If you get the error 'Peer authentication failed for user "discourse"':

  12. Edit the file /etc/postgresql/9.5/main/pg_hba.conf

  13. change all ‘peer’ to ‘trust’ and save the file

  14. restart postgres server: service postgresql restart

Run the importer again and this time it should work without any problem, be patient this might take a while based on your database size.

Hope this helps someone. :slight_smile:

24 个赞

What are the list of XenForo Data covered on this import?
I hope to import this list:

XenForo Page Nodes

  • Pages

XenForo

  • Profile Fields
  • Member Groups
  • Members
  • Status Updates / Profile Comments
  • Status Comments
  • Private Messages
  • Private Message Replies
  • Attachments
  • Member Ranks

XenForo Forums

  • Forums
  • Topics
  • Posts
  • Attachments
1 个赞

Got this error:

# bundle install --no-deployment
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.
Your Gemfile has no gem server sources. If you need gems that are not already on your machine, add a line like this to your Gemfile:
source 'https://rubygems.org'
Could not find gem 'mysql2' in any of the gem sources listed in your Gemfile.
1 个赞

Different Error now.

root@discourse-app:/var/www/discourse# RAILS_ENV=production bundle exec ruby script/import_scripts/xenforo.rb
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
Traceback (most recent call last):
	31: from script/import_scripts/xenforo.rb:3:in `<main>'
	30: from script/import_scripts/xenforo.rb:3:in `require'
	29: from /var/www/discourse/script/import_scripts/base.rb:20:in `<top (required)>'
	28: from /var/www/discourse/script/import_scripts/base.rb:544:in `<class:Base>'
	27: from /var/www/discourse/lib/discourse.rb:411:in `system_user'
	26: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/core.rb:196:in `find_by'
	25: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/core.rb:196:in `all?'
	24: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/core.rb:196:in `each'
	23: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/core.rb:196:in `block in find_by'
	22: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/model_schema.rb:336:in `columns_hash'
	21: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/model_schema.rb:456:in `load_schema'
	20: from /usr/local/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
	19: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/model_schema.rb:459:in `block in load_schema'
	18: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/attribute_decorators.rb:51:in `load_schema!'
	17: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/attributes.rb:234:in `load_schema!'
	16: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/model_schema.rb:466:in `load_schema!'
	15: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_handling.rb:90:in `connection'
	14: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
	13: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:1008:in `retrieve_connection'
	12: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:380:in `connection'
	11: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:521:in `checkout'
	10: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:793:in `acquire_connection'
	 9: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:832:in `try_to_checkout_new_connection'
	 8: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in `checkout_new_connection'
	 7: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:809:in `new_connection'
	 6: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:40:in `postgresql_connection'
	 5: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:40:in `new'
	 4: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:215:in `initialize'
	 3: from /usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:684:in `connect'
	 2: from /usr/local/lib/ruby/gems/2.5.0/gems/pg-1.0.0/lib/pg.rb:56:in `connect'
	 1: from /usr/local/lib/ruby/gems/2.5.0/gems/pg-1.0.0/lib/pg.rb:56:in `new'
/usr/local/lib/ruby/gems/2.5.0/gems/pg-1.0.0/lib/pg.rb:56:in `initialize': FATAL:  Peer authentication failed for user "discourse" (PG::ConnectionBad)
1 个赞

Yay no idea how long this will take :smiley:

3 个赞

This is correct right?

1 个赞

Guide needs an update I think.
Before running this, directory must be within /var/www/discourse/.
cd /var/www/discourse/

4 个赞

3 个帖子被拆分为新主题:XenForo 导入脚本导入了被禁止的用户以及软删除的主题和帖子

8 posts were split to a new topic: Help migrating Xenforo

14 篇帖子已拆分到一个新主题:从 XenForo 导入附件时出现问题

5 个帖子被拆分到一个新主题:迁移 XenForo 到 Discourse 时遇到问题

一个帖子已合并到一个现有主题:迁移 XenForo 到 Discourse 时遇到问题

想问问大家,你们为什么从 XenForo 迁移到 Discourse?我刚运营论坛一周,看到一些使用 XenForo 的网站,对其功能(包括积分系统)印象深刻。我只是想了解迁移的缺点或原因。谢谢!

刚刚完成了一个拥有百万帖子的 Xenforo 到 Discourse 的迁移,运行在 Digital Ocean 的 Droplet 上。以下是我按步骤操作的成功命令(与之前在另一个 vBulletin 论坛上所做的操作非常相似)。

建议导入时至少使用 4 核 vCPU 和 8GB 内存。

感谢本线程中的每一位帮助我完成这些迁移的人,这几天反复阅读和重读确实是一段有趣的经历。

1 - 安装 Digital Ocean Discourse 一键式 Droplet

2 - 通过 SSH 按照提示完成 Discourse 安装

打开 SSH 控制台
root
(你的 root 密码)
(回车)
(你的域名).com
等等

3 - 登录 SFTP

sftp root@XXX.XXX.XX.XX
y(如果被要求确认)
yes
(你的 root 密码)
put db.sql /var/discourse/shared/standalone/db.sql

4 - 登录网站以设置管理员账户

5 - 登录 SSH - 开始流程

ssh root@XXX.XXX.XX.XX
cd /var/discourse
./launcher start app
docker exec -it app bash
sudo apt-get update
sudo apt-get upgrade
y

6 - 安装 MariaDB(作为 MySQL 的替代品)

apt-get update && apt-get install mariadb-server-10.3 libmariadbd-dev
y

7 - MySQL 数据库设置

service mysql start
mysql -u root -p
密码
create database import_db;
exit;

8 - 导入转储文件到 MySQL 数据库**

mysql -u root -p import_db < /shared/db.sql
密码

9 - GEM 文件

echo "gem 'mysql2'" >> Gemfile
echo "gem 'mysql2', require: false" >> /var/www/discourse/Gemfile
echo "gem 'php_serialize', require: false" >> /var/www/discourse/Gemfile
cd /var/www/discourse
su discourse -c 'bundle install --no-deployment --without test --without development --path vendor/bundle'
(忽略红色的文本结果)

10 - 配置安装脚本

vi /var/www/discourse/script/import_scripts/xenforo.rb

---根据需要对文本文件进行编辑,如数据库名称/密码、前缀等---

(esc)
:wq

11 - Bundle 配置

bundle config set path 'vendor/bundle'
bundle config set without 'development:test'
bundle config unset deployment
su discourse -c 'bundle install'

12 - MySQL 配置(可能可以与上一步合并完成)

mysql --version
sudo mysql -u root -p
密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
exit

13 - 运行安装脚本

su discourse -c 'bundle exec ruby script/import_scripts/xenforo.rb'
4 个赞

我正在尝试完成此迁移,但似乎附件部分出现了错误。

RAILS_ENV=production bundle exec ruby script/import_scripts/xenforo.rb
正在加载现有群组...
正在加载现有用户...
正在加载现有分类...
正在加载现有帖子...
正在加载现有主题...

创建用户
跳过 407 个已导入的用户

正在导入分类...
       12 / 12 (100.0%)  [344731 项/分钟]
正在创建主题和帖子
        2 / 4554 (  0.0%)  [17724 项/分钟]  回溯(最近一次调用最后):
        18: from script/import_scripts/xenforo.rb:396:in `\u003cmain\u003e'
        17: from /var/www/discourse/script/import_scripts/base.rb:47:in `perform'
        16: from script/import_scripts/xenforo.rb:32:in `execute'
        15: from script/import_scripts/xenforo.rb:174:in `import_posts'
        14: from /var/www/discourse/script/import_scripts/base.rb:866:in `batches'
        13: from /var/www/discourse/script/import_scripts/base.rb:866:in `loop'
        12: from /var/www/discourse/script/import_scripts/base.rb:867:in `block in batches'
        11: from script/import_scripts/xenforo.rb:180:in `block in import_posts'
        10: from /var/www/discourse/script/import_scripts/base.rb:508:in `create_posts'
         9: from /var/www/discourse/script/import_scripts/base.rb:508:in `each'
         8: from /var/www/discourse/script/import_scripts/base.rb:509:in `block in create_posts'
         7: from script/import_scripts/xenforo.rb:186:in `block (2 levels) in import_posts'
         6: from script/import_scripts/xenforo.rb:315:in `process_xenforo_post'
         5: from script/import_scripts/xenforo.rb:324:in `process_xf_attachments'
         4: from /usr/local/lib/ruby/2.7.0/set.rb:328:in `each'
         3: from /usr/local/lib/ruby/2.7.0/set.rb:328:in `each_key'
         2: from script/import_scripts/xenforo.rb:326:in `block in process_xf_attachments'
         1: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.3/lib/active_support/core_ext/string/filters.rb:22:in `squish!'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.3/lib/active_support/core_ext/string/filters.rb:22:in `gsub!': 无法修改冻结的字符串: \"\\\\t\\\\tSELECT a.attachment_id, a.data_id, d.fil\\n\\\\t\\\\tFROM xf_attachment AS a\\\\n\\\\t\\\\tINNER JOIN xf_attachment_data d ON a.data_id = d.data_id\\\\n\\\\t\\\\tWHERE attachment_id = 13\\\\n\" (FrozenError)

有人知道这里可能出了什么问题吗?什么是“FrozenError”?

看起来我需要编辑 xenforo.rb 文件,并将

# frozen_string_literal: true

更改为

# frozen_string_literal: false

2 个赞

感谢撰写这份指南!

导入器是否也会导入头像和附件?我只需将它们复制到 /tmp/attachments 文件夹即可吗?

快速查看导入器后发现,它仅支持将上传内容导入到帖子中。若要支持头像,还需额外添加相关功能。

2 个赞

可以确认,它仅导入上传的文件,不包含头像。我上周刚完成了一次 XenForo 迁移。

3 个赞

板子规模如何?
帖子/主题/成员数。
恭喜 :slight_smile:

2 个赞