Python Find Binlog File

Source: Internet
Author: User

Often need to find some log information in the Binlog, so wrote a simple script. For a very large Binlog file, the script may be slow, after all, still use the list, temporarily did not think of a good way.

See the code in detail:

#/usr/bin/python#2016-04-12#search String in the Binlogs#Usage:#put this file into binlog-dir,exec as:#"Python test.py 111 123 Update" or#"Python test.py 111 123 update and insert" or#"Python test.py 111 123 update or delete"#The nums is the binlog-num.ImportSYSImportsubprocessdeffind_str (Files): forFileinchFiles:comm="mysqlbinlog {0}". Format (file) lines= subprocess. Popen (comm, Shell=true, stdout=subprocess. PIPE) Lines=Lines.stdout.readlines () forLineinchLines:line=Line.lower ()ifLen (sys.argv) = = 4:                ifSYS.ARGV[3] +"' inchLine :yield LineelifLen (sys.argv) = = 6 andSYS.ARGV[4] = =" and":                ifSYS.ARGV[3] +"'  andSYS.ARGV[5] +"' inchLine :yield LineelifLen (sys.argv) = = 6 andSYS.ARGV[4] = ="or":                ifSYS.ARGV[3] +"' orSYS.ARGV[5] +"' inchLine :yield Lineif __name__=="__main__": Start= Sys.argv[1] End= Sys.argv[2] Files= ["Updatelog. {0:06d}". Format (i) forIinchRange (int (start), int (end) +1)] F=find_str (Files) forIinchF:Print(i)

Python Find Binlog File

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.