Backup MediaWiki
A Guide to Using MediaWiki in a Hosted Environment
An instructional website by the developer of mh370wiki.net - a MediaWiki site about Malaysia Airlines Flight MH370.
How to Backup MediaWiki
Two steps are required:-
Make a copy of the installation directory. This will include the file LocalSettings.php with the site configuration, the current files used by MediaWiki, and all of the installed Extensions.
It will not include the database, so Step 2 is required.
Make a copy of the current database.
Check that the new database is functional.
Note: An alternative is to Export the database. To use or restore it, the database can be Imported. These processes are menu options in phpMyAdmin.
Step 1: Copy the Installation Directory
The installation directory for a MediaWiki-based website is typically in a sub-directory of /public_html, for example:-
/public_html/website folder/w/installation files
A copy should be placed in a directory which is not itself a sub-directory of public_html, so create the destination first.
From cPanel, open File Manager and highlight the /home/folder and from the top menu select +Folder. Enter a suitable name, for example MyBackups.
In File Manager navigate to the /public_html and click on it to display a directory listing. Select the website folder, and then click on Copy in the top menu.
A dialogue box will request Enter the file path that you want to copy this file to: but typically anticipates a subdirectory of /home/public_html but that is not what you want.
So replace the /public_html with the correct destination, for example /MyBackups. Click on the button Copy Files.
Navigate to your backup directory to check that the files were copied to your destination folder.
Note that this instruction means the backup has also included files in the root directory such as .htaccess, robots.txt, your favicon, the sitemap.xml file and the search engine files. Plus everything in the /w directory.
Step 2: Copy the Database
Identify the database used by your website by locating the variable $wgDBname in LocalSettings.php.
Then, in cPanel navigate to Databases and click on phpMyAdmin.
The left column is populated with a list of databases. Select the database you intend to copy.
The main part of the screen is filled with data relating to the database content. Ignore all of that and focus on the menu at the top:-
Click on Operations.
Scroll down to the section Copy database to:-
Enter the name for database backup. The database name may be prefixed with your user name. Add a meaningful descriptor such as the site name, date etc., separated by the underscore character_ (don't use spaces).
Leave all the options as default (like the image above), and click on Go.
If you refresh the screen your new database should be listed in the left column.
Step 3: Check the Database
A simple way to check that the backup is usable, is to change the value of $wgDBname in LocalSettings.php.
Comment the current line, add a new line with $wgDBname='your new database'; and save LocalSettings.php.
However, the website won't load and will look broken. Don't panic. There's another step which is actually best to do first:-
Before the database can be used, you need to add a user.
In cPanel navigate to Databases and click on Manage My Databases.
Scroll down to the section Add User To Database.
Select the user for the backup copy, simplest if it is the same as $wgDBuser for the original database, select the new database, and click Add.
The website should now be operational and use the backup of your original database.
Hint
If you continue to use the new database, then the original database becomes the backup. You know the 'backup' will be functional because that was what the website was using. So it is safe to keep that as the backup. And if the website is operational with the 'new' database then you could just keep using it.
This strategy just requires a bit of planning for the naming convention to use for this and subsequent versions.
Try to avoid changing the name of a database. See this warning:-
Articles which relate to MediaWiki backup
Articles which relate to MediaWiki backup are included in Category:Backup.
The CategoryTree Extension enables a listing of relevant sub-categories and pages:-
Links
- Manual:Backing up a wiki
- Some aspects of this Manual may be difficult to follow in a hosted environment.
https://www.mediawiki.org/wiki/Manual:Backing_up_a_wiki - Manual:Restoring a wiki from backup
- https://www.mediawiki.org/wiki/Manual:Restoring_a_wiki_from_backup