#!C:\Perl64\bin
#通过BCP备份和还原SQLSERVER指定的表
use 5.014;
#加载用户和密码配置文件
my $username ;
my $passwd;
##获取用户名
my $dir="c:";
$dir=$dir."/";
my $filename="config.txt";
my $keysword="username:";
my $count="50";
my $begincount=index($keysword,":");
my($file);
open(FILEH,$dir.$filename);
while(my $test=<FILEH>){
if((index($test,$keysword))>=0){
my $test1=substr($test,$begincount+1,$count);
#print "$test1";
chomp($username=$test1);
}
}
close(FILEH);
##获取密码
my $dir="c:";
$dir=$dir."/";
my $filename="config.txt";
my $keysword="password:";
my $count="50";
my $begincount=index($keysword,":");
my($file);
open(FILEH,$dir.$filename);
while(my $test=<FILEH>){
if((index($test,$keysword))>=0){
my $test2=substr($test,$begincount+1,$count);
#print "$test2";
chomp($passwd=$test2);
}
}
close(FILEH);
print "-------------------------------------------------------------------\n";
print "请首先检查用户和密码配置文件config.txt保存路径是否为$dir$filename\n";
print "-------------------------------------------------------------------\n";
print "重要提示:备份表操作请输入0;还原表操作请输入1\n";
print "请输入操作代码:";
chomp(my $inp=<STDIN>);
print "你输入的操作代码为$inp\n";
#判断输入为0即备份操作
if ($inp eq 0){
print '服务器IP:(不输入默认为localhost)';
chomp(my $a = <STDIN>);
if ($a==''){
$a='localhost';
}else{
print "你输入的服务器IP为:$a\n";
}