(Superseded) Come migrare / importare da SMF2 a Discourse

:mega: Questa documentazione è ora superata da questa guida SMF2: Migrate an SMF2 forum to Discourse

Volevo davvero migrare il nostro vecchio forum SMF2 su Discourse. Abbiamo oltre 1000 membri e circa 20.000 post in circa 2.000 argomenti.
Su SMF2 non abbiamo mai usato sondaggi né allegati — in realtà, non tutti avevano nemmeno un avatar. Alcuni post facevano molto affidamento su BBCode “avanzato”, però.

Ecco come abbiamo fatto.

Prerequisiti

Basta installare Discourse nel modo consueto.
Ho aggiunto il plugin Discourse BBCode per gestire liste, dimensioni, colori ecc. direttamente.

Se non riesci a stabilire una connessione remota al database MySQL di SMF2, dovrai importare i tuoi dati da un dump in un contenitore Docker temporaneo.

Se il tuo database accetta connessioni remote — o se è in esecuzione sullo stesso host, puoi saltare questo passaggio.

Un contenitore MySQL Docker temporaneo

Esegui il dump del tuo database:

cd /tmp/
mysqldump –u[nome utente] –p[password] [nome database] > sqldump.sql

Crea il contenitore MySQL Docker temporaneo:

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

Poi accedici:

docker exec -it mysql bash

Importa il dump del tuo database:

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

Se ricevi il seguente errore:

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

Aspetta solo un minuto affinchĂŠ il contenitore si avvii completamente.

Per la compatibilitĂ  del database, ho dovuto modificare il plugin di autenticazione del nostro database temporaneo, ma immagino che il tuo caso possa variare:

mysql -uuser -ppass db

Usa questa query:

ALTER USER user
IDENTIFIED WITH mysql_native_password
BY 'pass';

Poi esci e controlla l’indirizzo IP della tua istanza MySQL:

exit
docker inspect mysql | grep IPAddress

Ora hai una copia funzionante del tuo database SMF2.

Un contenitore di importazione Discourse temporaneo

Creiamo un nuovo contenitore chiamato “import”, basato sul contenitore app.yml predefinito:

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

nano containers/import.yml

Aggiungi il template mysql-dep al tuo nuovo contenitore di importazione:

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"
## Scommenta queste due righe se desideri aggiungere Lets Encrypt (https)
  #- "templates/web.ssl.template.yml"
  #- "templates/web.letsencrypt.ssl.template.yml"
  - "templates/import/mysql-dep.template.yml"

Poi semplicemente:

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

Importazione in Discourse

Una volta che il contenitore di importazione è stato ricostruito, dobbiamo accedervi per la nostra ultima modifica:

/var/discourse/launcher enter import
cd /var/www/discourse/ # lo script deve essere lanciato da questa directory esatta, ma dovresti esserci giĂ  finito comunque
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: hostname del database MySQL SMF2 (qui, l’IP di un contenitore Docker);
  • -u: utente MySQL SMF2;
  • -p: password MySQL SMF2;
  • -d: database MySQL SMF2;
  • -f: prefisso delle tabelle SMF2;
  • -t: fuso orario SMF2.

Pulizia

Se l’hai creato, ferma e rimuovi il contenitore MySQL Docker temporaneo:

docker stop mysql
docker rmi mysql

Ferma il contenitore Discourse “import” e usa il launcher per la pulizia:

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

In realtà sono riuscito a distruggere il mio contenitore principale :slight_smile: Non è un grosso problema:

/var/discourse/launcher rebuild app

Impostazioni Discourse dopo l’importazione

Alcune impostazioni predefinite potrebbero causare problemi con i post importati e i permessi. Modificale in base alle tue esigenze dal pannello delle impostazioni di Discourse:

  • lunghezza minima del titolo dell’argomento: l’ho impostata a 3 — gli argomenti con titoli troppo brevi si sono rivelati molto difficili da gestire (non potevano essere spostati, ecc.);
  • abbellimento del titolo: ho dovuto disattivarlo — gli argomenti il cui titolo non iniziava con una lettera maiuscola si sono rivelati molto difficili da gestire (non potevano essere spostati, ecc.).

Bibliografia

10 Mi Piace

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 Mi Piace

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 Mi Piace

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 Mi Piace

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 Mi Piace

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 Mi Piace

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 Mi Piace

No it should not override any of the site settings.

1 Mi Piace

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

Thank you for the guide.

I’m stuck right after you say:

For database compatibility, I had to change our temporary database authentification plugin, but I suppose your mileage may vary:

I get the error:

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)

I wonder if you could give me a clue as to how fix this please? Presumably it’s related to changing the ‘database authentication plugin’? If so, how do I do that please?

Thank you!

Next I tried importing the DB into a separate MySQL DB outside of Docker, etc. It’s running on localhost.

Now when I run the script I get this error at the same point as before:

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)

I have tried waiting for a period and re-running as per the guidance in the guide - but the same result always occurs unfortunately. Can anyone help me please?

Thank you

Here is a screenshot 2020-12-02_00-00-16.png - Google Drive