Anleitung:Backup eines Wikis
Es ist wichtig, regelmäßige Sicherungen (engl.: Backup, pl.: Backups) der Daten in ihrem Wiki zu machen. Diese Seite bietet einen Überblick über den Sicherungsvorgang für einen typischen MediaWiki-Wiki; möglicherweise möchten Sie Ihre eigenen Sicherungsskripte oder Zeitpläne anlegen, die an die Größe Ihres Wikis und Ihre individuellen Bedürfnisse angepasst sind.
Übersicht
MediaWiki speichert wichtige Daten an zwei Orten:
- Datenbank
- Seiten und ihr Inhalt, Benutzer und ihre Einstellungen, Metadaten, den Suchindex usw.
- Dateisystem
- Konfigurationsdateien, angepasste Skins, Erweiterungen, Bilder (inkl. gelöschte Bilder) usw.
Sie sollten in Erwägung ziehen, Ihr Wiki vor der Datensicherung auf read-only zu setzen, also vor Veränderung zu schützen — siehe auch $wgReadOnly . Dadurch wird sichergestellt, dass alle Teile der Datensicherung vollständig und konsistent sind.
Datenübertragung
Für die Übertragung des Backups vom Server stehen folgende Möglichkeiten zur Verfügung:
- Nicht-private Daten können einfach auf archive.org veröffentlicht und/oder in einem
dumps/
-Verzeichnis Ihres Servers abgelegt werden. - SCP (or WinSCP), SFTP/FTP oder irgendein anderes Übertragungsprotokoll, mit dem Sie vertraut sind, ist verfügbar.
- Ihr Webspace-Betreiber stellt Ihnen vielleicht sogar eine Datei-Manager-Oberfläche über Ihren Webbrowser zur Verfügung. Prüfen Sie die enthaltenen Leistungen Ihres Webhostingpaketes Ihres Hostinganbieters.
Datenbank
Die meisten wichtigen Daten des Wikis werden in der Datenbank gespeichert, die in der Regel sehr leicht zu sichern ist. Wenn Sie das MySQL-Backend benutzen (standardmäßig), stehen Ihnen verschiedene Tools zur Verfügung, um die Datenbank in eine Datei zu "dumpen" (engl. dumping, bedeutet soviel wie "exportieren"). Die dadurch erzeugte Skriptdatei kann verwendet werden, um die Datenbank von Grund auf neu einzurichten. If your wiki is currently offline, its database can be backed up by simply copying the database file.
When using the default MySQL or MariaDB backend, the database can be dumped into a script file which can be used later to recreate the database and all the data in it from scratch.
MySQL
Automysqlbackup
Das Paket in Debian anzeigen:
$ apt show automysqlbackup
[...]
Description: automysqlbackup creates backup every day, week and month for all of your MySQL database, to a configured folder. There's nothing to do but to install this package, and you'll rest assured that you have a way to go back in the history of your database.
[...]
Installation des Paketes:
# apt install automysqlbackup
Alle Datenbanken werden in /var/lib/automysqlbackup/ gespeichert:
$ find /var/lib/automysqlbackup/
/var/lib/automysqlbackup/
/var/lib/automysqlbackup/weekly
/var/lib/automysqlbackup/weekly/my_wiki
/var/lib/automysqlbackup/weekly/my_wiki/my_wiki_week.18.2016-05-07_15h32m.sql.gz
/var/lib/automysqlbackup/monthly
/var/lib/automysqlbackup/daily
/var/lib/automysqlbackup/daily/my_wiki
Manuelle Sicherung (Backup):
# automysqlbackup
Datenbank wiederherstellen:
gunzip < /var/lib/automysqlbackup/weekly/my_wiki/my_wiki_week.18.2016-05-07_15h32m.sql.gz|mysql -uUSER -pPASSWORD my_wiki
Für andere Distributionen, siehe Sourceforge.
Sicherung der Datenbank mit mysqldump in der shell
Der einfachste Weg, eine Dump-Datei der Datenbank zu erstellen, die Sie sichern möchten, ist es, das Standard-MySQL-Dump-Tool mysqldump aus der Kommandozeile aufzurufen. Achten Sie bitte darauf, dass alle Parameter richtig gesetzt sind, da die Wiederherstellung ansonsten Probleme bereiten kann! Abhängig von der Datenbank-Größe kann mysqldump einige Zeit in Anspruch nehmen.
Fügen Sie zunächst die folgende Zeile in die Datei LocalSettings.php ein
$wgReadOnly = 'Dumping Database, Access will be restored shortly';
Diese Zeile kann wieder entfernt werden, sobald die Sicherung abgeschlossen ist.
Ein beispielhafter Aufruf von der Linux/UNIX Kommandozeile:
mysqldump -h hostname -u userid -p --default-character-set=charset dbname > backup.sql
Verwenden Sie individuellen Werte für hostname
, userid
, character-set
und dbname
. Durch dieses Skript wird eine Sicherungsdatei mit dem Wochentag im Dateinamen erstellt, so dass Sie ein fortlaufendes Set von Datensicherungen haben. Wenn Sie die Dateien und Erweiterungen ebenfalls speichern möchten, könnten Sie zum Beispiel dieses Tool benutzen.
Wenn die letzte Zeile keinen DEFAULT CHARSET
-Teil enthält und Sie wissen, dass der Zeichensatz von niemandem verändert wurde, seit die Datenbank eingerichtet wurde, und dass die Wiki-Datenbank mit dem Standard-Zeichensatz der Datenbank erstellt wurde, dann gibt es noch einen anderen Weg, den Zeichensatz herauszufinden: Der STATUS
-Befehl zeigt den Standard-Zeichensatz des Datenbankservers (bei Server characterset:
). Hier eine Beispielausgabe:
Benutzen Sie die Option --default-character-set=latin1
in der mysqldump
-Kommandozeile, um die Zeichensatzkonvertierung zu verhindern, sofern der o.g. Standardzeichensatz auf "latin1" eingestellt ist.
für MySQL 4.1 und jüngere Versionen: Bei einigen allgemeinen Konfigurationen könnte mysqldump
die in der Datenbank gespeicherten Artikeltexte beschädigen. Wenn der Zeichensatz Ihrer Datenbank auf "latin1" statt "UTF-8" gesetzt ist, wird mysqldump
eine Zeichensatzkonvertierung durchführen, die beispielsweise Umlaute im Text zerstören könnte.
All four may be found in your LocalSettings.php (LSP) file.
hostname
may be found under $wgDBserver ; by default it is localhost.
userid
may be found under $wgDBuser , charset
may be found under $wgDBTableOptions , where it is listed after DEFAULT CHARSET=
.
If charset
is not specified mysqldump will likely use the default of utf8, or if using an older version of MySQL, latin1.
While dbname
may be found under $wgDBname .
After running this line from the command line mysqldump will prompt for the server password (which may be found under Handbuch:$wgDBpassword in LSP).
Das MySQL-Dump-Tool beispielsweise ist ein Kommandozeilenprogramm, das eine Dump-Datei mit dem Namen der Datenbank(en) erzeugen kann. Das Programmverhalten kann durch Standard-Parameter verändert werden, die das Format der Ausgabedatei z.B. durch Setzen des Zeichensatzes anpassen.
Sie können sich ansehen, welchen Zeichensatz Ihre Tabellen benutzen, wenn Sie einen MySQL-Befehl wie SHOW CREATE TABLE text
verwenden. Die letzte Zeile enthält dann einen DEFAULT CHARSET
-Teil.
Die Ausgabe von mysqldump kann durch Kompression mit gzip verkleinert werden. Dazu kann die Standardausgabe mit | auf gzip oder einen anderen Packer umgeleitet werden.
mysqldump -h hostname -u userid -p dbname | gzip > backup.sql.gz
Some newer versions of MySQL might show an error about tablespaces and PROCESS privilege.
MediaWiki does not use tablespaces.
The solution is to add the --no-tablespaces
option to the command:
mysqldump --no-tablespaces -h hostname -u userid -p dbname | gzip > backup.sql.gz
Wenn die Sicherung als XML erfolgen soll, kann der --xml Parameter verwendet werden:
mysqldump -h hostname -u userid -p --xml dbname > backup.xml
Und auch hier kann das Ergebnis durch Umleitung nach gzip komprimiert werden:
mysqldump -h hostname -u userid -p --xml dbname | gzip > backup.xml.gz
Additional options you should consider using with mysqldump for a backup includes the following.
Option | Beschreibung |
---|---|
--default-character-set | Specify default character set |
--no-tablespaces | Do not write CREATE LOGFILE GROUP or CREATE TABLESPACE statements in output |
--single-transaction | Issue a BEGIN SQL statement before dumping data from server |
--triggers | Dump triggers for each dumped table |
--routines | Dump stored routines (procedures and functions) from dumped databases |
--events | Dump events from dumped databases |
--add-drop-table | Add DROP DATABASE statement before each CREATE DATABASE statement |
--create-options | Include MySQL-specific table options in CREATE TABLE statements |
--extended-insert | Use multiple-row INSERT syntax |
If you do not use --single-transaction, then you should consider using the --lock-tables and --add-locks options.
Due to an unexpected change in MySQL versions 5.7.41 and 8.0.32 in February 2023, the --single-transaction option required the backup user to have RELOAD or FLUSH_TABLES privileges. The issue was fixed in MySQL versions 5.7.42 and 8.0.33. See MySQL Bug 109685 and Ubuntu Bug 2003866 for details.
Vergessen Sie nicht, auch die Komponenten des Wikis zu sichern, die nicht in der Datenbank abgelegt sind, wie z.B. Bilder, Logo und Erweiterungen.
Zeitgesteuerter Aufruf von mysqldump mittels cron
Cron ist eine zeitgesteuerte Aufgabenverarbeitung in Unix-artigen Betriebssystemen. Es ermöglicht eine periodische Ausführung von Aufgaben (Kommandos oder Shell-Skripte) zu bestimmten Zeiten.
Ein Beispielbefehl, den Sie mittel crontab aus ausführen können, könnte wie folgt aussehen:
nice -n 19 mysqldump -u $USER --password=$PASSWORD $DATABASE -c | nice -n 19 gzip -9 > ~/backup/wiki-$DATABASE-$(date '+%Y%m%d').sql.gz
Der Befehl nice -n 19
senkt die Priorität des Prozesses.
Für $USER
, $PASSWORD
, und $DATABASE
sind die gültigen Werte einzusetzen. Das obige Kommando schreibt eine Backup-Datei mit dem Wochentag im Dateinamen. Für eine zusätzliche Sicherung der Bilddateien und Erweiterungen kann dieses Skript verwendet werden.
If you want to add this task in Cron through Cpanel then you must escape the character "%"
/usr/bin/mysqldump -u $USER --password=$PASSWORD $DATABASE -c | /bin/gzip > ~/backup/wiki-$DATABASE-$(date '+\%Y\%m\%d').sql.gz
or you will get an error:
/bin/sh: -c: line 0: unexpected EOF while looking for matching `'' /bin/sh: -c: line 1: syntax error: unexpected end of file
Running mysqldump with Systemd
Systemd unifies service configurations and control. Timers are systemd unit files that control service files or events. Timers can be used as an alternative to cron. An example of systemd unit files and backup script is shown below.
wiki-backup.timer
The following timer runs the wiki-backup service at 5:10 AM every morning.
$ cat /etc/systemd/system/wiki-backup.timer [Unit] Description=Run the backup service once a day Documentation=... [Timer] OnCalendar=*-*-* 05:10:00 RandomizedDelaySec=600 Persistent=true [Install] WantedBy=timers.target
wiki-backup.service
When the wiki-backup timer fires, then the service is invoked.
The service runs a script located in /sbin
.
$ cat /etc/systemd/system/wiki-backup.service [Unit] Description=Run the backup service once a day Documentation=... [Service] Type=oneshot User=root ExecStart=/sbin/wiki-backup
wiki-backup script
$ cat /sbin/wiki-backup #!/usr/bin/env bash # Systemd adds random paths at times. Take full control of PATH. PATH=/bin:/sbin:/usr/bin:/usr/sbin export PATH # Read the backup password from conf or ini Failed wiki_password=... # Fix the wiki tables just in case. This step produces a lot of noise, # so send stdout to /dev/null. if MYSQL_PWD="${wiki_password}" \ mysqlcheck my_wiki --auto-repair --user=mwuser 1>/dev/null; then echo "Repair wiki database ok" else echo "Failed to repair wiki database" echo "Continuing anyways" fi # Disable the connection from Apache to MySQL for the dump if ! systemctl stop apache2.service ; then echo "Failed to stop Apache service" echo "Continuing anyways" fi # Lock option choice due to MySQL change at versions 5.7.41 and 8.0.32 in # February 2023. See https://bugs.mysql.com/bug.php?id=109685 and # https://bugs.launchpad.net/ubuntu/+source/mysql-5.7/+bug/2003866. if mysql --version 2>&1 | grep -q -E 'mysql[[:space:]]+Ver 8\.0\.32'; then echo "Using MySQL --lock-tables --add-locks options" mysql_lock_opt="--lock-tables --add-locks" else echo "Using MySQL --single-transaction option" mysql_lock_opt="--single-transaction" fi if MYSQL_PWD="${wiki_password}" \ mysqldump --no-tablespaces \ ${mysql_lock_opt} \ --events --triggers --routines \ --add-drop-table --create-options \ --extended-insert \ --default-character-set=utf8 \ -u mwuser -h localhost my_wiki | gzip -q -v9 > /backup/wiki-backup.sql.gz ; then echo "Dump wiki database ok" else echo "Failed to dump wiki database" echo "Continuing anyways" fi # Re-enable connection from Apache to MySQL for the dump if ! systemctl start apache2.service ; then echo "Failed to start Apache service" echo "Continuing anyways" fi exit 0
Tabellen
Some of the tables dumped have different degrees of temporariness. So to save disk space (beyond just gziping), although those tables need to be present in a proper dump, their data does not. However, under certain circumstances the disadvantage of having to rebuild all this data may outweigh saving disk space (for example, on a large wiki where restoration speed is paramount).
See mailing list thread mysql5 binary schema about the topic.
Latin-1 zu UTF-8 Konvertion
See the relevant section of the upgrading page for information about this process. Also see the talk page for more information about working with character sets in general.
PostgreSQL
You can use the pg_dump
tool to back up a MediaWiki PostgreSQL database. For example:
pg_dump mywiki > mywikidump.sql
will dump the mywiki
database to mywikidump.sql.
To restore the dump:
psql mywiki -f mywikidump.sql
You may also want to dump the global information, e.g. the database users:
pg_dumpall --globals > postgres_globals.sql
SQLite
Wenn dein Wiki gerade offline ist, kann seine Datenbank durch einfaches Kopieren der Datenbankdatei gesichert werden.
Andernfalls solltest du ein Wartungsskript verwenden: php maintenance/SqliteMaintenance.php --backup-to <backup file name>
, das sicherstellt, dass die Operation atomar abläuft und keine Inkonsistenzen existieren.
Wenn deine Datenbank nicht sehr groß ist und der Server nicht stark belastet wird, werden die Benutzer, die das Wiki bearbeiten, lediglich eine kurze Verzögerung bemerken.
Nutzerinnen und Nutzer, die nur lesen, werden in jedem Fall nichts bemerken.
phpMyAdmin
Turn your wiki to read only by adding $wgReadOnly = 'Site Maintenance';
to LocalSettings.php.
Find the wiki database in LocalSettings.php. Here is an example of what this looks like in LocalSettings.php:
## Database settings
$wgDBtype = "mysql";
$wgDBserver = "localhost";
$wgDBname = "sashtmax_mw19999";
$wgDBuser = "sashtmax_mw19999";
$wgDBpassword = "S7[88p]jJJ";
- Open the browser to your phpadmin link, login, choose the wiki database.
- Select Export. Make sure all items under Export are highlighted, and make sure Structure is highlighted (it's important to maintain the table structure). Optionally check Add DROP TABLE to delete existing references when importing. Make sure Data is checked.
- Select zipped.
- Click on GO and save the backup file.[1]
- Remove
$wgReadOnly = 'Site Maintenance';
from LocalSettings.php
Remember to also backup the file system components of the wiki that might be required, e.g. images, logo, and extensions.
Externe Links
HeidiSQL (alternative to phpMyAdmin)
HeidiSQL is similar to phpMyAdmin, but without any restrictions of phpMyAdmin's free version. HeidiSQL requires a direct database connection, where some hosts may only offer web interfaces (phpMyAdmin) to firewalled databases.
Dateisystem
Andere Komponenten des Wikis werden von MediaWiki im Dateisystem gespeichert, zumindest dort, wo es sich besser als eine Datenbank eignet, zum Beispiel bei Konfigurationsdateien ($1, $2 (finally removed in 1.23)), Bilddateien (inklusive gelöschte Bilder, Thumbnails, mathematische Formeln und SVG-Bilder, sofern vorhanden), Anpassungen des Skins, Erweiterungsdateien usw.
The most important of these are:
- LocalSettings.php
- uploaded files in the
images/
directory (including deleted files, thumbnails, and rendered math and SVG images, if applicable).
Der beste Weg, diese Dateien zu sichern, liegt darin, sie in eine Archivdatei zu packen, die zum Beispiel das .tar
-Format hat; eine Kompression ist bei Bedarf möglich. Unter Windows können dazu Programme wie WinZip, WinRar oder 7-Zip verwendet werden.
For Linux variants, assuming the wiki is stored in /srv/www/htdocs/wiki
tar zcvhf wikidata.tgz /srv/www/htdocs/wiki
It should be possible to backup the entire "wiki" folder in "htdocs" if using XAMPP.
Konfigurationsdateien
LocalSettings.php is the most important of these, but a wiki might also have things like .htaccess
or other web server configuration files that should be backed up.
Hochgeladene Dateien
Files uploaded to the wiki are by default put into the images/
directory, separated into subdirectories such as images/8/8f
.
There are also other directories such as images/archive/
and images/deleted/
.
These should all be backed up.
The images/thumb/
can be backed up along with everything else, but can optionally be excluded in order to save backup space.
This directory stores the derived thumbnails of images and other files; generally multiple thumbnails per wiki file.
After restoring from backup, these thumbnails will be recreated as required (although depending on $wgGenerateThumbnailOnParse this may need to be a manual process).
Backup des Wiki-Inhalts (XML dump)
Es ist auch eine gute Idee, einen XML-Dump zusätzlich zum Datenbank-Dump zu erstellen. XML-Dumps enthalten den Inhalt des Wikis (Wiki-Seiten mit allen Versionen oder wahlweise nur der letzten Version), jedoch ohne die verwandten Daten (keine Benutzeraccounts, keine Bild-Metadaten, keine Protokolle usw.). XML-Dumps sind von der Datenbankstruktur unabhängig und können in zukünftige (und auch ältere) Versionen von MediaWiki importiert werden. Solche Dumps verursachen meistens auch weniger Probleme mit Zeichensätzen und können leicht von Tools Dritter verarbeitet werden. Dies macht sie zu einer guten Absicherung, sollte Ihr Hauptdatenbank-Dump unbrauchbar geworden sein.
XML dumps are less likely to cause problems with character encoding, as a means of transferring large amounts of content quickly, and can easily be used by third party tools, which makes XML dumps a good fallback should your main database dump become unusable.
Um einen XML-Dump zu erstellen, benutzen Sie das Kommandozeilentool dumpBackup.php
, das sich im maintenance
-Verzeichnis Ihrer MediaWiki-Installation befindet.
Siehe Handbuch:dumpBackup.php für Details.
Sie können auch für einen Teil der Seiten online einen XML-Dump erstellen, indem Sie die Export-Spezialseite (Special:Export) benutzen, auch wenn der Versuch, größere Textmengen oder längere Versionengeschichten mit diesem Tool zu sichern, meistens an einem Timeout scheitert.
Um einen XML-Dump in Ihr Wiki zu importieren, benutzen Sie das Kommandozeilentool importDump.php
.
Für wenige Seiten können Sie auch die Import-Spezialseite benutzen, welche aber normalerweise auf die sysop-Benutzergruppe beschränkt ist.
Siehe Handbuch:XML-Dumps importieren für weitere Informationen.
Ohne Shell-Verbindung zum Server
MediaWiki Dump Generator
If you have no shell access, use the MediaWiki Client Tools' MediaWiki Dump Generator dumpgenerator script. It is run from the command-line in a terminal.
The XML dump can include full or only most recent page history.
The images dump will contain all file types with associated descriptions.
The siteinfo.json
and SpecialVersion.html
files will contain information about wiki features such as the installed extensions and skins.
User account information won't be preserved.
Full instructions are at the MediaWiki Client Tools' MediaWiki Dump Generator GitHub repository.
Siehe auch Meta:Data dumps.
Skripte
- Unofficial backup script by Flominator; creates a backup of all files and the database, with optional backup rotation.
Shell script, last updated 2012.
- Another backup script that: dumps DB, files (just pictures by default, option to include all files in installation), and XML; puts the site into read-only mode; timestamps backups; and reads the charset from LocalSettings.
Script does not need to be modified for each site to be backed up. Does not (yet) rotate old backups. Verwendung: backup.sh -d backup/directory -w installation/directory
. Also provides a script to restore a backup restore.sh -a backup/directory/dated_archive.tar.gz -w installation/directory
. Shell script, last updated 2013.
- User:Darizotas/MediaWiki Backup Script for Windows - a script for backing up a Windows MediaWiki install. Note: Has no restore feature.
Shell script, last updated 2015.
Shell script, last updated 2016.
- Script to make periodical backups mw_backup. This script will make daily, weekly and monthly backups of your database and images directory when run as a daily cron job.
PHP script, last updated 2017.
- Another unofficial MediaWiki backup script for Windows by Lanthanis that: exports the pages of specified namespaces as an XML file; dumps specified database tables; and adds further specified folders and files to a ZIP backup file.
Can be used with Windows task scheduler. Last updated 2019.
- WikiTeam tools - if you do not have server access (e.g. your wiki is in a free wikifarm), you can generate an XML dump and an image dump using dumpgenerator from WikiTeam tools, (Python 2). See some saved wikis.
Python 2 script.
- MediaWiki Dump Generator - if you do not have server access (e.g. your wiki is in a free wikifarm), you can generate an XML dump and an image dump using dumpgenerator from Mediawiki Client Tools, Python 3 script, last update 2023.
Erweiterungen
- Extension:DumpsOnDemand – Allows users to generate and download database dumps
- Erweiterung:DataDump – Allows users to generate and download XML and file/image dumps
Siehe auch
- Hilfe:Export is a quick and easy way to save all pages on your wiki.
- Handbuch:Wiederherstellen eines Wikis aus Sicherungskopien
- Anleitung: Verschiebung eines Wikis
- Handbuch:Aktualisierung
- Manual:Restoring wiki code from cached HTML — if you don't have a successful backup
- Exporting all the files of a wiki