Add new database dump and restore commands

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@810 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
lissav 2008-03-18 18:13:34 +00:00
parent 53d96cf3fc
commit a428ba2bba
4 changed files with 336 additions and 0 deletions

View File

@ -0,0 +1,54 @@
=head1 NAME
B<dumpxCATdb> - dumps the xCAT db tables .
=head1 SYNOPSIS
I<dumpxCATdb [-h| --help]>
I<dumpxCATdb [-v| --version]>
I<dumpxCATdb[-p| --path]>
=head1 DESCRIPTION
The dumpxCATdb command creates .csv files for all xCAT database tables and puts them in the directory given by the -p flag. These files can be used by the restorexCATdb command to restore the database.
=head1 OPTIONS
B<-h> Display usage message.
B<-v> Command Version.
B<-p> Path to the directory to dump the tables.
=head1 RETURN VALUE
0 The command completed successfully.
1 An error has occurred.
=head1 EXAMPLES
1. To dump the xCAT database into the /tmp/db directory, enter:
I<dumpxCATdb -p /tmp/db>
=head1 FILES
/opt/xcat/sbin/dumpxCATdb
=head1 NOTES
This command is part of the xCAT software product.
See restorexCATdb

View File

@ -0,0 +1,54 @@
=head1 NAME
B<restorexCATdb> - restores the xCAT db tables .
=head1 SYNOPSIS
I<restorexCATdb [-h| --help]>
I<restorexCATdb [-v| --version]>
I<restorexCATdb[-p| --path]>
=head1 DESCRIPTION
The restorexCATdb command restores the xCAT database tables from the directory given by the -p flag.
=head1 OPTIONS
B<-h> Display usage message.
B<-v> Command Version.
B<-p> Path to the directory containing the database restore files.
=head1 RETURN VALUE
0 The command completed successfully.
1 An error has occurred.
=head1 EXAMPLES
1. To restore the xCAT database from the /tmp/db directory, enter:
I<restorexCATdb -p /tmp/db>
=head1 FILES
/opt/xcat/sbin/restorexCATdb
=head1 NOTES
This command is part of the xCAT software product.
See dumpxCATdb

View File

@ -0,0 +1,109 @@
#!/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;
#-----------------------------------------------------------------------------
=head1 dumpxCATdb
dumpxCATdb -p <directory to place database dump>
=cut
#-----------------------------------------------------------------------------
# Main
my $rc = 0;
my $cmd;
&parse_args;
my @output = xCAT::Utils->runcmd("tabdump", 0);
if ($::RUNCMD_RC != 0)
{ # error
xCAT::MsgUtils->message("E",
"Error running tabdump to get list of tables\n");
exit 1;
}
foreach my $table (@output)
{
$cmd = "tabdump $table > $::PATH/$table.csv";
my @errout = xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0)
{ # error
xCAT::MsgUtils->message("E", "Error running $cmd, @errout\n");
}
}
exit $rc;
#-----------------------------------------------------------------------------
=head3 parse_args
Parses for input
=cut
#-----------------------------------------------------------------------------
sub parse_args
{
my $msg;
my $usagemsg;
Getopt::Long::Configure("posix_default");
Getopt::Long::Configure("no_gnu_compat");
Getopt::Long::Configure("bundling");
if (
!GetOptions(
'p|path=s' => \$::PATH,
'h|help' => \$::HELP,
'v|version' => \$::VERSION
)
)
{
$usagemsg =
" dumpxCATdb -h \n dumpxCATdb [-p] [path to dump directory]\n";
xCAT::MsgUtils->message("E", $usagemsg);
exit 1;
}
if ($::HELP)
{
$usagemsg =
" dumpxCATdb -h \n dumpxCATdb [-p] [path to dump directory]\n";
xCAT::MsgUtils->message("I", $usagemsg);
exit 0;
}
if ($::VERSION)
{
xCAT::MsgUtils->message("I", "Version 2.0\n");
exit 0;
}
if (!($::PATH))
{
my $msg = " -p with path to directory to hold db files.\n";
xCAT::MsgUtils->message("E", $msg);
exit 1;
}
if (!( -e $::PATH)) {
my $msg = " Input path must exist \n";
xCAT::MsgUtils->message("E", $msg);
exit 1;
}
}

View File

@ -0,0 +1,119 @@
#!/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;
#-----------------------------------------------------------------------------
=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;
}
my @files = readdir(DIRPATH);
foreach my $table (@files)
{
if ($table ne '.' and $table ne '..')
{
my $tablename = $::PATH;
$tablename .= "/";
$tablename .= $table;
$cmd = "tabrestore $tablename";
my @errout = xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0)
{ # error
xCAT::MsgUtils->message("E", "Error running $cmd, @errout\n");
}
}
}
closedir DIRPATH;
exit $rc;
#-----------------------------------------------------------------------------
=head3 parse_args
Parses for input
=cut
#-----------------------------------------------------------------------------
sub parse_args
{
my $msg;
my $usagemsg;
Getopt::Long::Configure("posix_default");
Getopt::Long::Configure("no_gnu_compat");
Getopt::Long::Configure("bundling");
if (
!GetOptions(
'p|path=s' => \$::PATH,
'h|help' => \$::HELP,
'v|version' => \$::VERSION
)
)
{
$usagemsg =
" restorexCATdb -h \n restorexCATdb [-p] [path to restore .csv files]\n";
xCAT::MsgUtils->message("E", $usagemsg);
exit 1;
}
if ($::HELP)
{
$usagemsg =
" restorexCATdb -h \n restorexCATdb [-p] [path to restore .csv files]\n";
xCAT::MsgUtils->message("I", $usagemsg);
exit 0;
}
if ($::VERSION)
{
xCAT::MsgUtils->message("I", "Version 2.0\n");
exit 0;
}
if (!($::PATH))
{
my $msg = " -p with path to place dump files is required \n";
xCAT::MsgUtils->message("E", $msg);
exit 1;
}
if (!(-e $::PATH))
{
my $msg = " Input path must exist \n";
xCAT::MsgUtils->message("E", $msg);
exit 1;
}
}