mysql> quit
从全库的备份中挖出test表的备份,在将其恢复。
perl restore_table.pl -f /tmp/test.sql -t test > /tmp/test.sql
/usr/local/mysql/bin/mysql -u -p -D test /tmp/test.sql
mysql> use test;
Database changed
mysql> select count(*) from test;
+----------+
| count(*) |
+----------+
| 1568394 |
+----------+
1 row in set (0.00 sec)
OK,表已经恢复了。贴下这个脚本的代码:
cat restore_table.pl
#!/usr/bin/perl -w
use strict;
use Getopt::Std;
my %opts;
getopt('ft',\%opts);
my $file=$opts{f};
my $tag=$opts{t};
my $pattern1="Table structure for table `$tag`";
my $pattern2="Dumping data for table `$tag`";
my $pattern3="40000 ALTER TABLE `$tag` DISABLE KEYS";
my $pattern4="40000 ALTER TABLE `$tag` ENABLE KEYS";
my $print=0;
open FD,$file;
while(){
my $content=$_;
$print=1 if $content =~ $pattern1;
print if $print == 1;
last if($content =~ $pattern2);
}
$print=0;
while(){
my $content=$_;
$print=1 if $content =~ $pattern3;
print if $print == 1;
last if($content =~ $pattern4);
}