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 12:56:05 +00:00
|
|
|
use strict;
|
2008-03-18 18:13:34 +00:00
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=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",
|
2010-12-17 19:21:16 +00:00
|
|
|
"Error running tabdump to get list of tables");
|
2008-03-18 18:13:34 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
2011-05-26 17:15:11 +00:00
|
|
|
# read tables to skip during dump from site.skiptables attribute
|
|
|
|
my @skiptbls=xCAT::Utils->get_site_attribute('skiptables');
|
|
|
|
|
2008-03-18 18:13:34 +00:00
|
|
|
foreach my $table (@output)
|
|
|
|
{
|
2011-04-19 13:38:57 +00:00
|
|
|
# if not -a request , skip eventlog and auditlog
|
|
|
|
if ( (!$::ALL) && (($table =~ /^eventlog/) || ($table =~ /^auditlog/))) {
|
|
|
|
if ($::DUMPVERBOSE) {
|
|
|
|
xCAT::MsgUtils->message("I", "Skipping $table\n");
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
# skip teal tables
|
|
|
|
if ( $table =~ /^x_teal/ ) {
|
|
|
|
if ($::DUMPVERBOSE) {
|
|
|
|
xCAT::MsgUtils->message("I", "Skipping $table\n");
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2011-05-26 17:15:11 +00:00
|
|
|
# skip and table in the site.skiptables attribute
|
|
|
|
if (grep(/^$table$/, @skiptbls)) {
|
|
|
|
if ($::DUMPVERBOSE) {
|
|
|
|
xCAT::MsgUtils->message("I", "Skipping $table\n");
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2011-04-19 13:38:57 +00:00
|
|
|
|
2011-05-11 19:25:01 +00:00
|
|
|
$cmd = "tabdump -f $::PATH/$table.csv $table";
|
2008-03-18 18:13:34 +00:00
|
|
|
my @errout = xCAT::Utils->runcmd($cmd, 0);
|
|
|
|
if ($::RUNCMD_RC != 0)
|
|
|
|
{ # error
|
2010-12-17 19:21:16 +00:00
|
|
|
xCAT::MsgUtils->message("E", "Error running $cmd, @errout");
|
2010-04-30 13:25:58 +00:00
|
|
|
} else {
|
|
|
|
if ($::DUMPVERBOSE) {
|
2010-12-17 19:21:16 +00:00
|
|
|
xCAT::MsgUtils->message("I", "Dumping $table");
|
2010-04-30 13:25:58 +00:00
|
|
|
}
|
2008-03-18 18:13:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-08-29 11:05:35 +00:00
|
|
|
xCAT::MsgUtils->message("I", "Backup 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:25:58 +00:00
|
|
|
my $usagemsg =
|
2011-04-19 13:38:57 +00:00
|
|
|
" dumpxCATdb -h \n dumpxCATdb -v \n dumpxCATdb [-a] [-V] <-p> [path to dump directory]";
|
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(
|
2011-04-19 13:38:57 +00:00
|
|
|
'a|all' => \$::ALL,
|
2008-03-18 18:13:34 +00:00
|
|
|
'p|path=s' => \$::PATH,
|
|
|
|
'h|help' => \$::HELP,
|
2010-04-30 13:25:58 +00:00
|
|
|
'V|verbose' => \$::DUMPVERBOSE,
|
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))
|
|
|
|
{
|
2010-12-17 19:21:16 +00:00
|
|
|
my $msg = " Requires -p with path to directory to hold db files.";
|
2008-03-18 18:13:34 +00:00
|
|
|
xCAT::MsgUtils->message("E", $msg);
|
|
|
|
exit 1;
|
|
|
|
}
|
2011-05-24 17:43:36 +00:00
|
|
|
if (!( -e $::PATH)) {
|
|
|
|
my $msg = " Creating $::PATH for database dump";
|
|
|
|
xCAT::MsgUtils->message("I", $msg);
|
|
|
|
my @output = xCAT::Utils->runcmd("mkdir -p $::PATH", 0);
|
|
|
|
if ($::RUNCMD_RC != 0)
|
|
|
|
{ # error
|
|
|
|
xCAT::MsgUtils->message("E",
|
|
|
|
"Error running mkdir -p $::PATH");
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
}
|
2008-03-18 18:13:34 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|