bbed--常用命令
1、默认密码:blockedit
[oracle@dg1:/home/oracle]#bbed
Password:
BBED: Release 2.0.0.0.0 - Limited Production on Sun Aug 11 22:46:48 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
2、帮助
[oracle@dg1:/home/oracle]#bbed help=y
PASSWORD - Required parameter
FILENAME - Database file name
BLOCKSIZE - Database block size
LISTFILE - List file name
MODE - [browse/edit]
SPOOL - Spool to logfile [no/yes]
CMDFILE - BBED command file name
LOGFILE - BBED log file name
PARFILE - Parameter file name
BIFILE - BBED before-image file name
REVERT - Rollback changes from BIFILE [no/yes]
SILENT - Hide banner [no/yes]
HELP - Show all valid parameters [no/yes]
3、登录bbed
SQL> select file#||' '||name||' '||bytes from v$datafile where file#=5;
FILE#||''||NAME||''||BYTES
--------------------------------------------------------------------------------
5 /home/oracle/test.dbf 524288000
将上述内容保存在filelist.bbed中
[oracle@dg1:/home/oracle]#cat file*
5 /home/oracle/test.dbf 524288000
创建parameter file:
[oracle@dg1:/home/oracle]#vi bbed.par
blocksize=8192
listfile=/home/oracle/filelist.bbed
mode=edit
连接bbed:
[oracle@dg1:/home/oracle]#bbed parfile=bbed.par password=blockedit
BBED: Release 2.0.0.0.0 - Limited Production on Sun Aug 11 23:14:43 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
BBED> show
FILE# 5
BLOCK# 1
OFFSET 0
DBA 0x01400001 (20971521 5,1)
FILENAME /home/oracle/test.dbf
BIFILE bifile.bbd
LISTFILE /home/oracle/filelist.bbed
BLOCKSIZE 8192
MODE Browse
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 80
COUNT 512
LOGFILE log.bbd
SPOOL No
4、bbed命令
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 [ | 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 ]
:
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] =
: [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
: [ value | ]
SUM [ DBA | FILE | FILENAME | BLOCK ] [ APPLY ]
PUSH [ DBA | FILE | FILENAME | BLOCK | OFFSET ]
POP [ALL]
REVERT [ DBA | FILE | FILENAME | BLOCK ]
UNDO
HELP [ | ALL ]
VERIFY [ DBA | FILE | FILENAME | BLOCK ]
CORRUPT [ DBA | FILE | FILENAME | BLOCK ]
下面是几个常用的:
set 设定当前的环境
show 查看当前的环境参数,跟sqlplus的同名命令类似。
dump 列出指定block的内容
find 在指定的block中查找指定的字符串,结果是显示出字符串,及其偏移量--offset,偏移量就是在block中的字节数
modify 修改指定block的指定偏移量的值,可以在线修改。
copy 把一个block的内容copy到另一个block中
verify 检查当前环境是否有坏块
sum 计算block的checksum,modify之后block就被标识为坏块,current checksum与reqired checksum不一致,sum命令可以计算出新的checksum并应用到当前块。
undo 回滚当前的修改操作,如果手误做错了,undo一下就ok了,回到原来的状态。
revert 回滚所有之前的修改操作,意思就是 undo all
SET
set dba
SQL> create table lf.t1 as select user_id,username,created from dba_users;
Table created.
SQL> select rowid,
2 dbms_rowid.rowid_relative_fno(rowid) rel_fno,
3 dbms_rowid.rowid_block_number(rowid) blockno,
4 dbms_rowid.rowid_row_number(rowid) rowno
5 from lf.t1 where user_id=1;
no rows selected
SQL> select * from lf.t1;
USER_ID USERNAME CREATED
---------- ------------------------------ ------------
0 SYS 14-MAY-13
5 SYSTEM 14-MAY-13
37 LF 12-AUG-13
9 OUTLN 14-MAY-13
36 MGMT_VIEW 14-MAY-13
31 APPQOSSYS 14-MAY-13
30 DBSNMP 14-MAY-13
32 WMSYS 14-MAY-13
34 SYSMAN 14-MAY-13
14 DIP 14-MAY-13
21 ORACLE_OCM 14-MAY-13
11 rows selected.
SQL> select rowid,
2 dbms_rowid.rowid_relative_fno(rowid) rel_fno,
3 dbms_rowid.rowid_block_number(rowid) blockno,
4 dbms_rowid.rowid_row_number(rowid) rowno
5 from lf.t1 where user_id=0;
ROWID REL_FNO BLOCKNO ROWNO
------------------ ---------- ---------- ----------
AAAEWmAAFAAAACDAAA 5 131 0
BBED> set dba 5,131
DBA 0x01400083 (20971651 5,131)
如果设置成功,会返回该block的RDBA (Relative Data Block Address),rdba就是rowid中的rfile#+block#。括号里面的是DBA值和block 和 file id。
set filename
BBED> set filename '/home/oracle/test.dbf'
FILENAME /home/oracle/test.dbf
filename必须用单引号
set file
BBED> set file 5
FILE# 5
set block
BBED> set file 5
FILE# 5
BBED> set block 200
BLOCK# 200
BBED> set block +100
BLOCK# 300
block 是一个相对的位置,我们需要先指定一个file,然后在指定block。 即对应file里的block。可以对当前block的位置进行+和-操作。
set offset
偏移量是相对某个block里的偏移量,可以用+和-进行操作
BBED> set offset 10
OFFSET 10
BBED> set offset -5
OFFSET 5
set blocksize
设置当前datafile 的blocksize 大小,该大小必须和datafile 的实际block 匹配,否则会报错。
BBED> set blocksize 8192
BLOCKSIZE 8192
set listfile
在前面讲过,可以通过parameter file 来指定bbed的属性,当然也可以通过set 来指定这些信息。对于listfile的文件,必须用单引号括起来。
BBED> set listfile '/u01/filelist.txt'
LISTFILE /u01/filelist.txt
set width
设定当前屏幕的宽度,默认是80.
BBED> set width 200
WIDTH 200
set count
设置dump 命令显示bytes的数量。默认是512 bytes。
BBED> set count 512
COUNT 512
set ibase
--设置内部的数字格式,默认是十进制。 也可以设置为十六进制或者八进制。设置完数字格式之后,使用该格式来设置blcok,offset等。
BBED> set ibase hex
IBASE Hex
BBED> set block +D
BLOCK# 14
BBED> set ibase decimal
IBASE Dec
set mode
BBED> set mode browse
MODE Browse
BBED> set mode edit
MODE Edit
SHOW
BBED> show
FILE# 5
BLOCK# 300
OFFSET 5
DBA 0x0140012c (20971820 5,300)
FILENAME /home/oracle/test.dbf
BIFILE bifile.bbd
LISTFILE /home/oracle/filelist.bbed
BLOCKSIZE 8192
MODE Edit
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 80
COUNT 512
LOGFILE log.bbd
SPOOL No
INFO
BBED> info
File# Name Size(blks)
----- ---- ----------
5 /home/oracle/test.dbf 64000
显示当前可以进行browse 或者edit 的file。即我们filelist 里指定的datafile信息。
MAP
Map会通过偏移量来显示block里的详细信息,如block header,data block header 和row directory。 使用/v 选项,可以查看更详细的信息。
在不指定block的情况下,会显示当前block的信息,如果想显示其他block的信息,可以使用file name,file id,block 和DBA 来指定要显示的block。
BBED> map
File: /home/oracle/test.dbf (5)
Block: 131 Dba:0x01400083
------------------------------------------------------------
KTB Data Block (Table/Cluster)
struct kcbh, 20 bytes @0
struct ktbbh, 96 bytes @20
struct kdbh, 14 bytes @124
struct kdbt[1], 4 bytes @138
sb2 kdbr[11] @142
ub1 freespace[7796] @164
ub1 rowdata[228] @7960
ub4 tailchk @8188
--这个是默认情况,@后面代表的对应的信息在block里的偏移量,即offset。
BBED> map /v dba 5,131
File: /home/oracle/test.dbf (5)
Block: 131 Dba:0x01400083
------------------------------------------------------------
KTB Data Block (Table/Cluster)
struct kcbh, 20 bytes @0
ub1 type_kcbh @0
ub1 frmt_kcbh @1
ub1 spare1_kcbh @2
ub1 spare2_kcbh @3
ub4 rdba_kcbh @4
ub4 bas_kcbh @8
ub2 wrp_kcbh @12
ub1 seq_kcbh @14
ub1 flg_kcbh @15
ub2 chkval_kcbh @16
ub2 spare3_kcbh @18
struct ktbbh, 96 bytes @20
ub1 ktbbhtyp @20
union ktbbhsid, 4 bytes @24
struct ktbbhcsc, 8 bytes @28
sb2 ktbbhict @36
ub1 ktbbhflg @38
ub1 ktbbhfsl @39
ub4 ktbbhfnx @40
struct ktbbhitl[3], 72 bytes @44
struct kdbh, 14 bytes @124
ub1 kdbhflag @124
sb1 kdbhntab @125
sb2 kdbhnrow @126
sb2 kdbhfrre @128
sb2 kdbhfsbo @130
sb2 kdbhfseo @132
sb2 kdbhavsp @134
sb2 kdbhtosp @136
struct kdbt[1], 4 bytes @138
sb2 kdbtoffs @138
sb2 kdbtnrow @140
sb2 kdbr[11] @142
ub1 freespace[7796] @164
ub1 rowdata[228] @7960
ub4 tailchk @8188
--通过block 来map
BBED> map block 131
File: /home/oracle/test.dbf (5)
Block: 131 Dba:0x01400083
------------------------------------------------------------
KTB Data Block (Table/Cluster)
struct kcbh, 20 bytes @0
struct ktbbh, 96 bytes @20
struct kdbh, 14 bytes @124
struct kdbt[1], 4 bytes @138
sb2 kdbr[11] @142
ub1 freespace[7796] @164
ub1 rowdata[228] @7960
ub4 tailchk @8188
DUMP(D)
显示block的具体内容,每次显示的bytes由count 控制,默认是512 bytes。 使用 /v 选项,可以显示更多详细信息。
BBED> dump /v dba 5,131 offset 0 count 128
File: /home/oracle/test.dbf (5)
Block: 131 Offsets: 0 to 127 Dba:0x01400083
-------------------------------------------------------
06a20000 83004001 3a0b0600 00000204 l ......@.:.......
bef40000 01000000 a6450000 380b0600 l .........E..8...
00000000 03003200 80004001 ffff0000 l ......2...@.....
00000000 00000000 00000000 00800000 l ................
380b0600 00000000 00000000 00000000 l 8...............
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00010b00 l ................
<16 bytes per line>
PRINT(P)
print命令输出datastructures。 在使用print时,可以指定dba,block 等参数来限定输出特定block。
BBED> p kdbt
struct kdbt[0], 4 bytes @138
sb2 kdbtoffs @138 0
sb2 kdbtnrow @140 11
BBED> p kdbt.kdbtoffs
sb2 kdbtoffs @138 0
注意:
当print 一个data structure 时,输出的格式如下:
UnitSize* | Name | Offset| Value
BBED> p kdbr
sb2 kdbr[0] @142 8047
sb2 kdbr[1] @144 8026
sb2 kdbr[2] @146 8009
sb2 kdbr[3] @148 7989
sb2 kdbr[4] @150 7965
sb2 kdbr[5] @152 7941
sb2 kdbr[6] @154 7920
sb2 kdbr[7] @156 7900
sb2 kdbr[8] @158 7879
sb2 kdbr[9] @160 7861
sb2 kdbr[10] @162 7836
在pointer 加前缀* 可以print location data structure。
使用kdbr[0] 作为一个指针来print 它对应的内容。这个kdbr[0] 是一个本地的data structure,我们print 需要加*号前缀。
BBED> p *kdbr[0]
rowdata[211]
------------
ub1 rowdata[211] @8171 0x2c
BBED> dump /v dba 5,131 offset 8171 count 128
File: /home/oracle/test.dbf (5)
Block: 131 Offsets: 8171 to 8191 Dba:0x01400083
-------------------------------------------------------
2c000301 80035359 53077871 050e0336 l ,.....SYS.xq...6
1a02063a 0b l ...:.
<16 bytes per line>
定位绝对offset
BBED> p offset 8171
rowdata[211]
------------
ub1 rowdata[211] @8171 0x2c
改16进制为10进制
BBED> p /d offset 8171
rowdata[211]
------------
ub1 rowdata[211] @8171 44
EXAMINE(X)
examine命令也是用来显示datablock的内容的,解释说明
BBED> x /rcnn
rowdata[190] @8150
------------
flag@8150: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8151: 0x00
cols@8152: 3
col 0[2] @8153: ..
col 1[6] @8156: #########################################
col 2[7] @8163: #########################################
可以repeat
BBED> x /3rcnn
rowdata[190] @8150
------------
flag@8150: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8151: 0x00
cols@8152: 3
col 0[2] @8153: ..
col 1[6] @8156: #########################################
col 2[7] @8163: #########################################
rowdata[211] @8171
------------
flag@8171: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8172: 0x00
cols@8173: 3
col 0[1] @8174: .
col 1[3] @8176: #########################################
col 2[7] @8180: #########################################
tailchk @8188
-------
BBED-00210: no row at this offset
FIND(F)
find命令可以用来搜索关键字。 可以从offset 0 搜索到top 或者从当前的offset 搜索到top。
find 不支持number和Date
SQL> select rowid,
2 dbms_rowid.rowid_relative_fno(rowid) rel_fno,
3 dbms_rowid.rowid_block_number(rowid) blockno,
4 dbms_rowid.rowid_row_number(rowid) rowno,
5 user_id,username,created
6 from lf.t1 where user_id=5;
ROWID REL_FNO BLOCKNO ROWNO USER_ID USERNAME CREATED
------------------ ---------- ---------- ---------- ---------- ------------------------------ ------------
AAAEWmAAFAAAACDAAB 5 131 1 5 SYSTEM 14-MAY-13
BBED> set file 5
FILE# 5
BBED> set block 131
BLOCK# 131
BBED> set offset 0
OFFSET 0
BBED> find /c SYSTEM top
File: /home/oracle/test.dbf (5)
Block: 131 Offsets: 8157 to 8191 Dba:0x01400083
------------------------------------------------------------------------
53595354 454d0778 71050e03 361a2c00 03018003 53595307 7871050e 03361a02
063a0b
<32 bytes per line>
BBED> d /v dba 5,131 offset 8157 count 128
File: /home/oracle/test.dbf (5)
Block: 131 Offsets: 8157 to 8191 Dba:0x01400083
-------------------------------------------------------
53595354 454d0778 71050e03 361a2c00 l SYSTEM.xq...6.,.
03018003 53595307 7871050e 03361a02 l ....SYS.xq...6..
063a0b l .:.
<16 bytes per line>
如果我们要继续搜索Dave,那么只需要按下f 就可以了,不需要跟参数。
BBED> f
BBED-00212: search string not found
COPY
BBED> copy dba 5,131 to dba 5,132
MODIFY(M)
BBED> d /v dba 5,131 offset 8157 count 128
File: /home/oracle/test.dbf (5)
Block: 131 Offsets: 8157 to 8191 Dba:0x01400083
-------------------------------------------------------
53595354 454d0778 71050e03 361a2c00 l SYSTEM.xq...6.,.
03018003 53595307 7871050e 03361a02 l ....SYS.xq...6..
063a0b l .:.
<16 bytes per line>
BBED> modify /c LINFENG dba 5,131 offset 8157
File: /home/oracle/test.dbf (5)
Block: 131 Offsets: 8157 to 8191 Dba:0x01400083
------------------------------------------------------------------------
4c494e46 454e4778 71050e03 361a2c00 03018003 53595307 7871050e 03361a02
063a0b
<32 bytes per line>
BBED> d /v dba 5,131 offset 8157 count 128
File: /home/oracle/test.dbf (5)
Block: 131 Offsets: 8157 to 8191 Dba:0x01400083
-------------------------------------------------------
4c494e46 454e4778 71050e03 361a2c00 l LINFENGxq...6.,.
03018003 53595307 7871050e 03361a02 l ....SYS.xq...6..
063a0b l .:.
<16 bytes per line>
注意一点,这里仅仅是修改,还没有进行update,即sum apply, select 才会改变。
SQL> select * from lf.t1 where user_id=5;
USER_ID USERNAME CREATED
---------- ------------------------------ ------------
5 SYSTEM 14-MAY-13
SUM
BBED> sum dba 5,131 apply
Check value for File 5, Block 131:
current = 0xb6bf, required = 0xb6bf
SQL> alter system flush buffer_cache;
SQL> select * from lf.t1 where user_id=5;
USER_ID USERNAME CREATED
---------- ------------------------------ ------------
5 LINFENG 14-MAY-13
REVERT
revert是恢复自bbed 启动以来的所有修改。
BBED> revert dba 5,131
All changes made to this block will be rolled back. Proceed? (Y/N) y
Reverted file '/home/oracle/test.dbf', block 131
BBED> sum dba 5,131 apply
Check value for File 5, Block 131:
current = 0xf4be, required = 0xf4be
SQL> select * from lf.t1 where user_id=5;
USER_ID USERNAME CREATED
---------- ------------------------------ ------------
5 LINFENG 14-MAY-13
SQL> alter system flush buffer_cache;
SQL> select * from lf.t1 where user_id=5;
USER_ID USERNAME CREATED
---------- ------------------------------ ------------
5 SYSTEM 14-MAY-13
UNDO
undo命令是回滚最后一次的操作。
BBED> dump /v dba 5,131 offset 8157
File: /home/oracle/test.dbf (5)
Block: 131 Offsets: 8157 to 8191 Dba:0x01400083
-------------------------------------------------------
53595354 454d0778 71050e03 361a2c00 l SYSTEM.xq...6.,.
03018003 53595307 7871050e 03361a02 l ....SYS.xq...6..
063a0b l .:.
<16 bytes per line>
BBED> m /c LF dba 5,131 offset 8157
File: /home/oracle/test.dbf (5)
Block: 131 Offsets: 8157 to 8191 Dba:0x01400083
------------------------------------------------------------------------
4c465354 454d0778 71050e03 361a2c00 03018003 53595307 7871050e 03361a02
063a0b
<32 bytes per line>
BBED> d /v dba 5,131 offset 8157
File: /home/oracle/test.dbf (5)
Block: 131 Offsets: 8157 to 8191 Dba:0x01400083
-------------------------------------------------------
4c465354 454d0778 71050e03 361a2c00 l LFSTEM.xq...6.,.
03018003 53595307 7871050e 03361a02 l ....SYS.xq...6..
063a0b l .:.
<16 bytes per line>
BBED> undo
BBED> modify /x 5359 filename '/home/oracle/test.dbf' block 131. offset 8157.
File: /home/oracle/test.dbf (5)
Block: 131 Offsets: 8157 to 8191 Dba:0x01400083
------------------------------------------------------------------------
53595354 454d0778 71050e03 361a2c00 03018003 53595307 7871050e 03361a02
063a0b
<32 bytes per line>
BBED> d /v dba 5,131 offset 8157
File: /home/oracle/test.dbf (5)
Block: 131 Offsets: 8157 to 8191 Dba:0x01400083
-------------------------------------------------------
53595354 454d0778 71050e03 361a2c00 l SYSTEM.xq...6.,.
03018003 53595307 7871050e 03361a02 l ....SYS.xq...6..
063a0b l .:.
<16 bytes per line>
VERIFY
verify命令用来验证block的完整性。
BBED> verify dba 5,131
DBVERIFY - Verification starting
FILE = /home/oracle/test.dbf
BLOCK = 131
DBVERIFY - Verification complete
Total Blocks Examined : 1
Total Blocks Processed (Data) : 1
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
CORRUPT
corrupt命令将一个block 标记为corrupt,这样db 在操作时就会跳过该block,从而避免错误。
注意: undo 命令不能undo 一个corruption,但是revert 命令却可以。
BBED> corrupt dba 5,131
Block marked media corrupt.
BBED> revert dba 5,131
All changes made to this block will be rolled back. Proceed? (Y/N) y
Reverted file '/home/oracle/test.dbf', block 131
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24996904/viewspace-768323/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/24996904/viewspace-768323/