Created
August 30, 2013 12:23
-
-
Save ShahriyarR/6389320 to your computer and use it in GitHub Desktop.
Output Binary log content to .txt file for parsing
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
import os | |
import subprocess | |
import shlex | |
import configparser | |
class BinlogToTxt: | |
def __init__(self,conf = 'datadir.conf'): | |
con = configparser.ConfigParser() | |
con.read(conf) | |
bolme=con.sections() | |
DB=bolme[0] | |
self.originalbinlogdir=con[DB]['originalbinlogdir'] | |
self.txtdir=con[DB]['txtdir'] | |
def binlog_show(self): | |
print("Your binary log list: ") | |
for files in os.listdir(self.originalbinlogdir): | |
print(files) | |
def binlog_convert(self): | |
self.binlog_show() | |
select=input("Which one convert to .txt file?(Give fullname): ") | |
subselect=select.find('0') | |
binselect=select[subselect:] | |
args = ['/usr/bin/mysqlbinlog', '-vv', '--base64-output=DECODE-ROWS', | |
'%s/%s' % (self.originalbinlogdir, select)] | |
filename = '%s/%s.txt' % (self.txtdir, binselect) | |
with open(filename, 'w') as f: | |
subprocess.Popen(args,stdout=f) | |
a = BinlogToTxt() | |
a.binlog_convert() |
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
[MySQL] | |
mysql = /usr/bin/mysql | |
mycnf = /usr/my.cnf | |
mysqlbinlog = /usr/bin/mysqlbinlog | |
mysqladmin = /usr/bin/mysqladmin | |
remoteconnection = --user=remote --password=12345 --host=192.168.1.18 | |
binlogsyncdir = /home/sh/remote_binlogs | |
myoptions= --read-from-remote-server --raw --to-last-log | |
originalbinlogdir = /home/sh/remote_binlogs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment