(後継)SMF2からDiscourseへの移行/インポート方法

:mega: このドキュメントは、以下の別の SMF2 ガイドに置き換えられました: Migrate an SMF2 forum to Discourse

私たちは、愛着のある SMF2 フォーラムを Discourse に移行したくてなりませんでした。メンバーは 1000 人以上、トピックは約 2000 件、投稿数は約 2 万件あります。
SMF2 では、投票も添付ファイルも使っていませんでした——実際、アバターを持っている人さえも全員ではありませんでした。ただし、一部の投稿では「高度な」BBCode に大きく依存していました。

以下に、私たちがどのようにこれを成し遂げたかを示します。

前提条件

Discourse を いつもの方法 でインストールしてください。
リスト、サイズ、色などを最初から処理できるように、Discourse BBCode プラグイン を追加しました。

SMF2 の MySQL データベースにリモート接続できない場合は、ダンプからデータを一時 Docker コンテナにインポートする必要があります。

データベースがリモート接続を受け入れている場合、または同じホストで実行されている場合は、このステップをスキップできます。

一時 Docker MySQL コンテナ

データベースをダンプします:

cd /tmp/
mysqldump –u[ユーザー名] –p[パスワード] [データベース名] > sqldump.sql

一時 Docker MySQL コンテナを作成します:

cd /tmp/
docker run -d -e MYSQL_ROOT_PASSWORD=pass -e MYSQL_USER=user -e MYSQL_PASSWORD=pass -e MYSQL_DATABASE=db -v "$PWD":/backup --name=mysql mysql

次に、コンテナに入ります:

docker exec -it mysql bash

データベースダンプをインポートします:

mysql -uuser -ppass db < /backup/sqldump.sql

以下のエラーが表示された場合:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

コンテナが完全に起動するまで 1 分ほどお待ちください。

データベースの互換性のため、一時データベースの認証プラグインを変更する必要がありましたが、状況は異なる可能性があります:

mysql -uuser -ppass db

このクエリを使用します:

ALTER USER user
IDENTIFIED WITH mysql_native_password
BY 'pass';

その後、ログアウトして MySQL インスタンスの IP アドレスを確認します:

exit
docker inspect mysql | grep IPAddress

これで、SMF2 データベースの動作するコピーが完成しました。

一時 Discourse インポートコンテナ

デフォルトの app.yml コンテナをベースにして、「import」という名前の新しいコンテナを作成しましょう:

cd /var/discourse
cp containers/app.yml containers/import.yml

nano containers/import.yml

新しいインポートコンテナに mysql-dep テンプレートを追加します:

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"
## Lets Encrypt (https) を追加する場合は、この 2 行のコメントを外してください
  #- "templates/web.ssl.template.yml"
  #- "templates/web.letsencrypt.ssl.template.yml"
  - "templates/import/mysql-dep.template.yml"

次に、以下を実行します:

/var/discourse/launcher stop app
/var/discourse/launcher rebuild import

Discourse へのインポート

インポートコンテナが再構築されたら、最新の調整 のためにコンテナに入ります:

/var/discourse/launcher enter import
cd /var/www/discourse/ # スクリプトは正確にこのディレクトリから起動する必要がありますが、自動的にそこに移動しているはずです
su discourse -c "bundle exec ruby script/import_scripts/smf2.rb -h 172.17.0.3 -u user -p pass -d db -f smf_ -t Europe/Paris"
  • -h: SMF2 MySQL データベースのホスト名(ここでは Docker コンテナの IP)
  • -u: SMF2 MySQL ユーザー
  • -p: SMF2 MySQL パスワード
  • -d: SMF2 MySQL データベース
  • -f: SMF2 テーブルのプレフィックス
  • -t: SMF2 のタイムゾーン

クリーンアップ

作成した場合は、一時 MySQL Docker コンテナを停止して削除します:

docker stop mysql
docker rmi mysql

Discourse の「import」コンテナを停止し、launcher を使用してクリーンアップします:

/var/discourse/launcher destroy import
/var/discourse/launcher cleanup

実際、メインのコンテナを削除してしまいました :slight_smile: 問題ありません:

/var/discourse/launcher rebuild app

インポート後の Discourse 設定

デフォルトの設定により、インポートされた投稿や権限に問題が発生する可能性があります。Discourse の設定パネルから、必要に応じて以下を変更してください:

  • トピックタイトルの最小長さ: 3 に変更しました——タイトルが短すぎるトピックは操作が非常に困難でした(移動できないなど)。
  • タイトルの整形: 無効にしました——タイトルが大文字で始まらないトピックは操作が非常に困難でした(移動できないなど)。

参考文献

「いいね!」 10

Thanks for providing this. Maybe @marcozambi can use this for the guide he was planning to write after his successful import (including attachments)?

See here:

Also can anybody from the Discourse team let us know what happened to the old topic that was a guide for SMF2 imports? I can no longer find it via search.

「いいね!」 1

Still determined to contribute, as soon as all the details will be in place. I’m taking notes of everything and I’ll write someting asap

「いいね!」 1

poke @codinghorror @sam @HAWK

I think we can combine what @_vincent has compiled here, what was in the “missing” topic, and a few notes from @marcozambi’s migration to make a pretty comprehensive guide for migrating SMF2 to Discourse.

I have undeleted it here: https://meta.discourse.org/t/importer-for-simple-machines-2-forums/17656

I am assuming it was deleted because it contained info that is no longer up to date so grab what you need from it and we’ll remove it again to avoid future confusion.

「いいね!」 1

Thanks! For the most part it was up-to-date. I did a migration with it a couple months ago and I would have been lost as f*$# without it.

I think the guide isn’t the problem, so much as the importer itself could use a little attention in a few areas. Also, if possible, we should change some of the MySQL settings in the Discourse docker container when it gets created to prevent connection timeouts. That would probably take care of everything IMO.

「いいね!」 1

Ok, it’s out. SMF2 to Discourse - The Ultimate Guide
I hope the Guide is readable enough, as I am not a native english speaker. It goes without saying that any constructive feedback is more than welcome.

「いいね!」 3

Hello guys,

Let me start that you did a wonderful job with [SMF2 to Discourse - The Ultimate Guide] and this migration tool.

I could migrate a huge SMF instante (61k members, 400k posts, 350k, topics).
I did a dry run and everything worked as it should.

My question is: will this script override Discourse specific settings like the ones in /admin/site_settings/ ? - I’m asking this as I want to make a final migration of the content that came up in the meantime on the SMF site, but I would not want to overwrite the settings already configured in /admin/site_settings/.

Thank you

「いいね!」 1

No it should not override any of the site settings.

「いいね!」 1

Thank you so much.

I don’t have the expertise to “read” the script and what exactly it is copying over. I was hoping the same

ガイドをありがとうございます。

以下の箇所の直後でつまずいています:

データベースの互換性のため、一時的なデータベース認証プラグインを変更する必要がありました。ただし、環境によって状況は異なる可能性があります:

以下のようなエラーが表示されます:

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)

この問題を解決するためのヒントをいただけますでしょうか?おそらく「データベース認証プラグイン」の変更に関連しているのでしょうが、もしそうであれば、どのように変更すればよいのでしょうか?

よろしくお願いいたします!

次に、Docker 外部の別の MySQL データベースに DB をインポートしてみました。これは localhost で動作しています。

スクリプトを実行すると、以前と同じ箇所で以下のエラーが発生します。

from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in initialize' /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in connect’: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) (Mysql2::Error::ConnectionError)

ガイドに記載されている手順に従って、しばらく待ってから再度実行してみましたが、残念ながら同じ結果になります。どなたかお手伝いいただけませんでしょうか?

よろしくお願いいたします。

こちらがスクリーンショットです https://drive.google.com/file/d/1z8TLY4zBr0KzrL9aJDQTG4NKG5Dhbg11/view?usp=drivesdk