Difference between revisions of "Backup and Restore"
Line 1: | Line 1: | ||
=Introduction= | =Introduction= | ||
To ensure this MediaWiki's content will not be lost, we created a set of script and put it in $wgResourceBase's extensions/BackupAndRestore directory. | To ensure this MediaWiki's content will not be lost<ref name="Woziak on Apple">{{:Video/Steve Jobs never understood the computer part: Wozniak - ET Exclusive}}</ref><ref extends="Woziak on Apple">[https://youtu.be/r98HTEjmkDY?t=174 The standard question Wozniak always asks his students:...]</ref>, we created a set of script and put it in $wgResourceBase's extensions/BackupAndRestore directory. | ||
The main challenge is to ensure both textual data and binary files are backed up and restored. There are four distinct steps: | The main challenge is to ensure both textual data and binary files are backed up and restored. There are four distinct steps: |
Revision as of 13:33, 11 February 2022
Introduction
To ensure this MediaWiki's content will not be lost[1]Cite error: Invalid <ref>
tag; invalid names, e.g. too many, we created a set of script and put it in $wgResourceBase's extensions/BackupAndRestore directory.
The main challenge is to ensure both textual data and binary files are backed up and restored. There are four distinct steps:
- Official Database Backup Tools
- Official Media File Backup Tools
- Restoring Binary Files
- Restoring SQL Data
It is necessary to study the notion File Backend[2] for Mediawiki: such as CopyFileBackend.php.
For specific data loading scripts, please see:ImportTextFiles.php
Database Backup
For textual data backup, the fastest way is to use "mysqldump". The more detailed instructions can be found in the following link: [3]
To backup all the uploaded files, such as images, pdf files, and other binary files, you can reference the following Stack Overflow answer[4]
In the PKC docker-compose configuration, the backup file should be dumped to /var/lib/mysql
for convenient file transfer on the host machine of Docker runtime.
Example of the command to run on the Linux/UNIX shell:
mysqldump -h hostname -u userid -p --default-character-set=whatever dbname > backup.sql
For running this command in PKC's docker implementation, one needs to get into the Docker instance using something like:
docker exec -it pkc-mediawiki-1 /bin/bash (pkc-mediawiki-1
may be replace byxlp_mediawiki
)
Whem running this command on the actual database host machine, hostname
can be omitted, and the rest of the parameters are explained below:
mysqldump -uwikiuser
-pPASSWORD_FOR_YOUR_DATABASE
my_wiki
> backup.sql (note that you should NOT leave a space between -p and the passoword data)
Substituting hostname, userid, whatever, and dbname as appropriate. 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
, whatever may be found under $wgDBTableOptions
, where it is listed after DEFAULT CHARSET=
. If whatever 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 Manual:$wgDBpassword in LSP).
For your convenience, the following instruction will compress the file as it is being dumped out.
mysqldump -h hostname -u userid -p dbname | gzip > backup.sql.gz
Dump XML file
One may use dumpBackup.php to back up textual content into a single XML file. Make sure that the following command is run at the /var/www/html
directory.
php maintenance/dumpBackup.php --full --quiet > ./images/yourFileName.xml
Media File Backup
Before running the PHP maintenance script dumpUploads.php, you must first create a temporary working directory:
mkdir /tmp/workingBackupMediaFiles
It is common to have files not being dumped out, due to errors caused by escape characters in File names. This will be resolved in the future.
You must first go to the proper directory, in the case of standard PKC configuration, you must make sure you launch the following command at this location /var/www/html
:
php maintenance/dumpUploads.php | sed -e '/\.\.\//d' -e "/'/d" | xargs --verbose cp -t /tmp/MediaFiles
Note that the second filtering expression tries to eliminate files with '
character in the file names. After dumping all the files to the MediaFiles
directory, make sure that you check whether there are files missing.
Then, compress the file in a zip directory.
zip -r ~/UploadedFiles_date_time.zip /tmp/MediaFiles
Remember to remove the temporary files and its directory.
rm -r /tmp/MediaFiles
It is very useful to learn more about xargs and sed Unix commands.
Restoring Binary Files
Loading binary files to MediaWiki, one must use a maintenance script in the /maintenance directory. This is the command line information. It needs to be launched in the container that runs MediaWiki instance.
Load images from the UploadedFiles location. In most cases, the variable $ResourceBasePath
string can be replaced by /var/www/html
.
cd $ResourceBasePath php $ResourceBasePath/maintenance/importImages.php $ResourceBasePath/images/UploadedFiles/
After all files are uploaded, one should try to run a maintenance scrip on the server that serves Mediawiki service:
php $ResourceBasePath/maintenance/rebuildImages.php
For more information, please refer to MediaWiki's documentation on MW:Manual:rebuildImages.php.
Restoring SQL Data
The following instruction should be launched in the host (through docker exec or kubectl exec -it command) of the container that hosts the mariadb/mysql service.
mysql -u $DATABASE_USER -p $DATABASE_NAME < BACKUP_DATA.sql
If the file is very large, it might have been compressed in to gz
or tar.gz
form. Then, just use the piped command to first uncompress it and directly send it to msql
program for data loading.
gunzip -c BACKUP_DATA.sql.gz | mysql -u $DATABASE_USER -p $DATABASE_NAME
Load XML file
One may use importDump.php to restore textual content from a single XML file. Make sure that the following command is run at the /var/www/html
directory.
php maintenance/importDump.php < yourFileName.xml
References
- ↑ Wozniak, Steve (Feb 26, 2018). Steve Jobs never understood the computer part: Wozniak - ET Exclusive. local page: The Economic Times.
- ↑ MediaWiki's File backend design considerations
- ↑ MediaWiki:Manual:Backing up a wiki
- ↑ Stack Overflow: Exporting and Importing Images in MediaWiki