Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1345282
  • 博文数量: 243
  • 博客积分: 888
  • 博客等级: 准尉
  • 技术积分: 2955
  • 用 户 组: 普通用户
  • 注册时间: 2012-12-05 14:33
个人简介

漫漫长路,其修远兮!

文章分类

全部博文(243)

文章存档

2017年(2)

2016年(22)

2015年(32)

2014年(57)

2013年(107)

2012年(23)

分类: Mysql/postgreSQL

2013-04-17 16:46:55

一.从全备中抽取某个表进行恢复

点击(此处)折叠或打开

  1. cat restore_table.pl
  2. #!/usr/bin/perl -w
  3. use strict;
  4. use Getopt::Std;

  5. my %opts;
  6. getopt('ft',\%opts);
  7. my $file=$opts{f};
  8. my $tag=$opts{t};
  9. my $pattern1="Table structure for table `$tag`";
  10. my $pattern2="Dumping data for table `$tag`";

  11. my $pattern3="40000 ALTER TABLE `$tag` DISABLE KEYS";
  12. my $pattern4="40000 ALTER TABLE `$tag` ENABLE KEYS";

  13. my $print=0;
  14. open FD,$file;
  15. while(<FD>){
  16.     my $content=$_;
  17.     $print=1 if $content =~ $pattern1;
  18.     print if $print == 1;
  19.     last if($content =~ $pattern2);
  20. }
  21. $print=0;
  22.  
  23. while(<FD>){
  24.         my $content=$_;
  25.         $print=1 if $content =~ $pattern3;
  26.         print if $print == 1;
  27.         last if($content =~ $pattern4);
  28. }
  29. close FD

  30. perl restore_table.pl -f /tmp/test.sql -t test > /tmp/test.sql


二.从全备中抽取某个库
1.找出创建库的开始行数和结束行数

点击(此处)折叠或打开

  1. grep -n -i 'create database' all.sql > create_database.log &


点击(此处)折叠或打开

  1. ./read_file.pl all.sql 526312268 576328859 &


点击(此处)折叠或打开

      read_file.pl
  1. #!/usr/bin/perl -w

  2. use strict;
  3. my $in_file = $ARGV[0];
  4. my $out_file = $ARGV[1];
  5. my $start = $ARGV[2];
  6. my $end = $ARGV[3];

  7. open FH, $in_file or die "can't open file $in_file\n";
  8. open O_FH, ">>$out_file" or die "can't open file $out_file\n";
  9. my $index = 0;
  10. while(<FH>){
  11.         $index++;
  12.         my $line = $_;
  13.         last if($index>$end);

  14.         if($index>=$start){
  15.             print O_FH $line;
  16.         }
  17. }
  18. close FH;
  19. close O_FH;
三.从binlog中抽取某个库和表

点击(此处)折叠或打开

  1. for i in $(seq 3828 3834); do mysqlbinlog --database=d_auction_gx3 binlog.00$i >> binlog_d_auction_gx3.sql; done
  2. mysqlbinlog binlog.003835 --stop-date='2011-09-02 12:59:59' --database=d_point_gx3 >> binlog_d_point_gx3.sql

点击(此处)折叠或打开

  1. 1.grep -B3 -w table_name restore.sql egrep -v '^--$' > restore_table.sql

  2. 2.emacs restore_table.sql


阅读(1487) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~