Skip to content

Instantly share code, notes, and snippets.

@Kagee
Created March 13, 2012 22:01
Show Gist options
  • Save Kagee/2032045 to your computer and use it in GitHub Desktop.
Save Kagee/2032045 to your computer and use it in GitHub Desktop.
summarize_binlog.pl
#!/usr/bin/perl
use strict;
use warnings;
if ($#ARGV < 0 ) {
print "usage: $0 <path> [path...]\n";
exit;
}
my $file = $ARGV[0];
# Check that the path exsists, is a file, and is readable
if((-e $file) && (-f $file) && (-r $file)) {
open F, "mysqlbinlog $file |" or print "couldn't read from mysqlbinlog $file\n" && exit;
my $queries = 0;
while (<F>) {
if (my ($found) = m/(^#.*Rotate to)/o) {
print "Startdato: ", (substr $found, 1, 6), "\n";
}
if (my ($found) = m/(^#.*Start: binlog)/o) {
print "Sluttdato: ", (substr $found, 1, 6), "\n";
}
if (my ($found) = m/(^#.*Query)/o) {
$queries++;
}
}
close F;
print "$queries queries found\n";
} else {
print "Does not exsist, is not a file, or ir unreadable: $file\n";
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment