Binary Log Parser Plugin

From wiki.zmanda.com
Jump to navigation Jump to search

Binary log parser plugin

Selective recovery of MySQL database requires the administrators to look at the database events in the incremental dumps using binary log parser. The MySQL binary logs can have lots of database events (millions of database events/transactions in many cases). The binary log parser plugin can help in the filtering the database events of interest.

For example: Administrator interested only in tables being dropped can create a plugin to filter "DROP TABLES" database events.

Parameters to be supplied to mysql-zrm

--action parse-binlogs
If the parse-binlogs action is specified, the utility will display the parsed output of the binary logs. This is useful to find out the log positions and/or timestamp to be used for restore operations. Either the source-directory or the bin-logs option should be specified. If the source-directory option is specified then the parsed output of the binary logs from that backup will be displayed. If bin-logs option is specified then parsed output of the binary log file specified will be displayed.
--action --parse-binlogs-plugin <plugin>
Plugin that can be used filter the output of parse-binlogs action. The full path of the plugin needs to be specified. This plugin is optional.
--action --parse-binlogs-plugin-options <"option1 option2 ...">
These options are passed to the parse-binlogs-plugin as one of the command line arguments.
mysql-zrm --action <restore> --bin-logs <"name1 name2 ...>
List of binary log files to be used for restoring. The full path for each file should be specified. For restore action, both source-directory and bin-logs options should not be specified.

Usage

The binary log parser plugin is optional and is specified as a command line parameter to mysql-zrm tool.

Example:

# mysql-zrm --action parse-binlogs --bin-logs "/var/lib/mysql-zrm/backupset1/20060819121532/mysql-bin.0" \
            --parse-binlogs-plugin "/usr/share/mysql-zrm/plugins/parse-binlogs.pl" \
             --parse-binlogs-plugin-options="DROP TABLE"

parse-binlogs-plugin parameter should have the full path to the plugin as parameter and parse-binlogs-plugin-options take strings as parameter. The parse-binlogs-plugin-options values are passed to the binary log parser as argument.

Plugin interface

The first parameter is the parse-binlogs-plugin-options value that was passed as parameter to mysql-zrm. The second parameter is the string containing one database event. The fields are separated by white spaces and fields are in following format:

Log filename | Log Position | Timestamp | Event Type | Event

The plugin should return 0 if the line should be displayed and 1 if it should be filtered out.

Template

/usr/share/mysql-zrm/plugins/parse-binlogs.pl is a template for binary log parser plugin. Users are expected to modify it to suit their environment.

Logs

Errors and messages from the plugin are logged to mysql-zrm logs (/var/log/mysql-zrm/mysql-zrm.log).