Code Monkey home page Code Monkey logo

mariadb-binlog-reader's Introduction

MariaDB Tools

This tool is written in Python, scans all the Binary logs and generates a report containing all the DML/DDL operations.

Note: Don't try to execute this on live binlog, best to copy the files in some other server or a slave and process.

List of arguments

  • Binary Log Path
    • This parameter locates the path of the MariaDB binary logs. Must not end with a "/"
  • Binary Log Base Filename
  • Binary Log Starting Number
    • This is the starting binary log number, refer to the examples below for better understanding.

Examples

Parsiong the the binary logs starting with 00001 to the last one. Take note of the last parameter is the starting binlog number.

root@2c44850ee333:~# python binlogreader.py /var/log/mysql mariadb-bin 1

*********** Reading Binary Logs ***********
Reading /var/log/mysql/mariadb-bin.000001...
Reading /var/log/mysql/mariadb-bin.000002...
Reading /var/log/mysql/mariadb-bin.000003...
Reading /var/log/mysql/mariadb-bin.000004...
Reading /var/log/mysql/mariadb-bin.000005...
Reading /var/log/mysql/mariadb-bin.000006...
Reading /var/log/mysql/mariadb-bin.000007...
Reading /var/log/mysql/mariadb-bin.000008...
*********** Finished Reading Binary Logs ***********

*********** Getting Distinct Changes ***********
*********** Distinct Changes Identified ***********

*********** Generating Report ***********
Generating Summary for [### DELETE FROM `testdb`.`tab`]
Generating Summary for [### INSERT INTO `testdb`.`junk`]
Generating Summary for [### INSERT INTO `testdb`.`tab`]
Generating Summary for [### INSERT INTO `testdb`.`testtab`]
Generating Summary for [### UPDATE `testdb`.`junk`]
Generating Summary for [### UPDATE `testdb`.`tab`]
Generating Summary for [CREATE TABLE tab(id serial, col varchar(100))]
Generating Summary for [DROP TABLE `junk` /* generated by server */]
*********** Report Generated ***********

*********** Start of the Binary Log Report ***************
DELETE FROM `testdb`.`tab`,217
INSERT INTO `testdb`.`junk`,100
INSERT INTO `testdb`.`tab`,5244
INSERT INTO `testdb`.`testtab`,5147648
UPDATE `testdb`.`junk`,2
UPDATE `testdb`.`tab`,322
CREATE TABLE tab(id serial, col varchar(100)),1
DROP TABLE `junk` /* generated by server */,1
*********** End of the Binary Log Report ***************

The output above indicates that all the binary logs were processed starting from 000001 to 000005 and the binary log repor covers all the transactions from the 5 logs mentioned.

Asuming we want to process on the 000004 and later files, we can trigger the script as follows. The report will be generated accordingly.

root@2c44850ee333:~# python binlogreader.py /var/log/mysql mariadb-bin 4

*********** Reading Binary Logs ***********
Skipping binlog file 1
Skipping binlog file 2
Skipping binlog file 3
Reading /var/log/mysql/mariadb-bin.000004...
Reading /var/log/mysql/mariadb-bin.000005...
Reading /var/log/mysql/mariadb-bin.000006...
Reading /var/log/mysql/mariadb-bin.000007...
Reading /var/log/mysql/mariadb-bin.000008...
*********** Finished Reading Binary Logs ***********

*********** Getting Distinct Changes ***********
*********** Distinct Changes Identified ***********

*********** Generating Report ***********
Generating Summary for [### INSERT INTO `testdb`.`junk`]
Generating Summary for [### INSERT INTO `testdb`.`tab`]
Generating Summary for [### INSERT INTO `testdb`.`testtab`]
Generating Summary for [### UPDATE `testdb`.`junk`]
Generating Summary for [DROP TABLE `junk` /* generated by server */]
*********** Report Generated ***********

*********** Start of the Binary Log Report ***************
INSERT INTO `testdb`.`junk`,100
INSERT INTO `testdb`.`tab`,100
INSERT INTO `testdb`.`testtab`,5147648
UPDATE `testdb`.`junk`,2
DROP TABLE `junk` /* generated by server */,1
*********** End of the Binary Log Report ***************

Next in lime is going to be the option to generate time based report generation on the hourly basis from the given binary logs.

Thank you.

mariadb-binlog-reader's People

Contributors

faizalrf avatar

Stargazers

Sylvain Arbaudie avatar

Watchers

James Cloos avatar Sylvain Arbaudie avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.