Ein vBulletin-4-Forum zu Discourse migrieren

Dieser Leitfaden behandelt die Migration eines vBulletin-4-Forums zu Discourse mit dem Importskript unter script/import_scripts/vbulletin.rb.

:warning: Erwarte, das Skript anzupassen. Jede vBulletin-Installation hat ihre eigenen Plugins, benutzerdefinierten Felder und BBCode-Eigenheiten. Die meisten echten Importe erfordern kleine Änderungen am Skript. Führen Sie vor der Arbeit in der Produktionsumgebung einen vollständigen Testimport auf einer Entwicklungsmaschine durch.

Welchen Importer sollte ich verwenden?

Forum Skript
vBulletin 4 script/import_scripts/vbulletin.rb (dieser Leitfaden)
vBulletin 3 script/import_scripts/vbulletin3.rb (gleiche Schritte, anderer Skriptname)
vBulletin 5 script/import_scripts/vbulletin5.rb
Sehr große Foren (Millionen von Beiträgen) script/bulk_import/vbulletin.rb (viel schneller, aber mit weniger Funktionen und schwerer anzupassen)

Was wird importiert

  • Gruppen
  • Benutzer (gesperrte Benutzer werden zu pausierten Benutzern)
  • Foren: Jedes Eltern- und Kindforum wird zu einer Kategorie und Unterkategorie
  • Themen
  • Angepinnte Threads → angepinnte Themen
  • Geschlossene Threads → geschlossene Themen
  • Weich gelöschte oder moderierte Threads → nicht gelistete Themen
  • Beiträge
  • Private Nachrichten
  • Anhänge
  • Avatare (nur wenn sie in der Datenbank gespeichert sind, siehe unten)
  • Dauerhafte Links (Permalinks) für Themen

Hinweise

  • Sie können einen unterbrochenen Import fortsetzen und gegen eine neuere Datenbank-Snapshot-Version erneut ausführen, um neue Inhalte zu übernehmen. Bereits importierte Inhalte werden nicht mit späteren Bearbeitungen aktualisiert.

  • Discourse unterstützt zwei Ebenen von Kategorien.tiefer verschachtelte Foren werden abgeflacht.

  • BBCode-Listen ([ul], [ol], [li]) werden nicht vollständig konvertiert und erfordern möglicherweise eine manuelle Bereinigung.

Vor dem Export

Wenn vBulletin Avatare im Dateisystem speichert, findet der Importer diese nicht. Rufen Sie /admincp/avatar.php?do=storage auf Ihrer vBulletin-Website auf und verschieben Sie die Avatare in die Datenbank, bevor Sie sie exportieren.

Exportieren Sie anschließend die Datenbank auf dem vBulletin-Server:

mysqldump -u BENUTZERNAME -p DATENBANK_NAME | gzip > vb4_dump.sql.gz

Kopieren Sie den Dump und den Anhängeordner auf die Maschine, auf der der Import erfolgen soll (z. B. mit scp oder rsync). Ihre vBulletin-Admin-Einstellungen zeigen an, wo die Anhänge gespeichert sind.

Option A: Import auf einer Entwicklungsmaschine (empfohlen)

Der lokale Import ermöglicht schnelles Iterieren und das Verwerfen fehlgeschlagener Versuche. Wenn das Ergebnis korrekt aussieht, erstellen Sie ein Backup der Seite und stellen Sie es in der Produktionsumgebung wieder her.

  1. Richten Sie eine Discourse-Entwicklungsumgebung ein, indem Sie dem Ubuntu/Debian- oder macOS-Leitfaden folgen.

  2. Installieren Sie MariaDB. Es ist ein direkter Ersatz für MySQL, und Pakete für MySQL 5.7 sind auf aktuellen Distributionen nicht mehr verfügbar.

    # Ubuntu/Debian
    sudo apt-get update
    sudo apt-get install mariadb-server libmariadb-dev
    sudo service mariadb start
    
     # macOS
     brew install mariadb
     brew services start mariadb
    
  3. Installieren Sie die Importer-Gems. mysql2 ist enthalten, wenn IMPORT=1 gesetzt ist. php-serialize muss hinzugefügt werden:

    cd ~/discourse
    echo "gem 'php-serialize', require: false" >> Gemfile
    IMPORT=1 bundle install
    
  4. Laden Sie die vBulletin-Datenbank:

    sudo mysql -e "CREATE DATABASE vb4"
    gunzip < vb4_dump.sql.gz | sudo mysql vb4
    
  5. Beginnen Sie mit einer leeren Discourse-Datenbank:

    bin/rails db:drop db:create db:migrate
    
  6. Führen Sie den Importer aus. Sie können ihn jederzeit stoppen und neu starten, da er bereits importierte Inhalte überspringt.

    export DB_HOST="localhost"  
    export DB_NAME="vb4"
    export DB_USER="root"
    export DB_PW=""                                # MariaDB-Root-Passwort, falls Sie eines festgelegt haben
    export TABLE_PREFIX="vb_"                      # Ihr Tabellenpräfix oder "", wenn keines vorhanden ist
    export ATTACHMENT_DIR="/pfad/zum/attachments"   # Der Anhängeordner, den Sie kopiert haben
    export TIMEZONE="America/Los_Angeles"          # Die von vBulletin verwendete Zeitzone
    
    IMPORT=1 bundle exec ruby script/import_scripts/vbulletin.rb
    
  7. Starten Sie Discourse und lassen Sie Hintergrundjobs beenden. Führen Sie bin/dev aus und starten Sie in einem zweiten Terminal bundle exec sidekiq. Das Neubacken von Beiträgen und die Bildverarbeitung können auf einem großen Forum lange dauern. Den Fortschritt können Sie unter http://localhost:4200/sidekiq verfolgen.

  8. Umstellung auf die Produktion. Erstellen Sie ein Backup und stellen Sie es auf Ihrer Produktionsseite wieder her, indem Sie dem Leitfaden Move a Discourse site to another VPS folgen.

Option B: Import direkt im Produktionscontainer

  1. Installieren Sie Discourse mit dem standardmäßigen Installationsleitfaden.

  2. Passen Sie die Website-Einstellungen an (siehe unten: Empfohlene Website-Einstellungen).

  3. Kopieren Sie den Dump und die Anhänge nach /var/discourse/shared/standalone/ auf dem Host. Im Container erscheinen sie unter /shared/, und Dateien dort überleben einen Container-Neuaufbau.

  4. Betreten Sie den Container und installieren Sie MariaDB:

    cd /var/discourse
    ./launcher enter app
    apt-get update
    apt-get install -y mariadb-server libmariadb-dev
    service mariadb start
    
  5. Installieren Sie die Importer-Gems:

    cd /var/www/discourse
    echo "gem 'php-serialize', require: false" >> Gemfile
    su discourse -c 'bundle config set --local deployment false && bundle config set --local frozen false'
    su discourse -c 'IMPORT=1 bundle install'
    
  6. Laden Sie die vBulletin-Datenbank:

    mysql -e "CREATE DATABASE vb4"
    gunzip < /shared/vb4_dump.sql.gz | mysql vb4
    
  7. Führen Sie den Importer aus. Führen Sie ihn in tmux oder screen aus, damit eine SSH-Trennung ihn nicht beendet.

    cd /var/www/discourse
    su discourse -c 'DB_NAME=vb4 DB_USER=root DB_PW="" TABLE_PREFIX=vb_ \
    ATTACHMENT_DIR=/shared/attachments TIMEZONE=America/Los_Angeles \
    IMPORT=1 bundle exec ruby script/import_scripts/vbulletin.rb'
    
  8. Aufräumen. Löschen Sie die Dateien, die Sie nach /shared kopiert haben, und bauen Sie den Container neu auf. Der Neuaufbau entfernt MariaDB und die zusätzlichen Gems und stellt die ursprüngliche Gemfile wieder her.

    exit
    cd /var/discourse
    ./launcher rebuild app
    

Empfohlene Website-Einstellungen

Legen Sie diese vor dem Import fest. Sie können sie auch in get_site_settings_for_import in script/import_scripts/base.rb festlegen, was hilfreich ist, wenn Sie Testimporte wiederholt durchführen.

  • login_required: Aktivieren Sie dies, bis der Import abgeschlossen und überprüft wurde.

  • slug_generation_method: Stellen Sie dies auf encoded, wenn Ihr Forum nicht auf Englisch ist, damit die URLs der Themen ihre Nicht-ASCII-Titel beibehalten.

  • download_remote_images_to_local: Deaktivieren Sie dies, wenn Sie nicht möchten, dass Discourse Bilder herunterlädt, die in alten Beiträgen verlinkt sind (Hotlinking).

  • disable_system_edit_notifications: Aktivieren Sie dies, damit Benutzer nicht über jeden Beitrag informiert werden, den das System während der Bildverarbeitung bearbeitet.

Bekannte Probleme

  • Integer values are not supported (ArgumentError) in parse_timestamp. Dies betrifft ältere Kopien des Skripts, die mit neueren Versionen von tzinfo ausgeführt werden. Aktualisieren Sie auf die neueste Discourse-Version oder ändern Sie `parse_timestamp` in:

    def parse_timestamp(timestamp)
    return nil if timestamp.blank?
       Time.zone.at(@tz.utc_to_local(Time.at(timestamp.to_i)))
    end
    
  • Zitate mit Benutzernamen, die Leerzeichen enthalten, oder verschachtelte Zitate werden nicht konvertiert. Siehe diese Antwort für verbesserte reguläre Ausdrücke.

  • Can't connect to local server through socket. MariaDB läuft nicht. Starten Sie es mit service mariadb start.

21 „Gefällt mir“

The script will now import avatars, but they must be embedded into the database. To do so, I’m told that you visit /admincp/avatar.php?do=storage and do something there. It seemed to work for the last client I did an import for.

Hey, @erlend_sh, make this a wiki and I’ll add to it in a few days when I submit a PR for this importer.

6 „Gefällt mir“

I was following your guide to import my vBulletin forum to Discourse. I am using a docker container for Discourse. I ran the following command:

I got a long list of errors:

sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
[...]
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified

Bundler::SudoNotPermittedError: Bundler requires sudo access to install at the moment. Try installing again, granting Bundler sudo access when
prompted, or installing into a different path.
An error occurred while installing rake (11.2.2), and Bundler cannot continue.
Make sure that `gem install rake -v '11.2.2'` succeeds before bundling.

I am new to ruby on rails and dockers. I do understand the concept of gems and Bundler.
What do these errors mean and how can I resolve them?

1 „Gefällt mir“

Ok so basically I had to install all the necessary gems.
The script worked quite well.

However, I am not able to login with one of the users I created on my vBulletin forum just before importing the database over to discourse.

1 „Gefällt mir“

You’ll need to set passwords. The script doesn’t import them (last I looked).

And even if it did, you’d need to install a plugin to make them work.

1 „Gefällt mir“

I am planning to write a script that will import the passwords for my case.
I know the mysql tables I need to consider for vBulletin. What is the table in PostgreSQL for Discourse that stores passwords and is used during login?

Prakarsh would you be able to share the forum url that you are trying to switch from? The vBulletin one. Will the Discourse one have the same URL?

Yes. Here it is: Brainstorm

Our plan is to keep the URL same for now. I cannot say when it will be live. Probably by end of next week if everything goes right :stuck_out_tongue:

1 „Gefällt mir“

Before you do that, you should read this topic.

You don’t want to directly touch the Discourse tables. You want a script like this. When I last used it and tried to import the passwords, it ran really slowly. I’m not sure why, but after reading this I decided that it’s probably not a bad idea to make people change their passwords.

3 „Gefällt mir“

@pfaffman - You mentioned you used import_pass field in your import script.
Where exactly do you put the import_pass field? And how do you use it?
If you could share it would be great help.

I have tried using this script but it failed 90% into the import of the users:

su discourse -c 'RAILS_ENV=production ruby script/import_scripts/vbulletin.rb'
root:XXXX@localhost wants vb4
loading existing groups...
loading existing users...
loading existing categories...
loading existing posts...
loading existing topics...

importing groups...
        6 / 19 ( 31.6%)  Failed to create group id 7 Moderators: ["Name has already been taken"]
       19 / 19 (100.0%)  
importing users
     2746 / 15319 ( 17.9%)  W, [2017-10-12T10:07:05.104837 #3578]  WARN -- : Bad date/time value "0000:00:00 00:00:00": mon out of range
W, [2017-10-12T10:07:05.106562 #3578]  WARN -- : Bad date/time value "0000:00:00 00:00:00": mon out of range
W, [2017-10-12T10:07:05.107305 #3578]  WARN -- : Bad date/time value "0000:00:00 00:00:00": mon out of range
    13901 / 15319 ( 90.7%)  script/import_scripts/vbulletin.rb:137:in `strip': invalid byte sequence in UTF-8 (ArgumentError)
        from script/import_scripts/vbulletin.rb:137:in `block (2 levels) in import_users'
        from /var/www/discourse/script/import_scripts/base.rb:226:in `block in create_users'
        from /var/www/discourse/script/import_scripts/base.rb:225:in `each'
        from /var/www/discourse/script/import_scripts/base.rb:225:in `create_users'
        from script/import_scripts/vbulletin.rb:133:in `block in import_users'
        from /var/www/discourse/script/import_scripts/base.rb:784:in `block in batches'
        from /var/www/discourse/script/import_scripts/base.rb:783:in `loop'
        from /var/www/discourse/script/import_scripts/base.rb:783:in `batches'
        from script/import_scripts/vbulletin.rb:117:in `import_users'
        from script/import_scripts/vbulletin.rb:78:in `execute'
        from /var/www/discourse/script/import_scripts/base.rb:45:in `perform'
        from script/import_scripts/vbulletin.rb:902:in `<main>'

Anyone have any suggestions regarding how to debug and fix this?

You have an encoding problem in your database.

The database claims is using one encoding, but some of the data is encoded some other way. A job I just did had a similar problem. UTF-8 likely does not exist when you started your forum.

This is probably a problem for stack exchange or a database person. It’s not a problem with the importer.

It’s the kind of problem that will take 10 minutes following a recipe that you don’t understand, ten hours looking for that recipe, or 100 hours fixing it by hand.

3 „Gefällt mir“

Cheers @pfaffman I was approaching the same conclusion… I started writing up the following before your comment…

It looks like it might be caused by non-ascii characters in usernames, so dumping the usernames into a text file and searching for UTF-8:

echo "select username from user" | mysql -p vb4 | grep --color='auto' -P -n "[^[:ascii:]]"

These were the entities this threw up:

’ ´ – é ã Ñ í ó 

So I used this page to generate encoded versions and updated the usernames in the database, for example:

UPDATE user SET username="&rsquo; &acute; &ndash; &eacute; &atilde; &Ntilde; &iacute; &oacute;" WHERE username="’ ´ – é ã Ñ í ó"

But the script still fails:

script/import_scripts/vbulletin.rb:137:in `strip': invalid byte sequence in UTF-8 (ArgumentError)
        from script/import_scripts/vbulletin.rb:137:in `block (2 levels) in import_users'
        from /var/www/discourse/script/import_scripts/base.rb:226:in `block in create_users'
        from /var/www/discourse/script/import_scripts/base.rb:225:in `each'
        from /var/www/discourse/script/import_scripts/base.rb:225:in `create_users'
        from script/import_scripts/vbulletin.rb:133:in `block in import_users'
        from /var/www/discourse/script/import_scripts/base.rb:784:in `block in batches'
        from /var/www/discourse/script/import_scripts/base.rb:783:in `loop'
        from /var/www/discourse/script/import_scripts/base.rb:783:in `batches'
        from script/import_scripts/vbulletin.rb:117:in `import_users'
        from script/import_scripts/vbulletin.rb:78:in `execute'
        from /var/www/discourse/script/import_scripts/base.rb:45:in `perform'
        from script/import_scripts/vbulletin.rb:902:in `<main>'

So I then dumped the whole users table into a text file:

echo "select * from user" | mysql -p vb4 > /tmp/allusers.txt

And then tried all the suggesting in this stackexchange thread for finding non-ascii characters and none were found, so now to search the whole database for the problem…

When I find a solution I’ll post it here in case it helps others…

2 „Gefällt mir“

The problem almost certainly exists in other tables.

You need to figure out what it’s encoded in and fix it.

Or, it could be that for some years it’s in one encoding and other years it’s another.

Best of luck. I was relieved they my client had engineers they solved the problem so I didn’t have to. I may have some notes that I’ll try to find when I get out of bed.

1 „Gefällt mir“

The database on the old server was UTF-8 but clearly it has some non-UTF-8 in it, the site has been in use for a long time and has 13k users… so taking care with dumping the old database:

mysqldump -uroot -p database -r dump.sql

And trying various methods to check the encoding (thanks to Stackexchange):

file dump.sql 
  dump.sql: ASCII text, with very long lines

apt install uchardet 
uchardet dump.sql
  UTF-8

iconv -f utf-8 -t utf-8 dump.sql > dump.utf-8.sql
  iconv: illegal input sequence at position 29618109

apt install moreutils
isutf8 dump.sql 
  dump.sql: line 2995, char 42, byte 29618109: Expecting bytes in the following ranges: 00..7F C2..F4.

And this is a image line:

INSERT INTO `customavatar` VALUES (6355,'ÿØÿà\0^PJFIF\0^A^A\0\0^A\0^A\0\0ÿþ\0;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 75

And before I delete the line using vim I need to increase the size of the partitions as it is a 1.4G file and I’m running out of space when editing it…

1 „Gefällt mir“

The problem was a user with &#55357;&#56444; in the username field, once the HTML entities were removed the import script ran, but there were a lot of errors like this:

ERR Error running script (call to f_b06356ba4628144e123b652c99605b873107c9be): @user_script:14: @user_script: 14: -MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error. 

Is this something that I should be concerned about and something that I should fix and then redo the import?

Are you out of disk space?

1 „Gefällt mir“

Yes! I’m now spinning up a new virtual server with a huge amount of disk space, CPUs and RAM and I’m going to start from scratch…

By the way, I’m following the instructions above for the Docker version and found that I needed to add an additional step in the container

echo "discourse ALL = NOPASSWD: ALL" >> /etc/sudoers

Before running:

su discourse -c 'bundle install --no-deployment --without test --without development'

In the non-docker instructions above there is this step to delete data from the database before doing the import:

  • Clear existing data from your local Discourse instance
cd ~/discourse
bundle exec rake db:drop db:create db:migrate

Was this omitted from the Docker instructions on purpose?

1 „Gefällt mir“

There are two, different, vbulletin import scripts, in the docker container:

cd /var/www/discourse
find ./ -name vbulletin.rb
./script/bulk_import/vbulletin.rb
./script/import_scripts/vbulletin.rb

The second one is twice the size of the first one and it is the one I have been using.