fixed bug 654497
This commit is contained in:
parent
82c84b7000
commit
0938e9d6cb
1 changed files with 66 additions and 25 deletions
|
|
@ -8,26 +8,50 @@
|
||||||
# http://www.plainblack.com info@plainblack.com
|
# http://www.plainblack.com info@plainblack.com
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
our ($webguiRoot, $mysql);
|
our ($webguiRoot);
|
||||||
$mysql = "/usr/bin/mysql";
|
|
||||||
$mysqldump = "/usr/bin/mysqldump";
|
|
||||||
$backupDir = $ARGV[0] || "/data/backups";
|
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
$webguiRoot = "..";
|
$webguiRoot = "..";
|
||||||
unshift (@INC, $webguiRoot."/lib");
|
unshift (@INC, $webguiRoot."/lib");
|
||||||
}
|
}
|
||||||
|
|
||||||
#-----------------------------------------
|
|
||||||
# NO NEED TO MODIFY BELOW THIS LINE
|
my $mysql = "/usr/bin/mysql";
|
||||||
|
my $mysqldump = "/usr/bin/mysqldump";
|
||||||
|
my $backupDir = "/data/backups";
|
||||||
|
|
||||||
|
|
||||||
if (!($^O =~ /Win/i) && $> != 0) {
|
if ($ARGV[0] ne "--doit") {
|
||||||
print "You must be the super user to use this utility.\n";
|
print "\n";
|
||||||
|
print "WebGUI Assisted Upgrade Utility\n";
|
||||||
|
print "\n";
|
||||||
|
print "There are no guarantees of any kind provided at this software. Use\n";
|
||||||
|
print "it at your own risk. Always make frequent backups of your data.\n";
|
||||||
|
print "\n";
|
||||||
|
print "NOTE: This utility will work on MySQL databases only. Any\n";
|
||||||
|
print "configs using non-MySQL databases will be skipped.\n";
|
||||||
|
print "\n";
|
||||||
|
print "By default WebGUI will use these settings to perform the\n";
|
||||||
|
print "upgrades. You may override these settings on a per site basis\n";
|
||||||
|
print "by adding the variables to each site's WebGUI config file.\n";
|
||||||
|
print "\n";
|
||||||
|
print "\tmysqlCLI = $mysql\n";
|
||||||
|
print "\tmysqlDump = $mysqldump\n";
|
||||||
|
print "\tbackupPath = $backupDir\n";
|
||||||
|
print "\n";
|
||||||
|
print "Use the following command to being the upgrade.\n";
|
||||||
|
print "\n";
|
||||||
|
print "\tperl $0 --doit\n";
|
||||||
|
print "\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!($^O =~ /^Win/i) && $> != 0) {
|
||||||
|
print "You must be the super user to use this utility.\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
use Data::Config;
|
use Data::Config;
|
||||||
use DBI;
|
use DBI;
|
||||||
use WebGUI::SQL;
|
use WebGUI::SQL;
|
||||||
|
|
@ -37,7 +61,7 @@ my ($upgrade, @files, $file, $dbh, $config, $dir, %upgrade, %config);
|
||||||
|
|
||||||
|
|
||||||
print "\nLooking for upgrade files...\n";
|
print "\nLooking for upgrade files...\n";
|
||||||
if ($^O =~ /Win/i) {
|
if ($^O =~ /^Win/i) {
|
||||||
$dir = $webguiRoot."\\docs\\upgrades\\";
|
$dir = $webguiRoot."\\docs\\upgrades\\";
|
||||||
} else {
|
} else {
|
||||||
$dir = $webguiRoot."/docs/upgrades/";
|
$dir = $webguiRoot."/docs/upgrades/";
|
||||||
|
|
@ -64,7 +88,7 @@ foreach $file (@files) {
|
||||||
|
|
||||||
|
|
||||||
print "\nGetting site configs...\n";
|
print "\nGetting site configs...\n";
|
||||||
if ($^O =~ /Win/i) {
|
if ($^O =~ /^Win/i) {
|
||||||
$dir = $webguiRoot."\\etc\\";
|
$dir = $webguiRoot."\\etc\\";
|
||||||
} else {
|
} else {
|
||||||
$dir = $webguiRoot."/etc/";
|
$dir = $webguiRoot."/etc/";
|
||||||
|
|
@ -78,40 +102,57 @@ foreach $file (@files) {
|
||||||
$config{$file}{configFile} = $dir.$file;
|
$config{$file}{configFile} = $dir.$file;
|
||||||
my $config = new Data::Config $config{$file}{configFile};
|
my $config = new Data::Config $config{$file}{configFile};
|
||||||
$config{$file}{dsn} = $config->param('dsn');
|
$config{$file}{dsn} = $config->param('dsn');
|
||||||
$config{$file}{dsn} =~ /DBI\:mysql\:(\w+).*/;
|
$config{$file}{dsn} =~ /DBI\:(\w+)\:(\w+).*/;
|
||||||
$config{$file}{db} = $1;
|
if ($1 eq "mysql") {
|
||||||
$config{$file}{dbuser} = $config->param('dbuser');
|
$config{$file}{db} = $2;
|
||||||
$config{$file}{dbpass} = $config->param('dbpass');
|
$config{$file}{dbuser} = $config->param('dbuser');
|
||||||
$dbh = DBI->connect($config{$file}{dsn},$config{$file}{dbuser},$config{$file}{dbpass});
|
$config{$file}{dbpass} = $config->param('dbpass');
|
||||||
($config{$file}{version}) = WebGUI::SQL->quickArray("select webguiVersion from webguiVersion order by dateApplied desc, webguiVersion desc limit 1",$dbh);
|
$config{$file}{mysqlCLI} = $config->param('mysqlCLI');
|
||||||
$dbh->disconnect;
|
$config{$file}{mysqlDump} = $config->param('mysqlDump');
|
||||||
|
$config{$file}{backupPath} = $config->param('backupPath');
|
||||||
|
$dbh = DBI->connect($config{$file}{dsn},$config{$file}{dbuser},$config{$file}{dbpass});
|
||||||
|
($config{$file}{version}) = WebGUI::SQL->quickArray("select webguiVersion from webguiVersion
|
||||||
|
order by dateApplied desc, webguiVersion desc limit 1",$dbh);
|
||||||
|
$dbh->disconnect;
|
||||||
|
} else {
|
||||||
|
delete $config{$file};
|
||||||
|
print "Skipping non-MySQL database.\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print "\nREADY TO BEGIN UPGRADES\n";
|
print "\nREADY TO BEGIN UPGRADES\n";
|
||||||
mkdir($backupDir);
|
|
||||||
mkdir($backupDir."/db");
|
my $notRun = 1;
|
||||||
|
|
||||||
foreach $config (keys %config) {
|
foreach $config (keys %config) {
|
||||||
|
my $clicmd = $config{$config}{mysqlCLI} || $mysql;
|
||||||
|
my $dumpcmd = $config{$config}{mysqlDump} || $mysqldump;
|
||||||
|
my $backupTo = $config{$config}{backupPath} || $backupDir;
|
||||||
|
mkdir($backupTo);
|
||||||
while ($upgrade{$config{$config}{version}}{sql} ne "") {
|
while ($upgrade{$config{$config}{version}}{sql} ne "") {
|
||||||
$upgrade = $upgrade{$config{$config}{version}}{from};
|
$upgrade = $upgrade{$config{$config}{version}}{from};
|
||||||
print "\n".$config{$config}{db}." ".$upgrade{$upgrade}{from}."-".$upgrade{$upgrade}{to}."\n";
|
print "\n".$config{$config}{db}." ".$upgrade{$upgrade}{from}."-".$upgrade{$upgrade}{to}."\n";
|
||||||
print "\tBacking up $config{$config}{db} ($upgrade{$upgrade}{from}).\n";
|
print "\tBacking up $config{$config}{db} ($upgrade{$upgrade}{from}).\n";
|
||||||
mkdir($backupDir."/db/".$config{$config}{db});
|
system($dumpcmd." -u".$config{$config}{dbuser}." -p".$config{$config}{dbpass}." --add-drop-table --databases ".$config{$config}{db}." > ".$backupTo."/".$config{$config}{db}."_".$upgrade{$upgrade}{from}.".sql");
|
||||||
system($mysqldump." -u".$config{$config}{dbuser}." -p".$config{$config}{dbpass}." --add-drop-table --databases ".$config{$config}{db}." > ".$backupDir."/db/".$config{$config}{db}."/".$upgrade{$upgrade}{from}.".sql");
|
|
||||||
print "\tUpgrading to $upgrade{$upgrade}{to}.\n";
|
print "\tUpgrading to $upgrade{$upgrade}{to}.\n";
|
||||||
system($mysql." -u".$config{$config}{dbuser}." -p".$config{$config}{dbpass}." --database=".$config{$config}{db}." < ".$upgrade{$upgrade}{sql});
|
system($clicmd." -u".$config{$config}{dbuser}." -p".$config{$config}{dbpass}." --database=".$config{$config}{db}." < ".$upgrade{$upgrade}{sql});
|
||||||
$config{$config}{version} = $upgrade{$upgrade}{to};
|
$config{$config}{version} = $upgrade{$upgrade}{to};
|
||||||
|
$notRun = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print "\nUPGRADES COMPLETE\n";
|
if ($notRun) {
|
||||||
|
print "\nNO UPGRADES NECESSARY\n";
|
||||||
|
} else {
|
||||||
|
print "\nUPGRADES COMPLETE\n";
|
||||||
|
print "Please restart your web server and test your sites.\n";
|
||||||
|
print "\nNOTE: If you have not already done so, please consult\ndocs/gotcha.txt for possible upgrade complications.\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
print "Please restart your web server and test your sites.\n";
|
|
||||||
|
|
||||||
print "\nNOTE: If you have not already done so, please consult\ndocs/gotcha.txt for possible upgrade complications.\n\n";
|
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------------
|
#-----------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue