https://www.wplug.org/mediawiki/api.php?action=feedcontributions&user=Seputarsoftware&feedformat=atomWPLUG - User contributions [en]2024-03-29T15:05:42ZUser contributionsMediaWiki 1.23.15//www.wplug.org/wiki/Simple_MediaWiki_BackupSimple MediaWiki Backup2012-03-11T13:01:24Z<p>Seputarsoftware: </p>
<hr />
<div>[[Category:Internet Committee]]<br />
<br />
MediaWiki is one of my favorite pieces of software. Not because its code is elegant (''LocalSettings.php? bleh''), or because it has such a succinct but useful set of features (''skins!''). No, the thing about MediaWiki is that it does a great job of being a wiki.<br />
<br />
I'm sure there has to be a better piece of wiki software out there, but I've not yet found it.<br />
<br />
So, in the interest helping out other MediaWiki aficionados, here are three scripts which I use when I'm doing upgrades. This is only half the battle (the backing up half.)<br />
<br />
<br />
==Backup Scripts==<br />
<br />
===Notes===<br />
* These scripts are designed for use with mysql as the backend to the wiki. Other databases require the scripts to be adapted appropriately.<br />
* There are redundancies in running [[#backupAll.bash|backupAll.bash]]. (hint: the databases). Why? Because when I run backupAll.bash, I want to backup everything. I want to backup the mysql server. I want to backup the wiki. There could be other things in backupAll.bash, but the listing here only includes the wiki related stuff. But, each backup should be atomic. So, [[#backupWiki.bash|backupWiki.bash]] should backup the wiki and its dependents. [[#backupDB.bash|backupDB.bash]] should backup the database. I don't worry that in there the database is getting backed up (or dumped, more precisely) twice. Better twice than not at all.<br />
* So, in regards to the above bullet point, you can run [[#backupWiki.bash|backupWiki.bash]] by itself and have your wiki backed up.<br />
* Why backup? Because with a backup in hand, you can safely upgrade your wiki to the latest version, which means you install cool [http://www.mediawiki.org/wiki/Extensions extensions.]<br />
<br />
===backupAll.bash===<br />
#!/bin/bash<br />
<br />
export scriptDir=/root<br />
<br />
if [ -z $1 ]<br />
then<br />
echo "Invalid backup label."<br />
exit 1;<br />
fi<br />
<br />
echo "Backing DB up to label $1"<br />
echo "_________________________"<br />
$scriptDir/backupDB.bash $1<br />
echo ""<br />
echo ""<br />
<br />
<br />
<br />
echo "Backing Wiki up to label $1"<br />
echo "_________________________"<br />
$scriptDir/backupWiki.bash $1<br />
echo ""<br />
echo ""<br />
<br />
<br />
===backupDB.bash===<br />
#!/bin/bash<br />
<br />
if [ -z $1 ]<br />
then<br />
echo "Invalid backup label."<br />
exit 1;<br />
fi<br />
<br />
<br />
export dbUser=root<br />
export password=supersecret<br />
export mysqlSQL=mysql.$1.sql<br />
export wikidbSQL=wikidb.$1.sql<br />
export mysqlBZ2=$mysqlSQL.bz2<br />
export wikidbBZ2=$wikidbSQL.bz2<br />
<br />
<br />
<br />
echo "Creating dump of mysql..."<br />
mysqldump -u $dbUser --password=$password mysql > $mysqlSQL<br />
<br />
echo "Creating dump of wikidb..."<br />
mysqldump -u $dbUser --password=$password wikidb > $wikidbSQL<br />
<br />
<br />
<br />
if [ -f $mysqlBZ2 ]<br />
then<br />
echo "Removing old backups of $mysqlBZ2..."<br />
rm -r $mysqlBZ2<br />
fi<br />
<br />
if [ -f $wikidbBZ2 ]<br />
then<br />
echo "Removing old backups of $wikidbBZ2..."<br />
rm -r $wikidbBZ2<br />
fi<br />
<br />
<br />
echo "Zipping up $mysqlBZ2..."<br />
bzip2 $mysqlSQL<br />
echo "Zipping up $wikidbBZ2..."<br />
bzip2 $wikidbSQL<br />
<br />
===backupWiki.bash===<br />
#!/bin/bash<br />
<br />
if [ -z $1 ]<br />
then<br />
echo "Invalid backup label."<br />
exit 1;<br />
fi<br />
<br />
export destFile=wikiBackup.$1.tar.bz2<br />
export temp=/tmp<br />
export backupWiki=backupWiki<br />
export tempDir=$temp/backupWiki<br />
export srv=/srv<br />
export mediaWiki=mediawiki<br />
export mediaWikiPath=$srv/$mediaWiki<br />
export wikiDB=wikidbB<br />
export password=supersecret<br />
<br />
<br />
# Remove the temporary directory if it exists.<br />
<br />
if [ -d $tempDir ] <br />
then<br />
echo "Removing temporary directory $tempDir..."<br />
rm -rf $tempDir<br />
fi<br />
<br />
<br />
# If the backup file exists, delete it.<br />
<br />
if [ -f $destFile ] <br />
then<br />
echo "Removing old backup file $destFile..."<br />
rm $destFile<br />
fi<br />
<br />
<br />
# Create the temporary directory.<br />
<br />
echo "Creating temporary directory $tempDir..."<br />
mkdir $tempDir<br />
<br />
<br />
# Get the database dumps.<br />
<br />
echo "Creating database dumps..."<br />
mysqldump -u root --password=$password mysql > $tempDir/mysql.sql<br />
mysqldump -u root --password=$password $wikiDB > $tempDir/wikidb.sql<br />
<br />
<br />
# Get the important files from mediawiki.<br />
<br />
echo "Creating backups of settings php files and vhost..."<br />
cp /etc/apache2/vhosts.d/wiki.conf $tempDir<br />
cp $mediaWikiPath/LocalSettings.php $tempDir<br />
cp $mediaWikiPath/AdminSettings.php $tempDir<br />
<br />
<br />
# Backup the mediawiki directory.<br />
<br />
echo "Backing up mediawiki directory..."<br />
tar --create --bzip2 --directory=$srv --file=$tempDir/mediawiki.tar.bz2 $mediaWiki <br />
<br />
<br />
# Create the master backup.<br />
<br />
echo "Creating master backup $destFile from $tempDir..."<br />
tar --create --bzip2 --directory=$temp --file=$destFile $backupWiki <br />
<br />
<br />
# Remove the temporary directory if it exists.<br />
<br />
if [ -d $tempDir ]<br />
then<br />
echo "Removing temporary directory $tempDir..."<br />
rm -rf $tempDir<br />
fi<br />
<br />
<br />
===What a backup entails...===<br />
yoda:~ # ./backupAll.bash test<br />
Backing DB up to label test<br />
_________________________<br />
Creating dump of mysql...<br />
Creating dump of wikidb...<br />
Removing old backups of mysql.test.sql.bz2...<br />
Removing old backups of wikidb.test.sql.bz2...<br />
Zipping up mysql.test.sql.bz2...<br />
Zipping up wikidb.test.sql.bz2...<br />
<br />
<br />
Backing Wiki up to label test<br />
_________________________<br />
Removing temporary directory /tmp/backupWiki...<br />
Creating temporary directory /tmp/backupWiki...<br />
Creating database dumps...<br />
Creating backups of settings php files and vhost...<br />
Backing up mediawiki directory...<br />
Creating master backup wikiBackup.test.tar.bz2 from /tmp/backupWiki...<br />
Removing temporary directory /tmp/backupWiki...<br />
<br />
[[Category:Internet Committee]]<br />
<br />
[http://update-seputar-software.blogspot.com/2011/12/ultrabook-notebook-tipis-harga-murah.html Ultrabook Notebook Tipis Harga Murah Terbaik]</div>Seputarsoftware