# 将 vBulletin 4 论坛迁移到 Discourse

**URL:** https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881
**Category:** Sysadmins
**Tags:** how-to
**Created:** [2016年十二月28日 14:59 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881 "2016-12-28T14:59:29Z")
**Posts on this page:** 20
**Page:** 3

<div class="post-metadata">

### Author: ![wishspinner](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wishspinner/32/139913_2.png) [@wishspinner](https://meta.discourse.org/u/wishspinner)
#### Post date: [2019年二月15日 23:21 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/47 "2019-02-15T23:21:02Z")

</div>

> [@pfaffman](#):
>
> I just did one 5M post import and am finishing up a 4M post import with 160GB of attachments. I made lots of edits to handle attachments not linked to in the post

I know this is a bit of an old topic, but I’ve just completed a comparably sized vb4 migration and am missing a LOT of image attachments, somewhere on the order of 75% of them I’d wager. They are not tombstoned, and all the threads have been rebaked.

Has anyone else dealt with this? How should I go about recovering those images?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2019年二月16日 00:53 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/48 "2019-02-16T00:53:44Z")

</div>

Did you see errors when you did the import?

---

<div class="post-metadata">

### Author: ![wishspinner](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wishspinner/32/139913_2.png) [@wishspinner](https://meta.discourse.org/u/wishspinner)
#### Post date: [2019年二月16日 01:01 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/49 "2019-02-16T01:01:48Z")

</div>

Yes, quite a few ‘Attachment file doesn’t exist’ errors with some ‘Couldn’t find attachment record for post.id=xxx, import\_id=xxx’ sprinkled in.

The thing that has me scratching my head is that these are posts that I know have intact attachments, and that those attachments are in the ATTACHMENT\_DIR global directory. The threads with missing images are missing ALL the associated images, which seems… not random.

I’m at a loss to find any common factor among the threads/posts with lost images either.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2019年二月16日 01:42 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/50 "2019-02-16T01:42:38Z")

</div>

Those messages were your clue that something was amiss. All you can do is diagnose the problem an run the import again.

Every import is a snowflake. I’ve don’t dozens of them. It’s rare that one just works. If you’d like help: [Redirecting…](https://www.literatecomputing.com/discourse-migration/)

---

<div class="post-metadata">

### Author: ![joedredd](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joedredd/32/153648_2.png) [@joedredd](https://meta.discourse.org/u/joedredd)
#### Post date: [2019年八月16日 14:45 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/51 "2019-08-16T14:45:25Z")

</div>

我想通过转换我们庞大的 VBulletin 数据库来尝试 Discourse，因此正在试用这个脚本。

它已成功导入用户和群组，但在导入子分类时已失败两次。

```
   正在导入顶级分类...
        7 / 7 (100.0%) [902 项/分钟] n]
正在导入子分类...
Traceback (most recent call last):
        5: from script/import_scripts/vbulletin.rb:942:in `<main>'
        4: from /home/peterb/discourse/script/import_scripts/base.rb:47:in `perform'
        3: from script/import_scripts/vbulletin.rb:84:in `execute'
        2: from script/import_scripts/vbulletin.rb:287:in `import_categories'
        1: from script/import_scripts/vbulletin.rb:287:in `each'
script/import_scripts/vbulletin.rb:289:in `block in import_categories': undefined method `[]' for nil:NilClass (NoMethodError)

```

我已检查过 UTF8 编码、服务器资源等各种因素，但现在不知还能检查什么。  
有什么建议吗？  
谢谢。

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2019年八月16日 16:01 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/52 "2019-08-16T16:01:58Z")

</div>

我目前正在运行一个 800 万条帖子的 vBulletin 导入。我已经添加了对点赞（似乎是某个插件或修改）和投票的支持。

从错误信息中我还无法完全确定问题所在。我猜是某种情况下找不到 `parentid`。

我认为你需要以某种方式修复这段代码：

```
    parent_category_id: category_id_from_imported_category_id(category["parentid"])

```

使其在 `category['parentid']` 为 nil 时也不会报错。

---

<div class="post-metadata">

### Author: ![joedredd](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joedredd/32/153648_2.png) [@joedredd](https://meta.discourse.org/u/joedredd)
#### Post date: [2019年八月20日 17:56 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/53 "2019-08-20T17:56:49Z")

</div>

谢谢。我再次查看后发现，管理员通过设置父级 ID 为 -1（该 ID 实际上不存在）来创建了“分类区块”。

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2019年八月20日 18:09 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/54 "2019-08-20T18:09:06Z")

</div>

没错。看来你已经搞定了。出现这类问题其实是常态而非例外。接下来你得决定是直接在数据库里修复，还是修改代码来适配这个有问题的数据库。

---

<div class="post-metadata">

### Author: ![joedredd](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joedredd/32/153648_2.png) [@joedredd](https://meta.discourse.org/u/joedredd)
#### Post date: [2019年八月20日 22:09 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/55 "2019-08-20T22:09:40Z")

</div>

任何数据迁移都是如此，无论你找到什么脚本，都无法涵盖所有突发情况。更糟糕的是，我唯一有空处理这件事的时间似乎总是在深夜（这是我为车友会免费做的）。vBulletin 网站经过了大量定制，所以我会看看还会出现什么其他意外情况。

---

<div class="post-metadata">

### Author: ![UnivacTwo](https://avatars.discourse-cdn.com/v4/letter/u/df705f/32.png) [@UnivacTwo](https://meta.discourse.org/u/UnivacTwo)
#### Post date: [2019年九月4日 12:18 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/56 "2019-09-04T12:18:28Z")

</div>

我理解有一个脚本可以处理 vBulletin 4 的导入，但我没看到任何关于将所有 URL 重定向到新 Discourse URL 格式的内容。

你们是如何处理这个问题的？你们论坛上的所有外部链接会发生什么变化？

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2019年九月4日 13:12 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/57 "2019-09-04T13:12:04Z")

</div>

> [@UnivacTwo](#):
>
> 我没有看到任何关于将所有 URL 重定向到新 Discourse URL 格式的内容

在这里：

> <https://github.com/discourse/discourse/blob/main/script/import_scripts/vbulletin.rb#L346-L359>

---

<div class="post-metadata">

### Author: ![UnivacTwo](https://avatars.discourse-cdn.com/v4/letter/u/df705f/32.png) [@UnivacTwo](https://meta.discourse.org/u/UnivacTwo)
#### Post date: [2019年九月4日 15:13 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/58 "2019-09-04T15:13:10Z")

</div>

谢谢 @RGJ，但你能解释一下这在现实中是如何工作的吗？这个脚本具体在做什么？它是否在 Discourse 中创建某种别名 URL，指向当前/正确的已导入 Discourse URL？

你建议如何将旧 Vbulletin 域名（[www.example1.com](http://www.example1.com)）迁移到新的 Discourse 域名（[www.example2.com](http://www.example2.com)）？

我认为，最理想的情况是旧论坛域名能够基于 301 重定向规则列表，将所有传入流量和链接重定向到新域名。你建议如何生成这样的重定向规则列表？

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2019年九月4日 15:31 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/59 "2019-09-04T15:31:06Z")

</div>

你_不必_更改域名，但如果你要更改，则需要分两步进行：

1. 将旧域名的所有内容重定向到新域名
2. Discourse 的永久链接会将 vBulletin 风格的 URL 转换为正确的 Discourse 主题。

如果你不更改域名，只是将其指向新的 Discourse 设置，那么你只需执行第 2 步。

---

<div class="post-metadata">

### Author: ![UnivacTwo](https://avatars.discourse-cdn.com/v4/letter/u/df705f/32.png) [@UnivacTwo](https://meta.discourse.org/u/UnivacTwo)
#### Post date: [2019年九月4日 16:30 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/60 "2019-09-04T16:30:41Z")

</div>

Discourse 的重定向 HTTP 头（301 或 302）表现如何？

从 SEO 的角度来看，我关心的是更换域名是否会影响排名。

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2019年九月4日 16:43 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/61 "2019-09-04T16:43:56Z")

</div>

`301 永久移动`

“永久链接”这个词已经说明了一切 🙂

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2019年九月4日 17:16 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/62 "2019-09-04T17:16:59Z")

</div>

如果您访问 `/admin/customize/permalinks` 并创建一个固定链接，即可亲自查看其工作原理。

---

<div class="post-metadata">

### Author: ![jsavage](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@jsavage](https://meta.discourse.org/u/jsavage)
#### Post date: [2019年九月8日 02:58 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/63 "2019-09-08T02:58:30Z")

</div>

我在附件未_完整_导入方面遇到了问题，与之前提到的情况类似，但脚本 **没有** 输出任何错误。  
数据库很小（71M），整个导入过程在 0 分 23 秒内完成。

 ![ss](https://global.discourse-cdn.com/meta/original/3X/5/0/502c928c7408f676f77e36b97e7ad92bab3eec20.png)  
大部分帖子中的附件都缺失了。  
我直接在 vb4 数据库中运行了脚本中的 SQL 查询，它们返回了正确的数据，因此目前我不确定问题出在哪里……

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2019年九月8日 04:08 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/64 "2019-09-08T04:08:29Z")

</div>

那些缺失的附件是否并未直接在帖子中链接？我认为脚本只会抓取帖子中提到的图片，而不是仅仅附加在帖子上的图片。

我有一个脚本可以导入这些内容，但尚未成功提交 PR。

---

<div class="post-metadata">

### Author: ![jsavage](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@jsavage](https://meta.discourse.org/u/jsavage)
#### Post date: [2019年九月8日 06:29 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/65 "2019-09-08T06:29:22Z")

</div>

是的，我觉得你说得对，@pfaffman，情况确实如此。  
等你上传那个脚本后，我会等着的！

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2019年九月8日 07:38 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/66 "2019-09-08T07:38:46Z")

</div>

如果你有预算，请告诉我。我打算在完成这次导入后提交一个版本，但我需要删除大量仅用于此次导入的代码，这就是为什么一年前没有完成的原因……

[上一頁](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881.md?page=2)

[下一頁](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881.md?page=4)
