1

I have binlog from MySQL and I need to output certain time frame into a seperate file, how would I do that?

here is sample of what binlog file contains:

# at 460
#130120  0:09:17 server id 1  end_log_pos 487   Xid = 79514636
COMMIT/*!*/;
# at 487
#130120  0:09:17 server id 1  end_log_pos 560   Query   thread_id=248447    exec_time=0 error_code=0

I'm looking to grep following:

#130120  0:09:17 server id 1  end_log_pos 487   Xid = 79514636
COMMIT/*!*/;
# at 487

I've tried pcregrep -M, but so far without any luck, my regex skills isn't where I thought they are, here is my actual line:

# mysqlbinlog /var/lib/mysql/log/logbin/mysql-bin.001036 | pcregrep -M '130120(\n|.*)\ at\ '
# 

* UPDATE *

  • number of lines between varies between different queries.

* UPDATE 2 *

this actually did the job...

# mysqlbinlog /var/lib/mysql/log/logbin/mysql-bin.001036 | sed -e '/130120 13/,/ at /!d' > /tmp/13
#
alexus
  • 12,342
  • 27
  • 115
  • 173

4 Answers4

1

This could have been done with awk very easily.

E.g

mysqlbinlog mysql-bin.001 | awk '($1 == "130120") {print $0}' > results.txt

This is tells awk to find anything in the first column that matches 130120 exactly and then print that entire line.

If you needed the minute and second exactly, you could then do something like the following:

awk '(($1 == "130120") && ($2 == "0:09:17")) {print $0}'

If you just needed the minute, you could use something like this:

awk '(($1 == "130120") && ($2 ~ "^0:09:")) {print $0}'
tacotuesday
  • 1,349
  • 1
  • 14
  • 26
0

this did the job:

# mysqlbinlog /var/lib/mysql/log/logbin/mysql-bin.001036 | sed -e '/130120 13/,/ at /!d' > /tmp/13
#
alexus
  • 12,342
  • 27
  • 115
  • 173
0

The real answer is to use the command line options to mysqlbinlog

mysqlbinlog --start-datetime=datetime --stop-datetime=datetime /path/to/mysql-bin.001036

R. S.
  • 1,624
  • 12
  • 19
-1
grep -C 1 COMMIT filename

-C is context, 1 line before and 1 line after

-A is after

-B is before

jftuga
  • 5,572
  • 4
  • 39
  • 50