binlog-inspect
English | 简体中文
binlog-inspect is a Rust command-line tool and library for inspecting plaintext MySQL binary logs. It reads one event at a time as a stream, decodes events into a typed model decoupled from the underlying library (including tagged/anonymous GTIDs, previous_gtids, table maps and row images), and emits JSON Lines, text or CSV.
Features
- Read one or more local binlogs, or standard input with
-; download HTTP(S) files with the optionalremotefeature. - Full event-type classification (27 types): typed decoding of format_description, table_map, query, xid, gtid (tagged,
uuid:tag:gno), anonymous_gtid, previous_gtids, rotate, stop, rows_query, incident, intvar, partial_update_rows (before images with applied JSON diffs) and write/update/delete row events; named but undecoded events retain their type andraw_len. - Row images preserve column positions and distinguish absent columns from SQL NULL, with MySQL column type and signedness for numerics.
- Filter by event type,
database.table, byte-offset ranges (--start-position/--stop-position), timestamp ranges (--start-datetime/--stop-datetime) and exact GTIDs (--include-gtid), with before/after row images. --statsprints one JSON summary (files, events, bytes, transactions, per-type and per-table counts, errors);--completionsgenerates shell completion scripts.- Raw event buffers have a default 64 MiB cap. Hostile event headers and table-map metadata are pre-validated, and supported CRC32 checksums are verified. This source checkout provides
visit_eventsfor consuming compressed-transaction children individually. --outputis written atomically: mode 0600 on unix, and existing files are never overwritten.- Layered exit codes: 0 success, 1 hard error, 2 usage error, 3 partial parse failure.
Install and quick start
Install from crates.io (requires Rust 1.88 or newer — the MSRV is verified and CI-enforced; the project uses the Rust 2024 edition). Note: the published 0.4.0 release predates the features documented below; the 0.5.0 batch is in-tree and not yet published:
Or build and install from source:
# or install into ~/.cargo/bin
Run these commands from the project root; --locked uses the dependencies in Cargo.lock:
|
JSON Lines is written to standard output by default. See the usage guide for exit-code semantics; on a partial parse failure the output contains the successfully parsed prefix, so check the exit status. --output creates a new file and never overwrites an existing one. Output can contain business data and should be stored in a trusted location.
Enable the optional feature for remote downloads:
Rust toolchain compatibility
Requires Rust 1.88 or newer (the MSRV is verified and enforced by a dedicated CI job); the project uses the Rust 2024 edition.
Limitations
- Only plaintext files are supported. Encrypted binlogs are rejected; HTTP download neither decrypts them nor implements the MySQL replication protocol.
- Compressed transactions (code 40) are decoded safely: the compression header is pre-validated, decompression is streamed and bounded (declared size + slack; >1 GiB declarations rejected), and inner events share the parser's table-map state.
partial_update_rowsdecodes the before image and applies the JSON-diff after image against it; a diff that cannot be applied is preserved as a loss-markingpartial_jsonvalue with its diffs and the reason.- Decoded JSON values are bounded: nesting beyond MySQL's 100-container limit, hostile aliased shapes that would expand past a 1,000,000-node per-value budget or a per-event shared budget (16× the event's wire size, capped at 4,000,000 nodes) return a parse error carrying the offset, as does a malformed opaque
NEWDECIMALmember or malformed column metadata. Opaque jsonb members render per the documented rules — decimals and date/time values as their text form, other opaque types asbase64:type<id>:<data>strings. - Rotate events are reported but not followed; list the next file yourself.
- MariaDB-specific event types (160+) remain
unknown; named types such asrandanduser_varkeep only the type andraw_len. - A single event may not exceed 64 MiB by default; the CLI can raise this with
--max-event-size(up to the 1 GiB inspection limit), and library callers withwith_max_event_size. - Raw
VAR_STRINGandTYPED_ARRAYtable-map columns produce an explicit unsupported-type error with the current dependency decoder. - Column names and numeric signedness depend on binlog metadata; bytes are encoded as hexadecimal without guessing a character set.
- Compatibility with every server version, event and column type has not been verified, and a successful exit does not mean every event was understood.
Documentation and development