Jump to content

Handbuch:XML-Dumps importieren

From mediawiki.org
This page is a translated version of the page Manual:Importing XML dumps and the translation is 79% complete.

Diese Seite beschreibt Methoden für den Import von XML-Dumps. XML-Dumps enthalten den Inhalt eines Wikis (Wikiseiten mit allen Versionen) ohne Daten mit Bezug zur Seite. Ein XML-Dump erstellt kein vollständiges Backup der Wiki-Datenbank, denn der Dump enthält keine Benutzerkonten, Bilder, Bearbeitungslogbücher, etc.

Die Seite Special:Export jeder MediaWiki-Seite, darunter jede Wikimedia-Seite und Wikipedia, erstellt eine XML-Datei (Inhaltsdump). Siehe Meta:Daten-Dumps und Handbuch:dumpBackup.php . XML-Dateien werden auf Meta:Hilfe:Export genauer erklärt.

Wie importiert man?

Es gibt mehrere Methoden, um diese XML-Dateien zu importieren.

Importieren großer XML-Dumps (wie der Englischen Wikipedia)

Guide to Importing the English Wikipedia XML File

Importing the English Wikipedia files can be a complex task, but with the right approach, it can be achieved reliably. This guide outlines the process using the importDump.php script located in the maintenance folder of your MediaWiki installation.

Prepare your environment

Before starting the import process, ensure that your server meets the necessary requirements, including sufficient disk space and system resources.

Obtain the Wikipedia XML Dump

The English Wikipedia XML dump can be downloaded from the Wikimedia Foundation's website. At the time of this writing, the file size is approximately 91GB.

Importing the XML Dump

There are several methods to import the XML dump into your MediaWiki installation:

  • Direct Import: You can use the importDump.php script provided in the maintenance folder. This method is reliable but may be resource-intensive.
  • Individual File Import: Alternatively, you can download and import each multipart XML file individually. While this approach allows for more manageable imports, it requires additional effort.
Managing Import Errors

Importing such a large file may result in errors, leading to interruptions in the process. To mitigate this, consider setting up cron jobs to import the XML dump in smaller batches over time. This approach ensures smoother processing and reduces the risk of failures.

Simple Cron Schedule Example

Notes:

  1. The Wiki files are assumed to be located in the main Web Server folder, typically /var/www/html/.
  2. The XML dump file is also assumed to be located in the same directory.
  3. This cron job is executed by the root user, and log files are created in the /root/wikilogs folder.
  4. Replace {your-server} with the URL of your server in the --server argument.
  5. This schedule runs every 10 minutes, allowing for different import sections to be executed in different hours.

Please make changes to point to your specific folders, or create any folders you wish to use.

*/15 4 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 5 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 6 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 7 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 8 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 9 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 10 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 11 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 12 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 13 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 14 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 15 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 16 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 17 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 18 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 19 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 20 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 21 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
*/15 22 * * * /root/wikilogs/10-cronjob.sh > ~/wikilogs/import-$(date +\%Y\%m\%d_\%H\%M\%S)-cron.log 2>&1
0 0 * * * /var/www/html/maintenance/run updateArticleCount.php --use-master --globals --memory-limit default --profiler json --update > ~/wikilogs/articleCount-`date +\%Y\%m\%d\%H\%M\%S`-cron.log 2>&1
30 1 * * * /var/www/html/maintenance/run update --quick > ~/wikilogs/update-`date +\%Y\%m\%d\%H\%M\%S`-cron.log 2>&1
30 2 * * * /var/www/html/maintenance/run rebuildrecentchanges.php --globals --memory-limit default --profiler json > ~/wikilogs/recentChanges-`date +\%Y\%m\%d\%H\%M\%S`-cron.log 2>&1
30 3 * * * /var/www/html/maintenance/run cleanupInvalidDbKeys.php --globals --memory-limit default --profiler json > ~/wikilogs/cleanupInvalidDbKeys-`date +\%Y\%m\%d\%H\%M\%S`-cron.log 2>&1
0 4 * * * /var/www/html/maintenance/run rebuildall.php --use-master --globals --memory-limit default --profiler json --update > ~/wikilogs/rebuildAll-`date +\%Y\%m\%d\%H\%M\%S`-cron.log 2>&1
0 5 * * * /var/www/html/maintenance/run cleanupUsersWithNoId.php --use-master --globals --memory-limit default --profiler json --update > ~/wikilogs/cleanupUsersWithNoId-`date +\%Y\%m\%d\%H\%M\%S`-cron.log 2>&1

In the /root/wikilogs folder, I have created a simple shell script to help import the dump.

#!/bin/bash

# Get the Wiki version to test for compatibility
# Get the BASH version to test for compatibility
# Get the current number of pages, round down to the nearest 1000's or 0 if less than 1000
# Get the server URL
# Start the import to the number of Articles
# Show total pages imported

# Function to convert HH:MM:SS to seconds
function time_to_seconds() {
    local time=$1
    local seconds=0
    IFS=":" read -r hours minutes seconds <<< "$time"
    seconds=$((hours*3600 + minutes*60 + seconds))
    echo "$seconds"
}

# Function to compare version numbers
function version_compare() {
    local version1="$1"
    local version2="$2"
    if [[ "$(printf '%s\n' "$version1" "$version2" | sort -V | head -n1)" == "$version1" ]]; then
        return 0
    else
        return 1
    fi
}

wikilocation="/var/www/html"

# Get the currently installed Wiki Version
rawWikiVersion=$(${wikilocation}/maintenance/run version)
wikiVersion=$(echo "$rawWikiVersion" | awk -F': ' '{split($2,a," "); print a[1]}')

# Compare the version with 1.4.0
# if ! version_compare "$wikiVersion" "1.40.0"; then
#     echo "MediaWiki version is not greater than 1.40.0. Aborting import process."
#     exit 1
# fi

# Get the latest number of pages in the stats
totalStartPages=$(${wikilocation}/maintenance/run showSiteStats | awk '/Total pages/ {print $NF}')

# Round down
articleCount=$(echo "scale=0; (${totalStartPages} / 1000) * 1000" | bc)

# The URL to the wiki
server="<YOUR HTTPS://WEBSITE HERE>"

# Location of the xml file
inputFile="/var/www/html/enwiki-20240120-pages-articles-multistream.xml"

start_time=$(date +%s)
echo "Starting on page ${articleCount} at $(date '+%m-%d-%y %I:%M %p') - Wiki Version ${wikiVersion} with ${server} for the URL"
${wikilocation}/maintenance/run importDump --quiet --memory-limit default --skip-to "${articleCount}" --server "${server}" < ${inputFile} > /dev/null
end_time=$(date +%s)

# Calculate the total number of pages imported
totalEndPages=$(${wikilocation}/maintenance/run showSiteStats | awk '/Total pages/ {print $NF}')
pages_imported=$((totalEndPages - totalStartPages))

# Calculate the duration of the import process in seconds
duration=$((end_time - start_time))

# Convert duration to minutes
duration_minutes=$((duration / 60))

# Calculate pages per minute
pages_per_minute=$(awk "BEGIN {printf \"%.2f\", ${pages_imported} / ${duration_minutes}}")

echo "Completed ${pages_imported} pages in ${duration_minutes} minutes (${pages_per_minute} pages/minute) on $(date '+%m-%d-%y %I:%M %p')"
Monitoring and Troubleshooting

During the import process, monitor the server logs for any errors or warnings. Common issues may include database connection errors, memory exhaustion, or file permissions issues. Troubleshoot any encountered problems promptly to ensure a successful import.

Post-Import Tasks

Once the import is complete, perform any necessary post-import tasks, such as rebuilding the search index or updating site configurations. Verify the integrity of the imported content to ensure consistency with the original Wikipedia articles.

Conclusion

Utilizing a server equipped with 16 cores, 16GB of RAM, and a 2TB SSD, the average import rate over a two-week period stands at 96 pages per minute. This performance metric provides valuable insight into the expected efficiency of the import process, allowing for effective planning and scheduling of import tasks. By leveraging the capabilities of such a server configuration, you can successfully import the English Wikipedia XML dump into your MediaWiki installation, enriching your platform with a wealth of knowledge and resources for users to explore.

To calculate the approximate time it will take to import 59,795,345 pages at an average rate of 96 pages per minute, we can use the following formula:

Total pages ÷ Pages per minute ÷ Minutes per hour ÷ Hours per day ÷ Days per week

Plugging in the values: 59,795,345÷96÷(60×24)÷7 ≈11.87

Rounding up, it will take approximately 12 weeks to import 59,795,345 pages.

Mit Spezial:Import

Special:Import kann von Wiki-Benutzern mit dem Recht import genutzt werden (standardmäßig sind dies Benutzer in der Gruppe sysop), um eine kleine Anzahl von Seiten zu importieren (etwa 100 sollten sicher sein).

Der Versuch, größere Dumps auf diese Weise zu importieren, kann zu Timeouts oder Verbindungsfehlern führen.

  • See Help:Import for a basic description of how the importing process works.[1]

Du wirst gebeten, ein Interwiki-Präfix anzugeben. Wenn du beispielsweise aus der englischen Wikipedia exportiert hast, musst du 'en' eingeben. XML importing requires the import and importupload permissions. Siehe Manual:Benutzerrechte .

Large XML uploads

Large XML uploads might be rejected because they exceed the PHP upload limit set in the php.ini file.

 ; Maximum allowed size for uploaded files.
 upload_max_filesize = 20M

Try changing these four settings in php.ini:

 ; Maximum size of POST data that PHP will accept.
 post_max_size = 20M

 max_execution_time = 1000  ; Maximum execution time of each script, in seconds
 max_input_time = 2000	    ; Maximum amount of time each script may spend parsing request data

 ; Default timeout for socket based streams (seconds)
 default_socket_timeout = 2000

Mit Hilfe von importDump.php, falls du Shell-Zugriff hast

Empfohlene Methode für die allgemeine Verwendung, aber langsam bei sehr großen Datensätzen.
Siehe: Handbuch:ImportDump.php , enthält Tipps zur Nutzung für große Wikis.

Mit Hilfe des Wartungsskript importTextFiles.php

MediaWiki Version:
1.23
MediaWiki Version:
1.27

Wenn du viele Inhalte aus einer anderen Quelle konvertiert hast (mehrere Textverarbeitungsdateien, Inhalte aus einem anderen Wiki, etc.), hast du vielleicht mehrere Dateien, die du in dein Wiki importieren möchtest. In MediaWiki 1.27 und später kannst du das Wartungsskript importTextFiles.php nutzen.

Du kannst auch das Wartungsskript edit.php für diesen Zweck nutzen.

rebuildall.php

Für große XML-Dumps kannst du rebuildall.php ausführen, es wird allerdings lange brauchen, da es alle Seiten parsen muss. Dies wird für große Datensätze nicht empfohlen.

Nutzung von pywikibot, pagefromfile.py und Nokogiri

pywikibot ist eine Sammlung von Werkzeugen in Python, die die Arbeit in Wikipedia oder anderen MediaWiki-Seiten automatisieren. Nachdem du es auf deinem Computer installiert hast, kannst du das Werkzeug pagefromfile.py nutzen, das dich eine Wiki-Datei in Wikipedia oder anderen MediaWiki-Seiten hochladen lässt. Die von dumpBackup.php erstellte XML-Datei kann in eine Wiki-Datei umgewandelt werden, die von 'pagefromfile.py' mithilfe eines einfachen Ruby-Programms in etwas wie das folgende umgewandelt werden kann (hier wandelt das Programm alle XML-Dateien um, die sich im aktuellen Verzeichnis befinden, was erforderlich ist, wenn deine MediaWiki-Seite eine Familie ist):

# -*- coding: utf-8 -*-
# dumpxml2wiki.rb

require 'rubygems'
require 'nokogiri'

# This program dumpxml2wiki reads MediaWiki xml files dumped by dumpBackup.php
# on the current directory and transforms them into wiki files which can then 
# be modified and uploaded again by pywikipediabot using pagefromfile.py on a MediaWiki family site.
# The text of each page is searched with xpath and its title is added on the first line as
# an html comment: this is required by pagefromfile.py.
# 
Dir.glob("*.xml").each do |filename|
  input = Nokogiri::XML(File.new(filename), nil, 'UTF-8')

  puts filename.to_s  # prints the name of each .xml file

  File.open("out_" + filename + ".wiki", 'w') {|f| 
    input.xpath("//xmlns:text").each {|n|
      pptitle = n.parent.parent.at_css "title" # searching for the title
      title = pptitle.content
      f.puts "\n{{-start-}}<!--'''" << title.to_s << "'''-->" << n.content  << "\n{{-stop-}}"
    }
  }
end

Als Beispiel ist hier ein Auszug aus einer Wiki-Datei-Ausgabe des Kommandos 'ruby dumpxml2wiki.rb' (zwei Seiten können dann von pagefromfile.py hochgeladen werden, eine Vorlage und eine zweite Seite, die eine Weiterleitung ist):

{{-start-}}<!--'''Template:Lang_translation_-pl'''--><includeonly>Tłumaczenie</includeonly>
{{-stop-}}

{{-start-}}#REDIRECT[[badania demograficzne]]<!--'''ilościowa demografia'''-->
<noinclude>
[[Category:Termin wielojęzycznego słownika demograficznego (pierwsze wydanie)|ilościowa demografia]]
[[Category:Termin wielojęzycznego słownika demograficznego (pierwsze wydanie) (redirect)]]
[[Category:10]]</noinclude>
{{-stop-}}

Das Programm greift auf jede XML-Datei zu, extrahiert die Texte innerhalb der Tags <text> </text> auf jeder Seite, sucht nach dem entsprechenden Titel und schließt ihn mit den Kommandos {{-start-}}<!--'''Titel der Seite'''--> {{-stop-}} ein, die von 'pagefromfile' genutzt werden, um eine Seite zu erstellen oder zu aktualisieren. Der Name der Seite ist ein HTML-Kommentar und durch drei Anführungszeichen in der ersten Zeile abgetrennt. Bitte beachte, dass der Name der Seite in Unicode geschrieben sein kann. Manchmal ist es wichtig, dass die Seite direkt mit dem Kommando beginnt, wie für #REDIRECT; daher muss sich der Name der Seite hinter dem Kommando, aber weiterhin in der ersten Zeile befinden.

Bitte denke daran, dass die von dumpBackup.php erzeugten XML-Dump-Dateien einen Namensraum als Präfix haben:

<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.4/">

Um auf den Textknoten mit Nokogiri zuzugreifen, musst du deinem Pfad das Präfix 'xmlns' hinzufügen:

input.xpath("//xmlns:text")

Nokogiri ist ein HTML-, XML-, SAX- und Reader-Parser mit der Möglichkeit, Dokumente über XPath- oder CSS3-Selektoren der letzten Generation von XML-Parsern mit Ruby zu durchsuchen.

Beispiel für die Nutzung von 'pagefromfile' zum Hochladen der ausgegebenen Wikitext-Datei:

python pagefromfile.py -file:out_filename.wiki -summary:"Reason for changes" -lang:pl -putthrottle:01

Wie importiert man Protokolle?

Das Exportieren und Importieren von Logbüchern mit den standardmäßigen MediaWiki-Skripten ist häufig schwierig; eine Alternative für den Import ist das Skript pages_logging.py im Werkzeug WikiDAT, wie von Felipe Ortega vorgeschlagen.

Fehlerbehebung

Versionsgeschichten vereinen, Versionskonflikte, Bearbeitungszusammenfassungen und andere Komplikationen

When importing a page with history information, if the user name already exists in the target project, change the user name in the XML file to avoid confusion. If the user name is new to the target project, the contributions will still be available, but no account will be created automatically.

When a page is referenced through a link or a URL, generic namespace names are converted automatically. If the prefix is not a recognized namespace name, the page will default to the main namespace. However, prefixes like "mw:" might be ignored on projects that use them for interwiki linking. In such cases, it might be beneficial to change the prefix to "Project:" in the XML file before importing.

If a page with the same name already exists, importing revisions will combine their histories. Adding a revision between two existing ones can make the next user's changes appear different. To see the actual change, compare the two original revisions, not the inserted one. So, only insert revisions to properly rebuild the page history.

A revision won't be imported if there's already a revision with the same date and time. This usually happens if it's been imported before, either to the current, a previous wiki, or both, possibly from a third site.

An edit summary might reference or link to another page, which can be confusing if the page being linked to has not been imported, even though the referencing page has been.

The edit summary doesn't automatically indicate whether the page has been imported, but in the case of an upload import, you can add this information to the edit summaries in the XML file before the import. This can help prevent confusion. When modifying the XML file with find/replace, keep in mind that adding text to the edit summaries requires differentiating between edits with and without an edit summary. If there are multiple comment tags in the XML file, only the last set will be applied.

Interwikis

Wenn du die Nachricht interwiki erhältst, ist das Problem, dass manche der zu importierenden Seiten ein Präfix haben, das für die interwiki -Verlinkung genutzt wird. Zum Beispiel würde das Präfix 'Meta:' in Konflikt mit dem Interwiki-Präfix meta: stehen, das standardmäßig auf https://meta.wikimedia.org verlinkt.

Du kannst eines der folgenden Dinge tun.

  • Das Präfix aus der interwiki -Tabelle entfernen. Dadurch wird der Seitentitel erhalten, die Interwiki-Verlinkung über dieses Präfix allerdings verhindert.
    Beispiel: Du behältst Seitentitel wie 'Meta:Bla bla', kannst jedoch das Präfix 'meta:' nicht nutzen, um auf meta.wikimedia.org zu verlinken (obwohl es über ein anderes Präfix möglich wäre).
    Wie man es macht: Führe vor dem Importieren des Dumps die Abfrage DELETE FROM interwiki WHERE iw_prefix='prefix' aus (Hinweis: Gib im prefix nicht den Doppelpunkt an). Alternativ kannst du, wenn du die Bearbeitung der Interwikitabelle aktiviert hast, einfach auf Special:Interwiki gehen und den Link 'Löschen' auf der rechten Seite neben der Zeile, die zu dem Präfix gehört, anklicken.
  • Ersetze vor dem Import das unerwünschte Präfix in der XML-Datei durch "Project:". Dadurch bleibt die Funktion des Präfix als Interlink erhalten, allerdings wird das Präfix in den Seitentiteln durch den Namen des Wikis ersetzt, in das sie importiert werden und es kann anstrengend sein, dies bei großen Dumps zu tun.
    Beispiel: Ersetze in der XML-Datei überall 'Meta:' durch 'Project:'. MediaWiki wird dann beim Import 'Project:' durch den Namen des Wikis ersetzen.

Siehe auch

Einzelnachweise

  1. Siehe Handbuch:XML-Importdateimanipulation in CSharp für ein Code-Beispiel in C#, bei dem eine XML-Importdatei manipuliert wird.