跳到主要内容

BBED工具使用说明

BBED工具概述

Oracle BBED(Block Browser and Editor)是一个用于浏览和编辑Oracle数据库块的实用工具。它通常被用于数据库恢复、数据修复和深度分析等场景。

BBED允许用户直接查看和修改数据库块的内容,包括数据块头、数据区和控制信息等。它可以绕过Oracle数据库的一些限制,提供更底层的访问和操作能力。

数据块结构:Oracle数据库使用数据块作为存储和管理数据的最小单位,每个数据块通常包含固定大小的字节。BBED工具提供了解析和编辑数据块中各个部分的能力,例如数据块头、行数据、索引和控制信息。

数据恢复:BBED工具可以用于数据库恢复的过程中,特别是在出现损坏或损失的数据块时。通过直接修改数据块的内容,可以尝试修复损坏的数据或者从备份中恢复丢失的数据。

数据分析:BBED工具还可以用于深度分析数据库块的结构和内容。通过查看数据块的各个部分,可以了解数据库中存储的数据、索引和控制信息的组织方式,帮助排查性能问题或进行数据库结构优化。

注意事项:由于BBED工具提供了对数据库块的底层访问和操作能力,使用它需要具备相当的数据库知识和经验,并且需要特别谨慎。错误的操作可能导致数据丢失或数据库不一致。在使用BBED之前,建议先在非生产环境中进行测试和熟悉工具的使用。

如何编译bbed环境

编译bbed
cd $ORACLE_HOME/rdbms/lib
make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed

# 修改环境变量
$ORACLE_HOME/rdbms/lib 加入到PATH变量中,如下:
PATH=$ORACLE_HOME/bin:$PATH:/home/ora10g/product/10.2/rdbms/lib; export PATH

# 11g以及12c以上版本编译bbed:
# copy 如下文件到11g环境中对于目录:
cp $ORACLE_10g_HOME/rdbms/lib/ssbbded.o $ORACLE_11g_HOME/rdbms/lib
cp $ORACLE_10g_HOME/rdbms/lib/sbbdpt.o $ORACLE_11g_HOME/rdbms/lib
cp $ORACLE_10g_HOME/rdbms/mesg/bbedus.msb $ORACLE_11g_HOME/rdbms/mesg
cp $ORACLE_10g_HOME/rdbms/mesg/bbedus.msg $ORACLE_11g_HOME/rdbms/mesg

# 编译bbed
cd $ORACLE_HOME/rdbms/lib
make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed

BBED相关配置

默认密码

  • blockedit
  • 免密码登陆
    • alias bbed='bbed parfile=par.txt password=blockedit'

准备par文件

par.bbed(文件名可自定义):

blocksize=8192 ---指定block size大小
listfile=listfile.txt ---指定文件名
mode=edit ---指定操作模式(分edit和view两种)
spool=yes ---是否记录bbed的操作日志
bbed parfile=par.bbed

准备listfile.txt

# listfile.txt(文件名可自定义):
select file# ||chr(9)||name||chr(9)||bytes from v$datafile;
说明:
1) 第1列,为文件号,可以人为定义。
2) 第2列,需要使用bbed操作的文件名(全路径)。
3) 第3列,文件大小,可不写。

BBED命令说明

help命令

BBED> help all
SET DBA [ dba | file#, block# ]
SET FILENAME 'filename'
SET FILE file#
SET BLOCK [+/-]block#
SET OFFSET [ [+/-]byte offset | symbol | *symbol ]
SET BLOCKSIZE bytes
SET LIST[FILE] 'filename'
SET WIDTH character_count
SET COUNT bytes_to_display
SET IBASE [ HEX | OCT | DEC ]
SET OBASE [ HEX | OCT | DEC ]
SET MODE [ BROWSE | EDIT ]
SET SPOOL [ Y | N ]
SHOW [ <SET parameter | ALL ]
INFO
MAP[/v] [ DBA | FILENAME | FILE | BLOCK ]
DUMP[/v] [ DBA | FILENAME | FILE | BLOCK | OFFSET | COUNT ]
PRINT[/x|d|u|o|c] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
EXAMINE[/Nuf] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
</Nuf:
N - a number which specifies a repeat count.
u - a letter which specifies a unit size:
b - b1, ub1 (byte)
h - b2, ub2 (half-word)
w - b4, ub4(word)
r - Oracle table/index row
f - a letter which specifies a display format:
x - hexadecimal
d - decimal
u - unsigned decimal
o - octal
c - character (native)
n - Oracle number
t - Oracle date
i - Oracle rowid
FIND[/x|d|u|o|c] numeric/character string [ TOP | CURR ]
COPY [ DBA | FILE | FILENAME | BLOCK ] TO [ DBA | FILE | FILENAME | BLOCK ]
MODIFY[/x|d|u|o|c] numeric/character string
[ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
ASSIGN[/x|d|u|o] <target spec=<source spec
<target spec : [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
<source spec : [ value | <target spec options ]
SUM [ DBA | FILE | FILENAME | BLOCK ] [ APPLY ]
PUSH [ DBA | FILE | FILENAME | BLOCK | OFFSET ]
POP [ALL]
REVERT [ DBA | FILE | FILENAME | BLOCK ]
UNDO
HELP [ <bbed command | ALL ]
VERIFY [ DBA | FILE | FILENAME | BLOCK ]
CORRUPT [ DBA | FILE | FILENAME | BLOCK ]

set命令

BBED> help set
SET DBA [ dba | file#, block# ] ---set dba地址或文件号,块号
SET FILENAME 'filename' ---set 数据文件名
SET FILE file# ---set 数据文件号
SET BLOCK [+/-]block# ---set 块号
SET OFFSET [ [+/-]byte offset | symbol | *symbol ] ---set offset(即偏移量)
SET BLOCKSIZE bytes ----set block大小
SET LIST[FILE] 'filename' ----set list文件
SET WIDTH character_count ----设置显示宽度
SET COUNT bytes_to_display ----设置显示bytes数目
SET IBASE [ HEX | OCT | DEC ] ----设置进制模式hex 16进制 oct 8进制 dec 10进制
SET OBASE [ HEX | OCT | DEC ]
SET MODE [ BROWSE | EDIT ] ---设置操作模式 查看模式或编辑模式
SET SPOOL [ Y | N ] ---是否保存操作日志

map命令

BBED help map   
MAP[/v] [ DBA | FILENAME | FILE | BLOCK ]

用法:
BBED map /v file 1 block 1
File: /oracle/backup/system.dbf (1)
Block: 1 Dba:0x00400001
------------------------------------------------------------
Data File Header

struct kcvfh, 676 bytes @0
struct kcvfhbfh, 20 bytes @0
struct kcvfhhdr, 76 bytes @20
ub4 kcvfhrdb @96
struct kcvfhcrs, 8 bytes @100
ub4 kcvfhcrt @108
ub4 kcvfhrlc @112
struct kcvfhrls, 8 bytes @116
ub4 kcvfhbti @124
struct kcvfhbsc, 8 bytes @128
ub2 kcvfhbth @136
ub2 kcvfhsta @138
struct kcvfhckp, 36 bytes @484
ub4 kcvfhcpc @140
ub4 kcvfhrts @144
ub4 kcvfhccc @148
struct kcvfhbcp, 36 bytes @152
ub4 kcvfhbhz @312
struct kcvfhxcd, 16 bytes @316
word kcvfhtsn @332
ub2 kcvfhtln @336
text kcvfhtnm[30] @338
ub4 kcvfhrfn @368
struct kcvfhrfs, 8 bytes @372
ub4 kcvfhrft @380
struct kcvfhafs, 8 bytes @384
ub4 kcvfhbbc @392
ub4 kcvfhncb @396
ub4 kcvfhmcb @400
ub4 kcvfhlcb @404
ub4 kcvfhbcs @408
ub2 kcvfhofb @412
ub2 kcvfhnfb @414
ub4 kcvfhprc @416
struct kcvfhprs, 8 bytes @420
struct kcvfhprfs, 8 bytes @428
ub4 kcvfhtrt @444
ub4 tailchk @8188

print命令

  • 通常配合map使用
BBED help print
PRINT[/x|d|u|o|c] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
说明:
x ----16进制
d ----10进制
u ----无正负之分的10进制 ---不需关注
o ----8进制
c ----字符 ---不需关注

示例如下:
BBED p /x file 1 block 1
kcvfh.kcvfhbfh.type_kcbh
------------------------
ub1 type_kcbh @0 0x0b
BBED p kcvfhbfh
struct kcvfhbfh, 20 bytes @0
ub1 type_kcbh @0 0x0b
ub1 frmt_kcbh @1 0xa2
ub1 spare1_kcbh @2 0x00
ub1 spare2_kcbh @3 0x00
ub4 rdba_kcbh @4 0x00400001
ub4 bas_kcbh @8 0x00000000
ub2 wrp_kcbh @12 0x0000
ub1 seq_kcbh @14 0x01
ub1 flg_kcbh @15 0x04 (KCBHFCKV)
ub2 chkval_kcbh @16 0x0ca9
ub2 spare3_kcbh @18 0x0000

dump命令

  • 默认dump 512 bytes
BBED help dump
DUMP[/v] [ DBA | FILENAME | FILE | BLOCK | OFFSET | COUNT ]

用法: dump可以简写为d
d /v file 1 block 1 offset 2 count 32 2+32-1

示例:

BBED d /v file 1 block 1 offset 2 count 32
File: /oracle/backup/system.dbf (1)
Block: 1 Offsets: 2 to 33 Dba:0x00400001
-------------------------------------------------------
00000100 40000000 00000000 0104a90c l ....@.........?
00000000 00000003 200ada51 c977414c l ........ .赒蓋AL

<16 bytes per line ----count值 32 =每行16bytes * 行数 2

find命令

  • 查找我们需要修改或查找的byte
BBED help find
FIND[/x|d|u|o|c] numeric/character string [ TOP | CURR ]

说明:
x ---16 进制
d ---10进制
u ---- 无需关注
o ----8进制
c ---字符

TOP:从开始位置
CURR:从当前位置查找 默认

示例:
BBED find /x 414c4558
File: /oracle/backup/system.dbf (1)
Block: 1 Offsets: 32 to 543 Dba:0x00400001
------------------------------------------------------------------------
414c4558 00000000 4f020000 00f00000 00200000 01000300 00000000 00000000

BBED find /c ALEX
File: /oracle/backup/system.dbf (1)
Block: 1 Offsets: 32 to 543 Dba:0x00400001
------------------------------------------------------------------------
414c4558 00000000 4f020000 00f00000 00200000 01000300 00000000 00000000

copy命令

  • 用于修改或备份
BBED help copy
COPY [ DBA | FILE | FILENAME | BLOCK ] TO [ DBA | FILE | FILENAME | BLOCK ]
用法:copy file 1 block 1 to file 5 block 100

示例:
BBED copy file 1 block 1 to file 6 block 1
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /oracle/backup/control.ctl (6)
Block: 1 Offsets: 0 to 511 Dba:0x01800001
------------------------------------------------------------------------
0ba20000 01004000 00000000 00000104 a90c0000 00000000 0003200a da51c977

revert命令

  • revert是恢复自bbed 启动以来的所有修改(包含被sum apply的数据)

modify命令

  • 修改命令,最重要的命令
BBED modify /x 999999  
File: /oracle/backup/control.ctl (6)
Block: 1 Offsets: 64 to 575 Dba:0x01800001
------------------------------------------------------------------------
99999932 30313031 32313154 32303237 33310000 00000000 00000000 00000000

sum命令

  • 用于计算check sum,或修改后进行apply
  • sum apply
BBED help sum
SUM [ DBA | FILE | FILENAME | BLOCK ] [ APPLY ]

BBED sum
Check value for File 6, Block 1:
current = 0x7dad, required = 0xa5be

BBED sum file 6 block 1 apply
Check value for File 6, Block 1:
current = 0xa5be, required = 0xa5be

verify命令

  • 常用于校验坏块
BBED help VERIFY
VERIFY [ DBA | FILE | FILENAME | BLOCK ]
示例:
BBED verify file 6 block 1
DBVERIFY - Verification starting
FILE = /oracle/backup/control.ctl
BLOCK = 1
DBVERIFY - Verification complete
Total Blocks Examined : 1
Total Blocks Processed (Data) : 0
Total Blocks Failing (Data) : 0
Total Blocks Processed (Index): 0
Total Blocks Failing (Index): 0
Total Blocks Empty : 0
Total Blocks Marked Corrupt : 0
Total Blocks Influx : 0
BBED verify dba 0x01800001
DBVERIFY - Verification starting
FILE = /oracle/backup/control.ctl
BLOCK = 1
DBVERIFY - Verification complete
Total Blocks Examined : 1
Total Blocks Processed (Data) : 0
Total Blocks Failing (Data) : 0
Total Blocks Processed (Index): 0
Total Blocks Failing (Index): 0
Total Blocks Empty : 0
Total Blocks Marked Corrupt : 0
Total Blocks Influx : 0

标记命令

  • tailchk = kcbh.bas_kcbh(后四位)+ kcbh.type_kcbh + kcbh.seq_kcbh