Difference between revisions of "Backup mediawiki"

(Created page with "Category:Website Category:Development MediaWiki backup is composed of: * Database backup * Files backup All the content of the blog (articles, structure, navigation...")
 
 
(3 intermediate revisions 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.
  
  
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 17: Line 20:
  
 
This is the backup principle:
 
This is the backup principle:
 +
 +
[[File:Wiki-backup-process.png|none|Backup mediaWiki]]
  
  
Line 30: Line 35:
 
'''Database backup'''
 
'''Database backup'''
  
<syntaxhighlight lang="php5">
+
<syntaxhighlight lang="php">
 
$backupDatabase = new Backup_Database($dbHost, $dbUser, $dbPassword, $dbName);
 
$backupDatabase = new Backup_Database($dbHost, $dbUser, $dbPassword, $dbName);
 
$status = $backupDatabase->backupTables($dbTables, $dstFolder);
 
$status = $backupDatabase->backupTables($dbTables, $dstFolder);
Line 43: Line 48:
 
'''Folder compression'''
 
'''Folder compression'''
  
<syntaxhighlight lang="php5">
+
<syntaxhighlight lang="php">
 
$z1=new recurseZip();
 
$z1=new recurseZip();
 
echo $z1->compress($srcWiki,$dstFolder);
 
echo $z1->compress($srcWiki,$dstFolder);
Line 53: Line 58:
 
You need to adjust the ''*** settings ***'' variables.  
 
You need to adjust the ''*** settings ***'' variables.  
  
<syntaxhighlight lang="php5">
+
<syntaxhighlight lang="php">
 
<?php
 
<?php
 
include('recurseZip.php');
 
include('recurseZip.php');
Line 79: 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 113: 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 23: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


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:

Backup mediaWiki


Server backup

Useful libraries


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.