xcat-core/xCAT-client/sbin/dumpxCATdb

163 lines
3.9 KiB
Plaintext
Raw Normal View History

#!/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;
use strict;
#-----------------------------------------------------------------------------
=head1 dumpxCATdb
dumpxCATdb -p <directory to place database dump>
See man page.
=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");
exit 1;
}
# Determine which table to skip
my @output2;
if ($ENV{'XCAT_SKIPTABLES'}) {
@output2=$ENV{'XCAT_SKIPTABLES'};
} else {
# read tables to skip from site.skiptables attribute
@output2=xCAT::Utils->get_site_attribute('skiptables');
}
my @skiptbls;
if (@output2) {
@skiptbls = split (/\,/,$output2[0]);
}
foreach my $table (@output)
{
# 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;
}
# skip ISNM tables except isnm_config
if ( $table =~ /^isnm_perf/ ) {
if ($::DUMPVERBOSE) {
xCAT::MsgUtils->message("I", "Skipping $table\n");
}
next;
}
# skip any table in the site.skiptables attribute
if (grep(/^$table$/, @skiptbls)) {
if ($::DUMPVERBOSE) {
xCAT::MsgUtils->message("I", "Skipping $table\n");
}
next;
}
$cmd = "tabdump -f $::PATH/$table.csv $table";
my @errout = xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0)
{ # error
xCAT::MsgUtils->message("E", "Error running $cmd, @errout");
} else {
if ($::DUMPVERBOSE) {
xCAT::MsgUtils->message("I", "Dumping $table");
}
}
}
xCAT::MsgUtils->message("I", "Backup Complete.");
exit $rc;
#-----------------------------------------------------------------------------
=head3 parse_args
Parses for input
=cut
#-----------------------------------------------------------------------------
sub parse_args
{
my $msg;
my $usagemsg =
" dumpxCATdb -h \n dumpxCATdb -v \n dumpxCATdb [-a] [-V] <-p> [path to dump directory]";
Getopt::Long::Configure("posix_default");
Getopt::Long::Configure("no_gnu_compat");
Getopt::Long::Configure("bundling");
if (
!GetOptions(
'a|all' => \$::ALL,
'p|path=s' => \$::PATH,
'h|help' => \$::HELP,
'V|verbose' => \$::DUMPVERBOSE,
'v|version' => \$::VERSION
)
)
{
xCAT::MsgUtils->message("E", $usagemsg);
exit 1;
}
if ($::HELP)
{
xCAT::MsgUtils->message("I", $usagemsg);
exit 0;
}
if ($::VERSION)
{
my $version = xCAT::Utils->Version();
xCAT::MsgUtils->message("N", $version);
exit 0;
}
if (!($::PATH))
{
my $msg = " Requires -p with path to directory to hold db files.";
xCAT::MsgUtils->message("E", $msg);
exit 1;
}
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;
}
}
}