Last active
December 25, 2015 08:19
-
-
Save callumj/6946282 to your computer and use it in GitHub Desktop.
tcpdump for MySQL - recording table modifications.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | perl -e ' | |
while(<>) { chomp; next if /^[^ ]+[ ]*$/; | |
if(/^(INSERT|UPDATE)/) { | |
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); | |
$time = "$hour:$min"; | |
if (defined $q) { | |
if ($q =~ /INSERT\s+INTO\s+`(\w+)`/) { | |
print "$time,insert,$1\n"; | |
} | |
if ($q =~ /UPDATE\s+`(\w+)`/) { | |
print "$time,update,$1\n"; | |
} | |
} | |
$q=$_; | |
} else { | |
$_ =~ s/^[ \t]+//; $q.=" $_"; | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment