使用需要MySQL的导入脚本

With the latest update ver 2.0.0 beta10 I’m now getting more errors with the bbpress import script (still can’t figure out why images are not being pulled over, but instead referring to their old URLs). Error after the importing topics and posts:

importing private messages...
      120 / 120 (100.0%)  [156526 items/min]  /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/mysql2-0.5.1/lib/mysql2/client.rb:131:in `_query': Table 'db.wp_bp_messages_messages' doesn't exist (Mysql2::Error)
	from /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/mysql2-0.5.1/lib/mysql2/client.rb:131:in `block in query'
	from /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/mysql2-0.5.1/lib/mysql2/client.rb:130:in `handle_interrupt'
	from /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/mysql2-0.5.1/lib/mysql2/client.rb:130:in `query'
	from /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/rack-mini-profiler-1.0.0/lib/patches/db/mysql2.rb:22:in `query'
	from script/import_scripts/bbpress.rb:505:in `bbpress_query'
	from script/import_scripts/bbpress.rb:453:in `block in import_private_messages'
	from /var/www/discourse/script/import_scripts/base.rb:870:in `block in batches'
	from /var/www/discourse/script/import_scripts/base.rb:869:in `loop'
	from /var/www/discourse/script/import_scripts/base.rb:869:in `batches'
	from script/import_scripts/bbpress.rb:452:in `import_private_messages'
	from script/import_scripts/bbpress.rb:32:in `execute'
	from /var/www/discourse/script/import_scripts/base.rb:46:in `perform'
	from script/import_scripts/bbpress.rb:510:in `<main>'
1 个赞

EDIT: After deeper inspection I found that (at least in my setup) the file was called

  - "templates/import/mysql-dep.template.yml"

NOTE that the correct spelling is “dep”, not “dev”.

=================

Hello! Thanks for posting this. I tried but got this error:

cat: templates/import/mysql-dev.template.yml: No such file or directory

I unfortunately don’t know enough about Docker to proceed…What am I doing wrong? Thank you so much. Here is the full output:

root@forum /var/discourse # ./launcher rebuild import
Ensuring launcher is up to date
Fetching origin
remote: Counting objects: 16, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 16 (delta 12), reused 7 (delta 6), pack-reused 0
Unpacking objects: 100% (16/16), done.
From https://github.com/discourse/discourse_docker
   2ad56e6..d032356  master     -> origin/master
Updating Launcher
Updating 2ad56e6..d032356
Fast-forward
 discourse-setup       | 2 +-
 image/base/Dockerfile | 5 +++--
 launcher              | 4 ++--
 3 files changed, 6 insertions(+), 5 deletions(-)
Ensuring launcher is up to date
Fetching origin
Launcher is up-to-date
cat: templates/import/mysql-dev.template.yml: No such file or directory
cd /pups && git pull && /pups/bin/pups --stdin
/usr/bin/docker: invalid reference format: repository name must be lowercase.
See '/usr/bin/docker run --help'.
cat: cids/import_bootstrap.cid: No such file or directory
"docker rm" requires at least 1 argument.
See 'docker rm --help'.

Usage:  docker rm [OPTIONS] CONTAINER [CONTAINER...]

Remove one or more containers
rm: cannot remove 'cids/import_bootstrap.cid': No such file or directory
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one
root@forum /var/discourse #support
1 个赞

did you get it resolved? Im too having this error

No. we just manually re-uploaded all of the images.

So I found out the reason for the issue we were having. The import script is breaking when it is trying to get wp_bb_message_message table, that’s happening because you would not have BuddyPress private messages module (which create these table) installed in your WordPress.

I did manage to pass that error by removing the code in bbpress.rb from line 414 to 502
This

 def import_private_messages
puts "", "importing private messages..."
last_post_id = -1
total_posts = bbpress_query("SELECT COUNT(*) count FROM #{BB_PRESS_PREFIX}bp_messages_messages").first["count"]

threads = {}

total_count = bbpress_query("SELECT COUNT(*) count FROM #{BB_PRESS_PREFIX}bp_messages_recipients").first["count"]
current_count = 0

batches(BATCH_SIZE) do |offset|
  rows = bbpress_query(<<-SQL
    SELECT thread_id, user_id
      FROM #{BB_PRESS_PREFIX}bp_messages_recipients
  ORDER BY id
     LIMIT #{BATCH_SIZE}
    OFFSET #{offset}
  SQL
  ).to_a

  break if rows.empty?

  rows.each do |row|
    current_count += 1
    print_status(current_count, total_count, get_start_time('private_messages'))

    threads[row['thread_id']] ||= {
      target_user_ids: [],
      imported_topic_id: nil
    }
    user_id = user_id_from_imported_user_id(row['user_id'])
    if user_id && !threads[row['thread_id']][:target_user_ids].include?(user_id)
      threads[row['thread_id']][:target_user_ids] << user_id
    end
  end
end

batches(BATCH_SIZE) do |offset|
  posts =  bbpress_query(<<-SQL
    SELECT id,
           thread_id,
           date_sent,
           sender_id,
           subject,
           message
      FROM wp_bp_messages_messages
     WHERE id > #{last_post_id}
  ORDER BY thread_id, date_sent
     LIMIT #{BATCH_SIZE}
  SQL
  ).to_a

  break if posts.empty?

  last_post_id = posts[-1]["id"].to_i

  create_posts(posts, total: total_posts, offset: offset) do |post|
    if tcf = TopicCustomField.where(name: 'bb_thread_id', value: post['thread_id']).first
      {
        id: "pm#{post['id']}",
        topic_id: threads[post['thread_id']][:imported_topic_id],
        user_id: user_id_from_imported_user_id(post['sender_id']) || find_user_by_import_id(post['sender_id'])&.id || -1,
        raw: post['message'],
        created_at: post['date_sent'],
      }
    else
      # First post of the thread
      {
        id: "pm#{post['id']}",
        archetype: Archetype.private_message,
        user_id: user_id_from_imported_user_id(post['sender_id']) || find_user_by_import_id(post['sender_id'])&.id || -1,
        title: post['subject'],
        raw: post['message'],
        created_at: post['date_sent'],
        target_usernames: User.where(id: threads[post['thread_id']][:target_user_ids]).pluck(:username),
        post_create_action: proc do |new_post|
          if topic = new_post.topic
            threads[post['thread_id']][:imported_topic_id] = topic.id
            TopicCustomField.create(topic_id: topic.id, name: 'bb_thread_id', value: post['thread_id'])
          else
            puts "Error in post_create_action! Can't find topic!"
          end
        end
      }
    end
  end
end
end

You can also get past it by simply installing buddypress and enabling its private message module.

2 个赞

Thanks for your helpful tutorial , worked fine for me !

Cheers

Sam

你好,
感谢分享这篇教程 :slight_smile:
附件也会一并导入吗?

看起来是这样。附件目录有一个配置项。

1 个赞

你好,
抱歉,请问如何生成 yourbackup.sql 文件?该文件应包含什么内容?是 bbPress 数据库的导出文件吗?

谢谢
++ .

没错。如何获取它取决于你拥有哪些工具以及你熟悉如何使用它们。

bbPress 安装非常标准,使用 WordPress 数据库,所有内容都存储在 wp_posts 表中。因此,我只需要导出 WordPress 的 posts 数据库吗?
抱歉打扰,但我没找到其他说明。

谢谢

您可以导出整个 WordPress 数据库,也可以查看代码以了解实际使用了哪些表。导出整个数据库更为简单。至于使用 mysqldump、cPanel、phpMyAdmin 还是其他工具,则难以给出具体推荐。

它起作用了(经过几次调整后):slight_smile: :slight_smile: 谢谢;)
succeed

1 个赞

我在导入时遇到 MySQL 数据库连接错误。SQL 数据库位于 localhost。如何绕过此错误?

/var/www/discourse# su discourse -c “bundle exec ruby script/import_scripts/bbpress.rb”

/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `connect’: 无法通过套接字 ‘/var/run/mysqld/mysqld.sock’ 连接到本地 MySQL 服务器 (2) (Mysql2::Error::ConnectionError)

谢谢。

如果 MySQL 服务器在服务器上运行而不是在容器中,请尝试使用主机 IP 地址。

MySQL 正在运行于一个容器中,而 Discourse 也运行在同一容器环境中。看起来来自 Discourse 容器的导入脚本无法连接到 MySQL 容器。除此之外,我还能做些什么?

您确定吗?能否在容器内部使用 mysql 命令行工具连接到它?

1 个赞

我已经解决了那个问题。我之前使用的是 localhost,后来我意识到 MySQL 的 IP 地址应该从以下命令获取:

下一个问题是导入脚本…

/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `connect’: Plugin caching_sha2_password could not be loaded: /usr/lib/x86_64-linux-gnu/mariadb19/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory (Mysql2::Error::ConnectionError)

我已经使用 ALTER 命令修改了密码。

上述问题的解决方案:再次运行以下命令。

ALTER USER 'root' IDENTIFIED WITH mysql_native_password BY 'newpassword';
1 个赞

在尝试使用上述发布的各种修复方案解决导入器运行问题后,我并没有看到任何帖子被成功导入。对于为什么会出现“与新数据库连接成功但没有任何帖子导入”的情况,大家有什么想法吗?

我试图将一个非 bbPress 的 WordPress(5.7)站点上的几百篇帖子导入到一个已经运行中的 Discourse 站点(2.7.0-beta5),该站点已有几百篇帖子。

已导入的数据库似乎存在:

mysql> show tables;
…
| wp_commentmeta        |
| wp_comments           |
| wp_links              |
| wp_options            |
| wp_postmeta           |
| wp_posts              |
| wp_term_relationships |
| wp_term_taxonomy      |
| wp_termmeta           |
| wp_terms              |
| wp_usermeta           |
| wp_users              |
…
运行导入器时的输出:
/var/www/discourse# su discourse -c "bundle exec ruby script/import_scripts/bbpress.rb"
正在加载现有群组...
正在加载现有用户...
正在加载现有分类...
正在加载现有帖子...
正在加载现有主题...

正在导入用户...

正在导入匿名用户...

正在导入分类...

正在导入主题和帖子...

正在从'postmeta'导入附件...

正在创建永久链接...


正在更新主题状态

正在更新主题的 bumped_at 字段

正在更新用户的 last posted at 字段

正在更新用户的 last seen at 字段

正在更新 first_post_created_at...

正在更新用户的 post_count...

正在更新用户的 topic_count...

正在更新用户的 digest_attempted_at...

正在更新主题用户

正在更新帖子计时

正在更新特色主题用户

正在更新分类中的特色主题
        6 / 6 (100.0%)  [1771 项/分钟]  ]  
正在重置主题计数器


完成 (00 小时 00 分 00 秒)