-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpick_sql.py
More file actions
executable file
·37 lines (30 loc) · 854 Bytes
/
Copy pathpick_sql.py
File metadata and controls
executable file
·37 lines (30 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/python
# -*- coding:utf-8 -*-
"""
mysqlbinlog处理后的binlog文件,根据查找关键字 lookfor
查找具体的SQL语句,从SET TIMESTAMP 到 COMMIT 的一个区段完整信息。
"""
from sys import argv
import os
script, file_name, lookfor = argv
fin = open(file_name)
fout = open(file_name + '.out','a+')
need_write = False
fout_list = []
for line in fin:
if line[:13] == "SET TIMESTAMP":
fout_list = []
need_write = False
fout_list.append(line)
elif line[:11] == "COMMIT/*!*/":
fout_list.append(line)
if need_write:
for out_line in fout_list:
fout.write(out_line)
else:
fout_list.append(line)
line_pos = line.find(lookfor)
if line_pos > 0:
need_write = True
fin.close()
fout.close()