Skip to content

Instantly share code, notes, and snippets.

@ShahriyarR
Created August 30, 2013 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShahriyarR/6389320 to your computer and use it in GitHub Desktop.
Save ShahriyarR/6389320 to your computer and use it in GitHub Desktop.
Output Binary log content to .txt file for parsing
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()
[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