2008-03-18 18:13:34 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
#(C)IBM Corp
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
{
|
|
|
|
$::XCATROOT =
|
|
|
|
$ENV{'XCATROOT'} ? $ENV{'XCATROOT'}
|
|
|
|
: -d '/opt/xcat' ? '/opt/xcat'
|
|
|
|
: '/usr';
|
|
|
|
}
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
|
|
|
use Getopt::Long;
|
|
|
|
use xCAT::MsgUtils;
|
|
|
|
use xCAT::Utils;
|
2010-04-30 13:35:44 +00:00
|
|
|
use strict;
|
2008-03-18 18:13:34 +00:00
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head1 restorexCATdb
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
restorexCATdb -p <directory containing db restore .csv files>
|
|
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Main
|
|
|
|
my $rc = 0;
|
|
|
|
|
|
|
|
&parse_args;
|
|
|
|
|
|
|
|
# read all the *.csv files from the input directory and restore the database
|
|
|
|
opendir DIRPATH, $::PATH;
|
|
|
|
if ($? != 0)
|
|
|
|
{
|
|
|
|
my $msg = " Unable to read directory $::PATH \n";
|
|
|
|
xCAT::MsgUtils->message("E", $msg);
|
|
|
|
exit 1;
|
|
|
|
}
|
2011-05-26 18:16:20 +00:00
|
|
|
# read tables to skip during restore from site.skiptables attribute
|
|
|
|
my @output2=xCAT::Utils->get_site_attribute('skiptables');
|
|
|
|
my @skiptbls;
|
|
|
|
if (@output2) {
|
|
|
|
@skiptbls = split (/\,/,$output2[0]);
|
|
|
|
}
|
|
|
|
|
2008-03-18 18:13:34 +00:00
|
|
|
my @files = readdir(DIRPATH);
|
|
|
|
foreach my $table (@files)
|
|
|
|
{
|
|
|
|
if ($table ne '.' and $table ne '..')
|
|
|
|
{
|
|
|
|
my $tablename = $::PATH;
|
|
|
|
$tablename .= "/";
|
|
|
|
$tablename .= $table;
|
2010-04-30 13:35:44 +00:00
|
|
|
if ( (!$::ALL) && (($table =~ /^eventlog/) || ($table =~ /^auditlog/))) {
|
|
|
|
|
|
|
|
if ($::VERBOSEREST) {
|
|
|
|
xCAT::MsgUtils->message("I", "Skipping $table\n");
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2011-04-19 13:55:14 +00:00
|
|
|
# skip teal tables
|
|
|
|
if ( $table =~ /^x_teal/ ) {
|
|
|
|
if ($::VERBOSEREST) {
|
|
|
|
xCAT::MsgUtils->message("I", "Skipping $table\n");
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2011-11-15 12:13:36 +00:00
|
|
|
# skip ISNM tables except isnm_config
|
|
|
|
if ( $table =~ /^isnm_perf/ ) {
|
|
|
|
if ($::DUMPVERBOSE) {
|
|
|
|
xCAT::MsgUtils->message("I", "Skipping $table\n");
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2011-05-26 18:16:20 +00:00
|
|
|
# skip and table in the site.skiptables attribute
|
|
|
|
if (@skiptbls) {
|
|
|
|
my ($tmptable,$suffix) = split(/\./,$table);
|
|
|
|
chomp $tmptable;
|
|
|
|
if (grep(/^$tmptable$/, @skiptbls)) {
|
|
|
|
if ($::VERBOSEREST) {
|
|
|
|
xCAT::MsgUtils->message("I", "Skipping $tmptable\n");
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
2011-04-19 13:55:14 +00:00
|
|
|
|
2010-04-30 13:35:44 +00:00
|
|
|
my $cmd = "tabrestore $tablename";
|
2008-03-18 18:13:34 +00:00
|
|
|
my @errout = xCAT::Utils->runcmd($cmd, 0);
|
|
|
|
if ($::RUNCMD_RC != 0)
|
|
|
|
{ # error
|
|
|
|
xCAT::MsgUtils->message("E", "Error running $cmd, @errout\n");
|
2010-04-30 13:35:44 +00:00
|
|
|
} else {
|
|
|
|
if ($::VERBOSEREST) {
|
|
|
|
xCAT::MsgUtils->message("I", "Restoring $table.\n");
|
|
|
|
}
|
2008-03-18 18:13:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir DIRPATH;
|
2010-08-29 11:05:35 +00:00
|
|
|
xCAT::MsgUtils->message("I", "Restore of Database Complete.");
|
2008-03-18 18:13:34 +00:00
|
|
|
exit $rc;
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 parse_args
|
|
|
|
|
|
|
|
Parses for input
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub parse_args
|
|
|
|
{
|
|
|
|
my $msg;
|
2010-04-30 13:35:44 +00:00
|
|
|
my $usagemsg =
|
|
|
|
" restorexCATdb -h \n restorexCATdb -v \n restorexCATdb [-a] [-V] <-p> [path to restore .csv files]\n";
|
2008-03-18 18:13:34 +00:00
|
|
|
Getopt::Long::Configure("posix_default");
|
|
|
|
Getopt::Long::Configure("no_gnu_compat");
|
|
|
|
Getopt::Long::Configure("bundling");
|
|
|
|
if (
|
|
|
|
!GetOptions(
|
2010-04-30 13:35:44 +00:00
|
|
|
'a|all' => \$::ALL,
|
2008-03-18 18:13:34 +00:00
|
|
|
'p|path=s' => \$::PATH,
|
|
|
|
'h|help' => \$::HELP,
|
2010-04-30 13:35:44 +00:00
|
|
|
'V|verbose' => \$::VERBOSEREST,
|
2008-03-18 18:13:34 +00:00
|
|
|
'v|version' => \$::VERSION
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message("E", $usagemsg);
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
if ($::HELP)
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message("I", $usagemsg);
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
if ($::VERSION)
|
|
|
|
{
|
2009-10-06 12:22:42 +00:00
|
|
|
my $version = xCAT::Utils->Version();
|
|
|
|
xCAT::MsgUtils->message("N", $version);
|
|
|
|
|
2008-03-18 18:13:34 +00:00
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
if (!($::PATH))
|
|
|
|
{
|
2009-10-06 12:22:42 +00:00
|
|
|
my $msg = " -p with path to database files is required \n";
|
2008-03-18 18:13:34 +00:00
|
|
|
xCAT::MsgUtils->message("E", $msg);
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
if (!(-e $::PATH))
|
|
|
|
{
|
|
|
|
my $msg = " Input path must exist \n";
|
|
|
|
xCAT::MsgUtils->message("E", $msg);
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|