Skip to content

Commit d536a55

Browse files
committed
support read binlog from stdin
1 parent 27ec2bc commit d536a55

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

doc/cmd.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,12 @@ lightning 还支持直接分析加密的 binlog,只需要添加 `-keyring` 配
5959
# 回滚所有删除事件
6060
lightning -plugin flashback -keyring keyring -event-types delete binlog.encrypted
6161
```
62+
63+
## 从标准输入读取 binlog
64+
65+
有时候需要分析的 binlog 并不在本机,可能存储在 s3 或其他服务器上。分析远程 binlog 文件时不想占用本地磁盘空间可以选择从标准输入读取 binlog。添加 `-` 表示从标准输入读取文件内容,示例如下:
66+
67+
```bash
68+
# 仅以 binlog 文件存储在 minio 为例,使用 minio client 读取远程经过压缩的 binlog 文件
69+
mc cat path/to/binlog_file.gz | gunzip | ./lightning - > decrypt_log.sql
70+
```

event/parser.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,14 @@ func CheckBinlogFileTime(files []string) error {
189189
// BinlogFileParser parser binary log file
190190
func BinlogFileParser(files []string) error {
191191
for _, filename := range files {
192-
fd, err := os.Open(filename)
192+
var fd *os.File
193+
var err error
194+
switch filename {
195+
case "-":
196+
fd = os.Stdin
197+
default:
198+
fd, err = os.Open(filename)
199+
}
193200
if err != nil {
194201
return err
195202
}

0 commit comments

Comments
 (0)