Mediawiki notes on upgrading/Mediawiki backup

From Bjoern Hassler's website
Jump to: navigation, search

WARNING - This hasn't been well tested yet! The instructions on Mediawiki notes on upgrading are well tested, so if in doubt, read those!

Some quick notes on mediawiki backup, also needed if you want to move an entire mediawiki.

Before you do this, read Mediawiki notes on upgrading regarding the latin1 issue, and select the appropriate commands below!

Improvements: Automatically get dbuser and password from AdminSettings.php.

[ View code | Edit code | Download]
print "Make sure that you have AdminSettings.php set up properly!";

if ($#ARGV != 1) {
print("                                                                                                                                                                                                         
Please provide two arguments!                                                                                                                                                                                   
                                                                                                                                                                                                                
$0 DBUSER WIKIDIR                                                                                                                                                                                               
                                                                                                                                                                                                                
");
exit;
};

($user,$wikidir) = @ARGV;

if (!-e "$wikidir/AdminSettings.php") {
    print "No AdminSettings in sight!";
    exit;
};

($date = `date '+%Y%m%d_%H%M%S'`) =~ s/\n//;
$dir = "wiki_backup_" . $date;

if (-e $dir) {
    exit("$dir exists.");
};
mkdir("$dir");
mkdir("$dir/database");
print "Database backup:\n";
system "mysqldump -u $user -p --all-databases  -c | gzip > $dir/database/MYSQL_BACKUP_$dat.txt.gz;                                                                                                              
mysqldump -u $user -p --all-databases -c --default-character-set=latin1 | gzip > $dir/database/MYSQL_BACKUP_latin1_$date.txt.gz;                                                                                
mysqldump -u $user -p --all-databases -c --xml | gzip > $dir/database/MYSQL_BACKUP_XML_$date.xml.gz;                                                                                                            
mysqldump -u $user -p --all-databases -c --xml --default-character-set=latin1 | gzip > $dir/database/MYSQL_BACKUP_XML_latin1_$date.xml.gz;                                                                      
";
mkdir("$dir/pages");
print "Page dump:\n";
system "php wiki/maintenance/dumpBackup.php --full | gzip > $dir/pages/AllWikiPages_$date.gz";
print "Wiki backup:\n";
system "cp -rip $wikidir $dir";
print "Making tar archive:\n";
system "tar cf wiki_backup_$date.tar $dir; gzip wiki_backup_$date.tar";
system "chmod go-rx wiki_backup_$date.tar.gz $dir";

print "Please archive                                                                                                                                                                                           
    wiki_backup_$date.tar.gz                                                                                                                                                                                    
somewhere. You can now delete the temporary dir:                                                                                                                                                                
    $dir                                                                                                                                                                                                        
                                                                                                                                                                                                                
Make sure you obscure your AdminSettings.php (including the copy in the backup!)                                                                                                                                
";

The file wiki_backup.tgz now contains all you need to completely reinstall the wiki elsewhere, or just to put the pages/images onto a different wiki.