perl binlog dml操作报告

<pre name="code" class="html">if ( $#ARGV < 2 ){  
        print "please input  like  binglog-0001 '2013-07-01 00:00:00' '2013-07-02 00:00:00'!\n";
                exit(-1);  
                   } 
        $file= $ARGV[0];  
        $start_dt = $ARGV[1];
        $end_dt = $ARGV[2];
@bin=`mysqlbinlog --start-datetime='$start_dt' --stop-datetime='$end_dt' $file`;
       foreach  (@bin){
        $_ =~ s/`//g;
#\s+匹配一个或者多个空格
       if ($_ =~/^update\s+(.*?)\s+/i)
         {#print "\$1 is $1\n";
         $act='update';
         $table=$1;
         $var=$act.-$table;
         $hash1{$var}++;
         }
        
  if ($_ =~/^delete\s+from\s+(.*?)\s+/i)
         {#print "\$1 is $1\n";
         $act='delete';
         $table=$1;
         $var=$act.-$table;
         $hash2{$var}++;
         }


  if ($_ =~/^insert\s+into\s+(.*?)\s+/i)
         {#print "\$1 is $1\n";
         $act='insert';
         $table=$1;
         $var=$act.-$table;
         $hash3{$var}++;
         }


};

  while(my($tj, $times) = each %hash1) {
 print "$tj  count(*) ==   $times\n";
};

  while(my($tj, $times) = each %hash2) {
 print "$tj  count(*) ==   $times\n";
};

  while(my($tj, $times) = each %hash3) {

 print "$tj  count(*) ==   $times\n";

};

[root@zjzc01 binlog]# perl perl_binlog.pl  mysql-bin.000086 '2016-08-26 00:00:00' '2016-08-27 00:00:00'
update-QRTZ_CRON_TRIGGERS  count(*) ==   59
update-QRTZ_FIRED_TRIGGERS  count(*) ==   59
update-ClientActionTrack  count(*) ==   19
update-QRTZ_TRIGGERS  count(*) ==   132
update-QRTZ_SCHEDULER_STATE  count(*) ==   323
delete-QRTZ_FIRED_TRIGGERS  count(*) ==   58
insert-ClientActionTrack(  count(*) ==   19
insert-QRTZ_FIRED_TRIGGERS  count(*) ==   55



   

posted @ 2016-08-26 10:49  czcb  阅读(151)  评论(0编辑  收藏  举报