bbed--常用命令

linfeng_oracle發表於2013-08-12

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 ]
<source>
<source>

下面是幾個常用的:

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/,如需轉載,請註明出處,否則將追究法律責任。