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'!
";
                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 ($_ =~/^updates+(.*?)s+/i)
         {#print "$1 is $1
";
         $act='update';
         $table=$1;
         $var=$act.-$table;
         $hash1{$var}++;
         }
        
  if ($_ =~/^deletes+froms+(.*?)s+/i)
         {#print "$1 is $1
";
         $act='delete';
         $table=$1;
         $var=$act.-$table;
         $hash2{$var}++;
         }


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


};

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

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

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

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

};

[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



   

原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6199303.html