Migrar um fórum MyBB para Discourse

Neste tutorial, aprenderemos como migrar um fórum MyBB para a plataforma :discourse: usando o script oficial de importação do MyBB.

O que pode ser migrado

  • Categorias
    • Categoria raiz => categoria raiz
    • Categoria filha => subcategoria
    • Fórum raiz => subcategoria
    • Fórum filho => subcategoria
  • Tópicos e respostas => tópicos e posts
  • Usuários
    • nome de usuário
    • e-mail
    • status de privilégios
    • status de inscrição
  • Redirecionamentos

Nosso plano é muito simples:

  • Configurar o ambiente local de DEV.
  • Exportar o banco de dados de produção.
  • Importar o banco de dados de produção para o Discourse.
  • Executar o script de importação do MyBB.

Vamos começar :slightly_smiling_face:

Configurando o Ambiente Local de DEV

Primeiro de tudo, você precisa seguir um destes guias para instalar a própria plataforma Discourse. Consulte este guia se tiver algum problema.

Instale o servidor de banco de dados MySQL;

MacOS:

$ brew install mysql@5.7
$ echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile

Verifique o status do serviço:

$ brew services list

Você deve ver algo como isto:

mysql@5.7         started

Caso contrário, execute o seguinte e tente novamente:

$ brew services start mysql@5.7

Ubuntu 18.04:

$ sudo apt update
$ sudo apt install mysql-server -y

Após concluir a instalação do MySQL, verifique seu status:

$ systemctl status mysql.service

Se não estiver em execução, execute o seguinte:

$ sudo systemctl start mysql

Para o Windows, você pode seguir o guia de instalação oficial.

Vamos chamar este ambiente de: servidor Discourse.

Exportando o Banco de Dados de Produção

Exporte/backup o banco de dados de produção (do servidor de produção MyBB) executando:

$ mysqldump -u NOME_USUARIO -p NOME_BANCO_DADOS > mybb_dump.sql
  • Copie este dump do banco de dados para o servidor Discourse.

:bulb: Você pode usar scp ou rsync para copiar o banco de dados.

Importando o Banco de Dados de Produção para o Discourse

No servidor Discourse, crie um banco de dados:

$ mysql -u root

:bulb: Se seu usuário do BD tiver uma senha, você deve usar: mysql -u root -p e depois digitar sua senha.

mysql> CREATE DATABASE mybb;

Certifique-se de que o banco de dados foi criado com sucesso executando:

mysql> SHOW DATABASES;

Você deve ver algo como:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| mybb               |
| sys                |
+--------------------+

O BD mybb está vazio por enquanto. Nosso próximo passo é importar o banco de dados de produção para ele.

$ mysql -u root mybb < mybb_dump.sql

Mais tarde, precisaremos do prefixo da tabela. Então, enquanto estamos aqui, vamos obtê-lo.

$ mysql -u root
mysql> USE mybb;
mysql> SHOW TABLES;

Você verá algo como isto:

+--------------------------+
| Tables_in_mybb           |
+--------------------------+
| mybb_adminlog            |
| mybb_adminoptions        |
| mybb_adminsessions       |
| mybb_adminviews          |
| mybb_announcements       |
| mybb_attachments         |
| mybb_attachtypes         |
| ...O restante das tabelas....|
+--------------------------+

Nosso prefixo de tabela é mybb_, conforme mostra a saída.

Executando o Script de Importação do MyBB

  • Vamos primeiro instalar as dependências do importador. Do servidor Discourse:
$ cd ~/discourse
$ echo "gem 'mysql2', require: false" >> Gemfile
$ bundle install

Em seguida, você deve configurar o script para funcionar corretamente. Copie e cole o seguinte em seu shell (altere os valores se necessário):

export DB_HOST="localhost"
export DB_NAME="mybb"
export DB_PW=""
export DB_USER="root"
export TABLE_PREFIX="mybb_"

Você tem outra opção para configurar o script. Abra script/import_scripts/mybb.rb em qualquer editor de sua escolha e altere os valores dentro das aspas duplas para atender às suas necessidades:

  DB_HOST ||= ENV['DB_HOST'] || "localhost"
  DB_NAME ||= ENV['DB_NAME'] || "mybb"
  DB_PW ||= ENV['DB_PW'] || ""
  DB_USER ||= ENV['DB_USER'] || "root"
  TABLE_PREFIX ||= ENV['TABLE_PREFIX'] || "mybb_"

Execute o importador com uma instância limpa do Discourse:

$ bundle exec rails db:drop
$ bundle exec rails db:create
$ bundle exec rails db:migrate
$ bundle exec ruby script/import_scripts/mybb.rb

O importador se conectará ao servidor MySQL e migrará seu banco de dados MyBB para o banco de dados Discourse.

Após o término do importador, inicie a instância do Discourse executando:

$ bundle exec rails server

Em seguida, inicie o Sidekiq (processador de jobs em segundo plano) para processar os dados migrados:

$ bundle exec sidekiq

:bulb: Você pode monitorar o progresso do sidekiq em http://localhost:3000/sidekiq/queues.

Configure seu servidor de produção do Discourse seguindo este tutorial.

Faça um backup da plataforma Discourse (servidor Discourse local) e faça o upload para seu servidor de produção do Discourse seguindo este tutorial.

:tada:

Se você tiver alguma dúvida sobre o processo, ficarei feliz em ajudar.

Boa migração :grinning:

9 curtidas

Hi - this looks like a great guide, except as a Cpanel rather than linux user, migrating from a shared host, I don’t have root access or ssh access to the original host, but I do have access to PhPMyAdmin in Cpanel from which I can export the Mybb database.
Will this do?
What if any special export settings are required? And into what directory on my Digital Ocean droplet should this database be copied? (I am using FileZilla)

Yes.

It does not matter, home directory works just fine.

3 curtidas

Hi again - I can get up to this point in the tutorial

bundle install

and for me this falls over with error

'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.

Any suggestions?

Unfortunately I know nothing about ruby or linux or gemfiles and so am just literally plodding though various discourse cli setup tasks as the tutorials instruct by cutting and pasting commands via PuTTy, without any kind of understanding.

I am running Ubuntu and Discourse in a Digital Oceans Droplet, if that helps?

Also, I see a subsequent reference to pasting database export commands into ‘shell’ . For practical purposes is my current PuTTy connection to the server = ‘shell’, or is some other interface/console involved?

OK, in partial answer to my own question, random thrashing around on forums suggests

$ sudo apt-get install libmysqlclient-dev

will then allow mysql2 gem to install (whatever that is) - ignoring the warning about not doing this as root.

Getting past that and to the next step - typing

$ bundle exec rails db:drop

gives another error::::

bundler: failed to load command: rails (/usr/local/bin/rails)
Gem::Exception: can’t find executable rails for gem railties. railties is not currently included in the bundle, perhaps you meant to add it to your Gemfile?

Checking in /usr/local/bin/ and I can see a file named ‘rails’ is definitely there.

Typing $ sudo gem or $ gem install rails or $ sudo gem install rails does not help (per various suggestions stumbled across for this error).

Have even gone back and installed Ruby on Rails from scratch to try and ensure all normal dependencies are present How To Install Ruby on Rails with rbenv on Ubuntu 18.04 | DigitalOcean -and no improvement - whether I use version 2.51 or 2.61.

Well out of my depth here…

Well I can say categorically that following this guide as written does NOT work for anyone following the official steps for setting up local Dev environment under WSL2 installation of Ubuntu-18.04 under Windows 10 - at almost every step there will be some dependency missing or connection refused error or similar.

With a lot of pain and online research, I have managed to get up to the command:

$ bundle exec ruby script/import_scripts/mybb.rb

but this generates response:

mysql2/client.rb:90:in `connect’: Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2) (Mysql2::Error::ConnectionError)

This has been a brick wall - nothing I have found by searching online seems to offers a working solution to this

How do I solve this and progress to the next step? Any help much appreciated!

1 curtida

Hi, how can I upload database on my DigitalOcean droplet? I used installation 1click of DigitalOcean to install Discourse (Ubuntu).
On my PC I have Windows 10 Home 18362 build version.

Then I have installed Mysql but now I don’t know how “physically” upload Mybb database on the server. Isn’t there phpmyadmin where you can easily import the database? :frowning:

1 curtida

You need to upload the file using scp or similar. Then Something like

  mysql - u user - p password database < filename..sql
3 curtidas

I’m stuck :frowning:

1 curtida

This guide should be updated to be compatible with running the import inside a Docker install instead of using a local development machine.

5 curtidas

Really looking forward for the guide to run on a docker based environment :slight_smile:

2 curtidas

I gave up on DIY in the end and got a developer on the job - referring him to all the great suggestions on this forum (which helped!) - and I believe he achieved this directly on my live Digital Ocean droplet rather than in a separate development environment (so I could review things easily as he worked - users were not impacted as forum not officially live yet.) - in other words I think it is possible.

After a few iterations, results are now pretty good - all the MyCode and strange character issues resolved, translated my MyBB post prefixes as Discourse tags, custom multi-select user profile fields imported successfully.

If he is willing, I will ask him to share any tweaks to standard import script, and other techniques used here.

4 curtidas

In case it helps anyone, the developer @rahilqf I engaged completed the project including translation of custom MyBB user fields into Discourse custom user fields (which depends on having the multi-select-user-field plugin installed), MyBB post prefixes translated into Discourse tags, and stripping out of nearly all redundant MyCode tags from MyBB post text.

His customized import script version is shared here - Custom MyBB to Discourse Import Script.

He also successfully merged in a Yahoo Groups Mbox archive, using the standard Yahoo import script - though with this attachments seemed not to translate. In my case that was not a major problem.

3 curtidas

I’m converting users, post, topics etc from Mybb database!

I have followed this guide: Beginners Guide to Install Discourse on Ubuntu for Development

but http://localhost:3000/ or http://forum.omaggieconcorsi.com:3000/ don’t work

Anyway, the program is converting something, but I don’t know where I can then export the data.
Discourse I can’t see it with http://forum.omaggieconcorsi.com:3000/ or http://localhost:3000/ so how can I at least export the database with posts, users etc. from the old Mybb forum and then import it on new Discourse instance?

Thanks!

Did you follow those instructions on the same computer where you’re running the web browser?

1 curtida

Yes, always the same computer

Ok, I have followed this guide on Ubuntu 18.04 “real” SO installed on PC and localhost:3000 works!

But now I have problem with database Mysql :frowning: Sorry…

I type:

debby@debby-MS-7721: mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

:frowning:

EDIT: I have added password to root with ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

And in DB_PW I have written the password of root user.

… and now it’s creating users!!

Cross your fingers for me, is it finally the right time after weeks of testing??

1 curtida

I’m trying to import the database from MyBB to discourse. Like @Paul_King I can’t get it to work on my DigitalOcean server. I keep getting all kinds of errors as I follow this guide.

I’m stuck trying to execute the command

$ bundle exec rails db:drop
bundler: command not found: rails
Install missing gem executables with `bundle install`

Bundle install says it’s complete

$ bundle install
Your Gemfile lists the gem mysql2 (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of one of them later.
Using bundler 1.16.1
Using mysql2 0.4.10
Bundle complete! 2 Gemfile dependencies, 2 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

Trying to manually install rails results in this:

$ gem install rails
Building native extensions. This could take a while...
ERROR:  Error installing rails:
        ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.5.0/gems/racc-1.5.2/ext/racc/cparse
/usr/bin/ruby2.5 -r ./siteconf20210110-8155-1ms05r3.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.5.0/gems/racc-1.5.2 for inspection.
Results logged to /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/racc-1.5.2/gem_make.out

This is extremely frustrating.


Left this post open and managed to install rails. Then had a million other errors and managed to fix them. Errors. On. Every. Single. Step.

Never before I have felt such pure hatred for software. Why is ruby like this? This is a nightmare. I’m now stuck with this error:

$ bundle exec rails db:drop
Traceback (most recent call last):
        1: from /usr/local/bin/bundle:23:in `<main>'
/usr/local/bin/bundle:23:in `load': cannot load such file -- /usr/share/rubygems-integration/all/gems/bundler-1.16.1/exe/bundle (LoadError)

Can someone help?

1 curtida

Not useful, but I encountered much the same brick walls, both when attempting to set up in a local development environment (to generate a Discourse database file/backup) and directly in my Digital Ocean Droplet. Finally decided after wasting tens of hours that life is too short and got a developer from Fiverr (who took weeks to figure it out, but got there).
I suspect the incentives just aren’t there for anyone to make the process easier.

Best of luck - and I hope if you finally do crack it, you will leave a trail of breadcrumbs on here for others to follow!

1 curtida

Como você instalou o Rails? Você seguiu um dos guias de desenvolvimento? (como o Guia para Iniciantes para Instalar o Discourse no Ubuntu para Desenvolvimento)

Existem alguns documentos de passo a passo para executar o script de instalação dentro do container de produção (o que eu geralmente faço), então você pode usar um deles como guia.