Manual:Mencadangkan wiki

This page is a translated version of the page Manual:Backing up a wiki and the translation is 36% complete.
Outdated translations are marked like this.

Sangat penting untuk membuat cadangan wiki Anda (data dan berkasnya) secara rutin. Pada halaman ini akan dijelaskan secara umum bagaimana melakukan cadangan data wiki Anda pada MediaWiki; Untuk kebutuhan yang lebih spesifik misalnya cadangan secara periodik, Anda perlu melakukan penyesuaian tersendiri.

Help:Export adalah cara yang cepat dan mudah untuk menyimpan semua halaman di wiki Anda.

Tinjauan

MediaWiki menyimpan data pada dua lokasi, yaitu:

Database
Halaman berikut isinya, pengguna berikut preferensinya, metadata, indeks pencarian, dsb.
File System
Berkas konfigurasi perangkat lunak, skin kustomisasi, ekstensi, gambar (termasuk di dalamnya gambar yang dihapus), dsb.

Pertimbangkan untuk membuat konfigurasi Wiki menjadi read-only saja sebelum melakukan backup - lihat $wgReadOnly . Hal ini akan memastikan data-data dalam proses backup akan konsisten.

Transfer berkas

Anda harus memilih metode untuk mentransfer berkas dari peladen letak mereka.

  • Data yang tidak pribadi bisa diterbitkan di archive.org dan/atau di direktori dumps/ peladen web Anda.
  • SCP (atau WinSCP), SFTP/FTP atau protokol transfer apa pun yang Anda mau.
  • Perusahaan hosting-nya mungkin menyediakan antarmuka manajer berkas lewat penjelajah web; periksa ke penyedia Anda.

Basis data

Mayoritas data kritikal wiki tersimpan di dalam database, berarti dapat disimpulkan bahwa umumnya proses backup akan cukup sederhana. Saat menggunakan MySQL atau MariaDB backend default, database dapat dibuang ke dalam file skrip yang nantinya dapat digunakan untuk membuat ulang database dan semua data di dalamnya dari awal. If your wiki is currently offline, its database can be backed up by simply copying the database file.

Saat menggunakan default MySQL atau MariaDB backend, database dapat dibuang ke dalam file skrip yang nantinya dapat digunakan untuk membuat ulang database dan semua data di dalamnya dari awal.

MySQL

Automysqlbackup

Lihat paketnya di Debian:

$ 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.
[...]

Pasang paketnya:

# apt install automysqlbackup

Semua basis data Anda akan disimpan di /var/lib/automysqlbackup/:

$ 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

Pencadangan manual:

# automysqlbackup

Mengembalikan basis data:

gunzip < /var/lib/automysqlbackup/weekly/my_wiki/my_wiki_week.18.2016-05-07_15h32m.sql.gz|mysql -uUSER -pPASSWORD my_wiki

Untuk distribusi lainnya, lihat di Sourceforge.

Mysqldump dari baris perintah

Cara paling mudah untuk membuat file dump dari database yang ingin Anda buat cadangannya adalah dengan menggunakan alat dump MySQL standar mysqldump dari baris perintah. Pastikan parameternya benar atau Anda mungkin mengalami kesulitan memulihkan database. Tergantung pada ukuran database, mysqldump dapat memakan banyak waktu.

Pertama masukkan baris berikut ke LocalSettings.php

$wgReadOnly = 'Dumping Database, Access will be restored shortly';

ini dapat dihapus segera setelah dump selesai.

Contoh perintah untuk dijalankan di shell Linux/UNIX:

mysqldump -h hostname -u userid -p --default-character-set=charset dbname > backup.sql

Mengganti hostname, userid, whatever, dan dbname yang sesuai. Keempatnya dapat ditemukan di file LocalSettings.php (LSP) Anda. nama host dapat ditemukan di bawah $wgDBserver ; secara default itu adalah localhost. userid dapat ditemukan di bawah $wgDBuser , apapun dapat ditemukan di bawah $wgDBTableOptions , jika dicantumkan setelah DEFAULT CHARSET=. Jika whatever tidak ditentukan, mysqldump kemungkinan akan menggunakan default utf8, atau jika menggunakan MySQL versi lama, latin1. While dbname may be found under $wgDBname . Setelah menjalankan baris ini dari baris perintah mysqldump akan meminta kata sandi server (yang dapat ditemukan di bawah Manual:$wgDBpassword di LSP).

Lihat mysqldump untuk daftar lengkap parameter baris perintah.

The output from mysqldump can instead be piped to gzip, for a smaller output file, as follows

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

A similar mysqldump command can be used to produce XML output instead, by including the --xml parameter.

mysqldump -h hostname -u userid -p --xml dbname > backup.xml

dan untuk memampatkan file dengan saluran ke gzip

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.

Additional Mysqldump Options
Pilihan Deskripsi
--default-character-set Tentukan set karakter default
--no-tablespaces Jangan menulis pernyataan CREATE LOGFILE GROUP atau CREATE TABLESPACE dalam output
--single-transaction Issue a BEGIN SQL statement before dumping data from server
--triggers Pemicu dump untuk setiap tabel yang dibuang
--routines Buang rutinitas yang tersimpan (prosedur dan fungsi) dari database yang dibuang
--events Buang events dari database yang dibuang
--add-drop-table Tambahkan pernyataan DROP DATABASE sebelum setiap pernyataan CREATE DATABASE
--create-options Sertakan opsi tabel khusus MySQL dalam pernyataan CREATE TABLE
--extended-insert Gunakan sintaksis INSERT multi-baris

Jika Anda tidak menggunakan --single-transaction, maka Anda harus mempertimbangkan untuk menggunakan --lock-tables dan opsi --add-locks.

Karena perubahan yang tak terduga dalam versi MySQL 5.7.41 dan 8.0.32 pada Februari 2023, opsi transaksi --single mengharuskan pengguna cadangan untuk memiliki hak istimewa RELOAD atau FLUSH_TABLES. Masalah ini diperbaiki dalam versi MySQL 5.7.42 dan 8.0.33. See MySQL Bug 109685 and Ubuntu Bug 2003866 for details.

Remember to backup the additional file system components used by the wiki that might be required during a restore, like images, logo, skins 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 nice -n 19 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.

  Peringatan Jangan mencoba melakukan backup basisdata MediaWiki menggunakan mysqlhotcopy. Format tabel yang digunakan MediaWiki tidak dapat dibackup menggunakan perkakas ini. Tidak akan ada pemberitahuan mengenai kegagalan backup menggunakan perkakas ini!

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

Tabel

Beberapa dari tables yang dibuang memiliki derajat temporal yang berbeda. Jadi untuk menghemat ruang disk (tidak hanya melakukan gzip), walaupun tabel tersebut perlu ada dalam dump yang baik, data mereka tidak. Namun, dalam kondisi tertentu kerugian dari harus membangun ulang semua data ini adalah dapat lebih penting daripada menghemat ruang disk (misalnya, pada wiki yang besar kecepatan restorasi menjadi penting).

Lihat arsip diskusi pada milis thread mengenai topik ini.

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

If your wiki is currently offline, its database can be backed up by simply copying the database file. Otherwise, you should use a maintenance script: php maintenance/SqliteMaintenance.php --backup-to <backup file name>, which will make sure that operation is atomic and there are no inconsistencies. If your database is not really huge and server is not under heavy load, users editing the wiki will notice nothing but a short lag. Users who are just reading will not notice anything in any case.

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";
  1. Open the browser to your phpadmin link, login, choose the wiki database.
  2. 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.
  3. Select zipped.
  4. Click on GO and save the backup file.[1]
  5. 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.

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.

Sistem berkas

MediaWiki menyimpan komponen lain dari wiki di dalam sistem berkas ketika ini lebih cocok daripada memasukkan mereka ke basis data.

Berkas yang paling penting adalah $1 dan berkas yang diunggah di direktori $2 (termasuk berkas gambar, thumbnail, dan gambar matematika dan SVG yang diberikan, jika ada).

  • LocalSettings.php
  • uploaded files in the images/ directory (including deleted files, thumbnails, and rendered math and SVG images, if applicable).

Metode yang terbaik untuk membackup berkas-berkas ini adalah dengan menempatkan mereka sebagai berkas archive seperti .tar. Bagi pengguna sistem operasi Windows, dapat menggunakan aplikasi WinZip atau 7-zip.

Untuk varian Linux, dengan asumsi wiki disimpan di /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.

Configuration files

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.

Uploaded files

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).

Cadangkan konten wiki (XML dump)

Merupakan ide yang bagus untuk membuat dump XML selain melakukan dump basisdata. Di dalam XML terdapat isi dari wiki (halaman wiki berikut dengan revisinya), tanpa data-yang-terkait (tidak terdapat akun user, metadata gambar, log, dsb). Dump XML independen terhadap struktur basisdata, dan dapat diimport ke versi MediaWiki yang lebih baru atau lebih lama.

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.

To create an XML dump, use the command-line tool dumpBackup.php , located in the maintenance directory of your MediaWiki installation. See Manual:dumpBackup.php for more details.

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 . 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).

See Manual:Importing XML dumps for more information.

Without shell access to the server

See m:Data dumps about Wikimedia database dumps.

WikiTeam3

If you have no server shell access, use Save the Web Project's WikiTeam3 Python 3 script, (full instructions are at that link).

Windows: When using --images, because NTFS does not allow characters such as :*?"<>| in filenames, some files may not be downloaded, please check the errors.log file.
Example usage
  • --curonly dumps only the latest revision of pages
  • --xml exports an XML dump, uses Special:Export by default when no other xmldump method is specified.
  • --xmlrevisions uses API:Allrevisions (MediaWiki 1.27+) xmldump method. Recommended as it's quicker and puts almost no pressure on the MediaWiki backend compared to Special:Export.
  • --images generates an image dump
  • --force generates a dump even if there is one already at Internet Archive
Public wikis
wikiteam3dumpgenerator <WIKI_URL> --xml --xmlrevisions
Private wikis
To dump a private wiki you will have to use a login that has at least read permission on the wiki.
wikiteam3dumpgenerator <WIKI_URL> --xml --xmlrevisions --force --user <USER> --pass <PASSWORD>
If that doesn't work. Login with a web browser, save the site cookies in Netscape format to cookies.txt, and add option --cookies cookies.txt

Script

With server shell access

  Peringatan Use these at your own risk. Check your wiki's LocalSettings.php for the correct character set to use, as you may need to edit the script to suit.
  • 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. Usage: 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.

Shell script - last updated 2015.

  • 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.

Without server shell access

For example your wiki is in a wikifarm , using the MediaWiki API .

  • WikiTeam's dumpgenerator Python 2 script can generate an XML dump and an image dump - last updated 2023.
  • Mediawiki Client Tools' MediaWiki Dump Generator dumpgenerator Python 3 script can generate an XML dump and an image dump - last updated 2023.
  • See above: Save the Web Project's WikiTeam3 wikiteam3dumpgenerator Python 3 script can generate an XML dump and an image dump - actively maintained in 2024.

Extensions

Lihat pula

Pranala luar