2007-10-26 22:44:33 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
2008-02-14 14:25:49 +00:00
|
|
|
|
|
|
|
# Just like xcatclient, but needs to read a file in and pass it as $request->data
|
|
|
|
|
|
|
|
BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; }
|
2007-12-11 19:15:28 +00:00
|
|
|
use lib "$::XCATROOT/lib/perl";
|
2007-10-26 22:44:33 +00:00
|
|
|
use File::Basename;
|
2008-02-14 14:25:49 +00:00
|
|
|
use xCAT::Client;
|
2013-09-13 17:57:32 +00:00
|
|
|
use xCAT::Utils;
|
|
|
|
|
2008-02-14 14:25:49 +00:00
|
|
|
use Getopt::Long;
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-02-14 14:25:49 +00:00
|
|
|
sub usage {
|
|
|
|
print "Usage: tabrestore <tablename>.csv\n";
|
2013-09-13 17:57:32 +00:00
|
|
|
print " tabrestore -a <tablename>.csv\n";
|
2008-02-14 14:25:49 +00:00
|
|
|
print " tabrestore [-?|-h|--help]\n";
|
2013-09-13 17:57:32 +00:00
|
|
|
print " tabrestore [-v|--version]\n";
|
2008-02-14 14:25:49 +00:00
|
|
|
exit $_[0];
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-02-14 14:25:49 +00:00
|
|
|
#my $bname = basename($0);
|
2007-10-26 22:44:33 +00:00
|
|
|
my $cmdref;
|
|
|
|
$cmdref->{command}->[0] = "tabrestore";
|
|
|
|
|
2008-02-14 14:25:49 +00:00
|
|
|
# Get the options
|
|
|
|
my $HELP;
|
2013-09-13 17:57:32 +00:00
|
|
|
if (
|
|
|
|
!GetOptions(
|
|
|
|
'h|?|help' => \$HELP,
|
|
|
|
'v|version' => \$VERSION,
|
|
|
|
'a|addrows' => \$ADDROWS,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{ usage(1); }
|
|
|
|
|
2007-10-26 22:44:33 +00:00
|
|
|
my $arg=shift(@ARGV);
|
|
|
|
while ($arg =~ /^-/) {
|
|
|
|
push (@{$cmdref->{arg}}, $arg);
|
|
|
|
$arg=shift(@ARGV);
|
|
|
|
}
|
2013-09-13 17:57:32 +00:00
|
|
|
if ($VERSION)
|
|
|
|
{
|
|
|
|
my $version = xCAT::Utils->Version();
|
|
|
|
print "$version\n";
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
if ($HELP)
|
|
|
|
{
|
|
|
|
usage;
|
|
|
|
}
|
|
|
|
if ($ADDROWS)
|
|
|
|
{
|
|
|
|
$cmdref->{addrows}->[0] = "yes";
|
|
|
|
}
|
|
|
|
|
2008-02-14 14:25:49 +00:00
|
|
|
unless ($arg) { usage(2); } # no filename specified
|
|
|
|
|
|
|
|
# Open the specified table file and put its contents in the data key
|
2007-10-26 22:44:33 +00:00
|
|
|
my $filename = $arg;
|
|
|
|
my $tabname = basename($filename);
|
|
|
|
$tabname =~ s/\..*//;
|
|
|
|
$cmdref->{table}->[0] = $tabname;
|
|
|
|
my $fh;
|
2008-02-14 14:25:49 +00:00
|
|
|
unless (open($fh,$filename)) { print "Error: Unable to open $arg for reading.\n"; exit 3; }
|
2007-10-26 22:44:33 +00:00
|
|
|
while (<$fh>) {
|
|
|
|
push @{$cmdref->{data}},$_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-14 14:25:49 +00:00
|
|
|
xCAT::Client::submit_request($cmdref,\&xCAT::Client::handle_response);
|
2013-09-13 17:57:32 +00:00
|
|
|
exit $xCAT::Client::EXITCODE;
|
|
|
|
|