Difference between revisions of "Backup mediawiki"
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Category:Website]] | [[Category:Website]] | ||
[[Category:Development]] | [[Category:Development]] | ||
+ | |||
MediaWiki backup is composed of: | MediaWiki backup is composed of: | ||
* Database backup | * Database backup | ||
* Files backup | * Files backup | ||
+ | |||
+ | All the content of the blog (articles, structure, navigation, ...) is saved in database. Only the images, extensions and engine are in files. | ||
− | + | You can find this backup script on my github: https://github.com/guihome-diaz/IT/tree/master/backup_mediawiki | |
Line 81: | Line 84: | ||
+ | // ############################## | ||
+ | // Create backup directory | ||
+ | // ############################## | ||
+ | $today = date("Y-m-d"); | ||
+ | // Control the destination folder | ||
+ | if(!is_dir($dstFolder)) { | ||
+ | die('Aborting backup process!! Backup invalid path specified'); | ||
+ | } | ||
+ | // Check if the parent directory is writeable | ||
+ | if(!is_writable($dstFolder)) { | ||
+ | die('Aborting backup process!! Unable to create directory, permissions denied.'); | ||
+ | } | ||
+ | // Create folder for new backups | ||
+ | $dstFolder .= "/" . $today; | ||
+ | if(mkdir($dstFolder, 0777, true) === false) { | ||
+ | die('Aborting backup process!! Problems creating directory.'); | ||
+ | } | ||
+ | |||
// ############################## | // ############################## | ||
// DB backup | // DB backup | ||
Line 115: | Line 136: | ||
?> | ?> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | =User interaction= | ||
+ | |||
+ | For the user interaction, I'm using a simple HTML5 + JavaScript page. | ||
+ | You can find everything on my github. |
Latest revision as of 22:45, 18 January 2015
MediaWiki backup is composed of:
- Database backup
- Files backup
All the content of the blog (articles, structure, navigation, ...) is saved in database. Only the images, extensions and engine are in files.
You can find this backup script on my github: https://github.com/guihome-diaz/IT/tree/master/backup_mediawiki
Contents
Backup principle
As this blog is running on a shared webserver, I do not have console access. Therefore I have to use PHP, HTML and JavaScript only. No shell script or Linux command.
This is the backup principle:
Server backup
Useful libraries
- Database backup library: backup script
- Zip file library: recursive script
Database backup
$backupDatabase = new Backup_Database($dbHost, $dbUser, $dbPassword, $dbName);
$status = $backupDatabase->backupTables($dbTables, $dstFolder);
if ($status) {
// Success case
} else {
// Error case
}
Folder compression
$z1=new recurseZip();
echo $z1->compress($srcWiki,$dstFolder);
Complete backup script
You need to adjust the *** settings *** variables.
<?php
include('recurseZip.php');
include('backup_mysql_db.php');
// ##############################
// Settings
// ##############################
// ***** Output folder *****
$dstFolder = "/home/...";
// ***** Database settings *****
$dbName = 'myDb';
$dbHost = 'dbServer';
$dbUser = 'dbUser';
$dbPassword = 'secret';
// $dbTables = '*';
$dbTables = "wiki_archive,wiki_category,wiki_categorylinks,wiki_change_tag,wiki_externallinks,wiki_external_user,wiki_filearchive,wiki_hitcounter,wiki_image,wiki_imagelinks,wiki_interwiki,wiki_ipblocks,wiki_iwlinks,wiki_job,wiki_l10n_cache,wiki_langlinks,wiki_logging,wiki_log_search,wiki_module_deps,wiki_msg_resource,wiki_msg_resource_links,wiki_objectcache,wiki_oldimage,wiki_page,wiki_pagelinks,wiki_page_props,wiki_page_restrictions,wiki_protected_titles,wiki_querycache,wiki_querycachetwo,wiki_querycache_info,wiki_recentchanges,wiki_redirect,wiki_revision,wiki_searchindex,wiki_sites,wiki_site_identifiers,wiki_site_stats,wiki_tag_summary,wiki_templatelinks,wiki_text,wiki_transcache,wiki_updatelog,wiki_uploadstash,wiki_user,wiki_user_former_groups,wiki_user_groups,wiki_user_newtalk,wiki_user_properties,wiki_valid_tag,wiki_watchlist";
// ***** Folders to backup *****
$srcWiki = "/home/...";
$srcWikiUploadFiles = "/home/...";
// ##############################
// Create backup directory
// ##############################
$today = date("Y-m-d");
// Control the destination folder
if(!is_dir($dstFolder)) {
die('Aborting backup process!! Backup invalid path specified');
}
// Check if the parent directory is writeable
if(!is_writable($dstFolder)) {
die('Aborting backup process!! Unable to create directory, permissions denied.');
}
// Create folder for new backups
$dstFolder .= "/" . $today;
if(mkdir($dstFolder, 0777, true) === false) {
die('Aborting backup process!! Problems creating directory.');
}
// ##############################
// DB backup
// ##############################
$log = '';
$backupDatabase = new Backup_Database($dbHost, $dbUser, $dbPassword, $dbName);
$status = $backupDatabase->backupTables($dbTables, $dstFolder);
if ($status) {
$log .= "<p>";
$log .= "<strong>Database backup complete!</strong>";
$log .= "</p>";
} else {
$log .= "<p>";
$log .= "<strong><span style='font-weight:bold; color:red'> Database backup failure </span></strong>";
$log .= "<br> Please check the logs";
$log .= "</p>";
}
// ##############################
// Files backup
// ##############################
// Backup mediawiki
$z1=new recurseZip();
echo $z1->compress($srcWiki,$dstFolder);
// Backup wiki related files
$z2=new recurseZip();
echo $z2->compress($srcWikiUploadFiles,$dstFolder);
$log .= "<p>";
$log .= "<strong>Files backup complete!</strong>";
$log .= "</p>";
echo $log;
?>
User interaction
For the user interaction, I'm using a simple HTML5 + JavaScript page. You can find everything on my github.