Manual:Backing up a wiki/fr

Il est important d'effectuer des sauvegardes régulières des données contenues dans votre wiki. Cette page collige le processus de sauvegarde d'un wiki MediaWiki standard ; vous aurez probablement à cœur de concevoir vous-même les scripts de vos sauvegardes ou de les planifier à la mesure de la taille de votre wiki et de vos besoins.

Présentation générale
Un MediaWiki stocke les données importantes à 2 endroits :
 * la base de données : les pages et leur contenu, les utilisateurs et leurs préférences, les métadonnées, l'index pour la recherche, etc.
 * le système de fichiers : les fichiers de configuration logicielle, les apparences d'affichage personnalisées, les extensions, les images — y compris les images effacées — etc.

Pensez bien à configurer le wiki en mode « lecture seule » avant de créer la sauvegarde, voir pour cela Manual:$wgReadOnly. Ça permet d'assurer la cohérence de toutes les parties de votre sauvegarde — des extensions que vous auriez pu installer peuvent tout de même écrire des données.

Transfert de fichiers
Sauf si vous avez un accès direct au serveur hébergeant le wiki (et encore…) vous aurez à choisir une méthode de transfert de fichiers :
 * copie sécurisée avec SCP ou WinSCP ;
 * protocole de transfert de fichiers SSH (SFTP) ;
 * utilisation d'un client FTP ;
 * l'hébergeur professionnel peut aussi mettre à votre disposition une interface de gestion de fichiers utilisable dans un navigateur web, vérifiez auprès de votre interlocuteur ;
 * d'autres méthodes, il y en a toute une liste sur Wikipédia.

Base de données
La plupart des données critiques d'un wiki sont stockées dans une base de données, généralement facile à sauvegarder. En cas d'utilisation d'un arrière-plan MySQL — backend — par défaut, la base de données peut être versée — dump — dans un fichier de script quant à lui utilisé plus tard pour reconstituer la base et toutes les données à partir de zéro.

Mysqldump en ligne de commande
Le plus pratique pour créer un fichier dump de la base de données que vous souhaitez sauvegarder consiste à employer l'outil MySQL standard  en ligne de commande. Assurez-vous d'avoir tout préalablement bien paramétré, sinon la restauration de la base de données risque d'être ardue. peut prendre un temps considérable, tout dépend de la taille de la base de données.

Initialement placez cette ligne de code dans $wgReadOnly = 'Dumping Database, Access will be restored shortly'; on peut la retirer une fois le dump terminé.

Exemple de commande à exécuter dans une interface — shell — Linux/UNIX : mysqldump -h hostname -u userid --password --default-character-set=whatever dbname > backup.sql En remplaçant hostname, userid, password, dbname etc. comme il convient. Si aucun jeu de caractères n'est spécifié, mysqldump utilise, les versions précédentes utilisaient. La base de données de votre wiki pourrait tout aussi bien être en binaire. C'est à vérifier dans le fichier LocalSettings.php, habituellement sous  DEFAULT CHARSET. Sinon mysql pourrait effectuer le dump selon le système du serveur et non celui du wiki… On peut aussi trouver le  dans   sous.

D'autres paramètres peuvent être utiles, tels que : --quote-names      : fournit les identifiants en toutes lettres entre guillemets obliques --hex-blob         : sauvegarde de colonnes binaires dans un format hexadécimal

See mysqldump for a full list of command line parameters.

The output from mysqldump can instead be piped to gzip, for a smaller output file, as follows mysqldump -h hostname -u userid --password dbname | gzip > backup.sql.gz

A similar mysqldump command can be used to produce xml output instead, by including the --xml parameter. mysqldump -h hostname -u userid --password --xml dbname > backup.xml and to compress the file with a pipe to gzip mysqldump -h hostname -u userid --password --xml dbname | gzip > backup.xml.gz

Remember to also backup the file system components of the wiki that might be required, eg. images, logo, and extensions.

Running mysqldump with Cron
Cron is the time-based job scheduler in Unix-like computer operating systems. Cron enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates.

A sample command that you may run from a crontab may look like this:  nice -n 19 mysqldump -u $USER --password=$PASSWORD $DATABASE -c | nice -n 19 gzip -9 > ~/backup/wiki-$DATABASE-$(date '+%Y%m%d').sql.gz

The  lowers the priority of the process.

Use valid values for $USER, $PASSWORD, and $DATABASE. This will write a backup file with the weekday in the filename so you would have a rolling set of backups. If you want to save the files and extensions as well, you might want to use this one.

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

Tables
Under close examination one finds that some of the tables dumped have various 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 the saving in disk space (for example, on a large wiki where restoration speed is paramount).

See a mailing list thread about the topic.

Latin-1 to UTF-8 conversion
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
See Manual:SQLite

phpMyAdmin
Turn your wiki to read only by adding  to LocalSettings.php.

Open the browser to your phpadmin link, login, choose the wiki database. (Check LocalSettings.php if you're not sure). 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. Then click on GO and save the backup file.

Remove  from LocalSettings.php

Remember to also backup the file system components of the wiki that might be required, eg. images, logo, and extensions.

File system
MediaWiki stores other components of the wiki in the file system where this is more appropriate than insertion into the database, for example, site configuration files (LocalSettings.php, AdminSettings.php), image files (including deleted images, thumbnails and rendered math and SVG images, if applicable), skin customisations, extension files, etc.

The best method to back these up is to place them into an archive file, such as a .tar</tt> file, which can then be compressed if desired. On Windows, applications such as WinZip or 7-zip can be used if preferred.

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.

XML dump
It is also a good idea to create an XML dump in addition to the database dump. XML dumps contain the content of the wiki (wiki pages with all their revisions), without the site-related data (they do not contain user accounts, image metadata, logs, etc). XML dumps are independent of the database structure, and can be imported into future (and even past) versions of MediaWiki. They are also less likely to cause problems with character encoding, and can readily be processed by third party tools, which makes them a good fallback should your main database dump become unusable, and also as a means of redistributing content en masse.

To create an XML dump, use the command-line tool dumpBackup.php</tt>, located in the maintenance</tt> directory of your MediaWiki installation. Run the command as php dumpBackup.php</tt> without any arguments to display a brief description of the syntax. You need to specify whether you want a full dump of the complete history of every page, or just the current contents of each page. Prior to MediaWiki 1.16: If an attempt to use  fails with a message about insufficient  permissions, ensure that you have a properly configured   file. Instructions on creating the file are at Manual:AdminSettings.php.

You can also create an XML dump for a specific set of pages online, using Special:Export, although attempting to dump large quantities of pages through this interface will usually time out.

To import an XML dump into a wiki, use the command-line tool importDump.php</tt>. For a small set of pages, you can also use the Special:Import page via your browser (by default, this is restricted to the sysop group). As an alternative to dumpBackup.php</tt> and importDump.php</tt>, you can use MWDumper, which is faster, but requires a Java runtime environment.

See Manual:Importing XML dumps for more information.

Without shell access to the server
If you have no shell access, then use the WikiTeam Python script dumpgenerator.py from a DOS, Unix or Linux command-line. To run the script see the WikiTeam tutorial.

See also Data dumps.

Scripts

 * Unofficial backup script by User:Duesentrieb; creates a backup of all files, a database dump, and an xml dump.
 * Unofficial backup script by User:Duesentrieb, User:Kaotic added the ability for the script to place the wiki into read only mode during the database dump.
 * Unofficial backup script by User:Duesentrieb, User:Megam0rf added a few lines to circumvent Kaotic's problem with.
 * Unofficial backup script by User:Duesentrieb, User:Robkam set option for default character-set to binary, and other minor tweaks.
 * Unofficial backup script by Flominator; creates a backup of all files and the database, with optional backup rotation.
 * User:Darizotas/MediaWiki Backup Script for Windows - a script for backing up a Windows MediaWiki install. Note: Has no restore feature.
 * Unofficial web-based backup script, mw_tools, by Wanglong (allwiki.com); you can use it to back up your database, or use the backup files to recover the database, the operation is very easy.
 * 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 WikiTeam tools (see some saved wikis)
 * Fullsitebackup
 * Another backup script that: dumps DB, files, 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. Usage: