1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
use clap::{Parser, Subcommand, ValueEnum};
#[derive(Parser)]
#[command(name = "idb")]
#[command(about = "InnoDB file analysis toolkit")]
#[command(version)]
pub struct Cli {
/// Control colored output
#[arg(long, default_value = "auto", global = true)]
pub color: ColorMode,
/// Write output to a file instead of stdout
#[arg(short, long, global = true)]
pub output: Option<String>,
#[command(subcommand)]
pub command: Commands,
}
#[derive(Clone, Copy, ValueEnum)]
pub enum ColorMode {
Auto,
Always,
Never,
}
#[derive(Subcommand)]
pub enum Commands {
/// Parse .ibd file and display page summary
Parse {
/// Path to InnoDB data file (.ibd)
#[arg(short, long)]
file: String,
/// Display a specific page number
#[arg(short, long)]
page: Option<u64>,
/// Display additional information
#[arg(short, long)]
verbose: bool,
/// Skip empty/allocated pages
#[arg(short = 'e', long = "no-empty")]
no_empty: bool,
/// Output in JSON format
#[arg(long)]
json: bool,
/// Override page size (default: auto-detect)
#[arg(long = "page-size")]
page_size: Option<u32>,
},
/// Detailed page structure analysis
Pages {
/// Path to InnoDB data file (.ibd)
#[arg(short, long)]
file: String,
/// Display a specific page number
#[arg(short, long)]
page: Option<u64>,
/// Display additional information
#[arg(short, long)]
verbose: bool,
/// Show empty/allocated pages
#[arg(short = 'e', long = "show-empty")]
show_empty: bool,
/// Compact list mode (one line per page)
#[arg(short, long)]
list: bool,
/// Filter by page type (e.g., INDEX)
#[arg(short = 't', long = "type")]
filter_type: Option<String>,
/// Output in JSON format
#[arg(long)]
json: bool,
/// Override page size (default: auto-detect)
#[arg(long = "page-size")]
page_size: Option<u32>,
},
/// Hex dump of raw page bytes
Dump {
/// Path to InnoDB data file
#[arg(short, long)]
file: String,
/// Page number to dump (default: 0)
#[arg(short, long)]
page: Option<u64>,
/// Absolute byte offset to start dumping (bypasses page mode)
#[arg(long)]
offset: Option<u64>,
/// Number of bytes to dump (default: page size or 256 for offset mode)
#[arg(short, long)]
length: Option<usize>,
/// Output raw binary bytes (no formatting)
#[arg(long)]
raw: bool,
/// Override page size (default: auto-detect)
#[arg(long = "page-size")]
page_size: Option<u32>,
},
/// Intentionally corrupt pages for testing
Corrupt {
/// Path to data file
#[arg(short, long)]
file: String,
/// Page number to corrupt (random if not specified)
#[arg(short, long)]
page: Option<u64>,
/// Number of bytes to corrupt
#[arg(short, long, default_value = "1")]
bytes: usize,
/// Corrupt the FIL header area
#[arg(short = 'k', long = "header")]
header: bool,
/// Corrupt the record data area
#[arg(short, long)]
records: bool,
/// Absolute byte offset to corrupt (bypasses page calculation)
#[arg(long)]
offset: Option<u64>,
/// Show before/after checksum comparison
#[arg(long)]
verify: bool,
/// Output in JSON format
#[arg(long)]
json: bool,
/// Override page size (default: auto-detect)
#[arg(long = "page-size")]
page_size: Option<u32>,
},
/// Search for pages across data directory
Find {
/// MySQL data directory path
#[arg(short, long)]
datadir: String,
/// Page number to search for
#[arg(short, long)]
page: u64,
/// Checksum to match
#[arg(short, long)]
checksum: Option<u32>,
/// Space ID to match
#[arg(short, long)]
space_id: Option<u32>,
/// Stop at first match
#[arg(long)]
first: bool,
/// Output in JSON format
#[arg(long)]
json: bool,
/// Override page size (default: auto-detect)
#[arg(long = "page-size")]
page_size: Option<u32>,
},
/// List/find tablespace IDs
Tsid {
/// MySQL data directory path
#[arg(short, long)]
datadir: String,
/// List all tablespace IDs
#[arg(short, long)]
list: bool,
/// Find table file by tablespace ID
#[arg(short = 't', long = "tsid")]
tablespace_id: Option<u32>,
/// Output in JSON format
#[arg(long)]
json: bool,
/// Override page size (default: auto-detect)
#[arg(long = "page-size")]
page_size: Option<u32>,
},
/// Extract SDI metadata (MySQL 8.0+)
Sdi {
/// Path to InnoDB data file (.ibd)
#[arg(short, long)]
file: String,
/// Pretty-print JSON output
#[arg(short, long)]
pretty: bool,
/// Override page size (default: auto-detect)
#[arg(long = "page-size")]
page_size: Option<u32>,
},
/// Analyze InnoDB redo log files
Log {
/// Path to redo log file (ib_logfile0, ib_logfile1, or #ib_redo*)
#[arg(short, long)]
file: String,
/// Limit to first N data blocks
#[arg(short, long)]
blocks: Option<u64>,
/// Skip empty blocks
#[arg(long)]
no_empty: bool,
/// Display additional information
#[arg(short, long)]
verbose: bool,
/// Output in JSON format
#[arg(long)]
json: bool,
},
/// Show InnoDB file and system information
Info {
/// Inspect ibdata1 page 0 header
#[arg(long)]
ibdata: bool,
/// Compare ibdata1 and redo log LSNs
#[arg(long = "lsn-check")]
lsn_check: bool,
/// MySQL data directory path
#[arg(short, long)]
datadir: Option<String>,
/// Database name (for table/index info)
#[arg(short = 'D', long)]
database: Option<String>,
/// Table name (for table/index info)
#[arg(short, long)]
table: Option<String>,
/// MySQL host
#[arg(long)]
host: Option<String>,
/// MySQL port
#[arg(long)]
port: Option<u16>,
/// MySQL user
#[arg(long)]
user: Option<String>,
/// MySQL password
#[arg(long)]
password: Option<String>,
/// Path to MySQL defaults file (.my.cnf)
#[arg(long = "defaults-file")]
defaults_file: Option<String>,
/// Output in JSON format
#[arg(long)]
json: bool,
/// Override page size (default: auto-detect)
#[arg(long = "page-size")]
page_size: Option<u32>,
},
/// Validate page checksums
Checksum {
/// Path to InnoDB data file (.ibd)
#[arg(short, long)]
file: String,
/// Show per-page checksum details
#[arg(short, long)]
verbose: bool,
/// Output in JSON format
#[arg(long)]
json: bool,
/// Override page size (default: auto-detect)
#[arg(long = "page-size")]
page_size: Option<u32>,
},
}