[20161118]rman备份的疑问2.txt
--这个是我前几天做测试时遇到的疑问,不知道为什么rman 备份要修改数据块的dba地址。
--我在itpub上也问了这个问题,链接http://www.itpub.net/thread-2071504-1-1.html,可惜没有人解答。
--具体细节不清楚,读取数据文件然后重新编码组织数据,将kcbh.rdba_kcbh的后2位放入tailchk中,设置spare3_kcbh=0x0001,
--也许为了区分备份与数据文件,当然还有别的目的,再做一些测试:
1.环境:
SCOTT@book> @ &r/ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
CREATE TABLESPACE SUGAR DATAFILE
'/mnt/ramdisk/book/sugar01.dbf' SIZE 40M AUTOEXTEND ON NEXT 16M MAXSIZE UNLIMITED
LOGGING
ONLINE
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;
SCOTT@book> create table t1 (id number,name varchar2(20)) tablespace sugar;
Table created.
--打开2个session插入不同的记录:
insert into t1 values(1,'A1B2C3D4E5');
commit ;
--另外会话:
insert into t1 values(2,'F6G7H8I9J0');
commit ;
alter system checkpoint ;
SCOTT@book> select rowid,t1.* from t1;
ROWID ID NAME
------------------ ---------- --------------------
AAAVvZAAGAAAACGAAA 1 A1B2C3D4E5
AAAVvZAAGAAAACHAAA 2 F6G7H8I9J0
SCOTT@book> @ &r/rowid AAAVvZAAGAAAACGAAA
OBJECT FILE BLOCK ROW ROWID_DBA DBA TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
89049 6 134 0 0x1800086 6,134 alter system dump datafile 6 block 134 ;
SCOTT@book> @ &r/rowid AAAVvZAAGAAAACHAAA
OBJECT FILE BLOCK ROW ROWID_DBA DBA TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
89049 6 135 0 0x1800087 6,135 alter system dump datafile 6 block 135 ;
--这样可以实现插入不同的块。
2.备份数据文件。
RMAN> backup datafile 6 format '/u01/backup/d6_a.bak' ;
Starting backup at 2016-11-17 11:40:11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=35 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/mnt/ramdisk/book/sugar01.dbf
channel ORA_DISK_1: starting piece 1 at 2016-11-17 11:40:12
channel ORA_DISK_1: finished piece 1 at 2016-11-17 11:40:13
piece handle=/u01/backup/d6_a.bak tag=TAG20161117T114012 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-11-17 11:40:13
$ strings -td /u01/backup/d6_a.bak| egrep 'A1B2C3D4E5|F6G7H8I9J0'
1114098 A1B2C3D4E5
1122290 F6G7H8I9J0
--1114098/8192=135.998291015625
--1122290/8192=136.998291015625
BBED> p filename '/u01/backup/d6_a.bak' block 135 kcbh.rdba_kcbh
ub4 rdba_kcbh @4 0x01800087
BBED> p filename '/u01/backup/d6_a.bak' block 136 kcbh.rdba_kcbh
ub4 rdba_kcbh @4 0x01800088
BBED> set dba 0x01800087
DBA 0x01800087 (25165959 6,135)
BBED> set dba 0x01800088
DBA 0x01800088 (25165960 6,136)
--现在是不一致的(与前面对照)。
3.修改数据块spare3_kcbh=0x0001看看:
SCOTT@book> alter tablespace SUGAR offline;
Tablespace altered.
BBED> p dba 6,134 spare3_kcbh
ub2 spare3_kcbh @18 0x0000
BBED> p filename '/u01/backup/d6_a.bak' block 135 spare3_kcbh
ub2 spare3_kcbh @18 0x0001
--前次提到备份修改spare3_kcbh=0x0001.我修改数据块看看。
BBED> assign dba 6,134 spare3_kcbh=0x0001
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
ub2 spare3_kcbh @18 0x0001
BBED> sum
Check value for File 6, Block 134:
current = 0xace3, required = 0xace2
BBED> sum apply dba 6,134
Check value for File 6, Block 134:
current = 0xace2, required = 0xace2
BBED> verify
DBVERIFY - Verification starting
FILE = /mnt/ramdisk/book/sugar01.dbf
BLOCK = 134
Block 134 is corrupt
Corrupt block relative dba: 0x01800086 (file 0, block 134)
Bad header found during verification
Data in bad block:
type: 6 format: 2 rdba: 0x01800086
last change scn: 0x0000.0065f43a seq: 0x1 flg: 0x06
spare1: 0x0 spare2: 0x0 spare3: 0x1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 从这里看出这些在某种情况下具有特殊含义。
consistency value in tail: 0xf43a0601
check value in block header: 0xace2
computed block checksum: 0x0
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 : 1
Total Blocks Influx : 0
Message 531 not found; product=RDBMS; facility=BBED
--可以发现数据块根本不能设置这个值,恢复回来。
BBED> assign dba 6,134 spare3_kcbh=0x0000
ub2 spare3_kcbh @18 0x0000
BBED> sum apply dba 6,134
Check value for File 6, Block 134:
current = 0xace3, required = 0xace3
BBED> verify
DBVERIFY - Verification starting
FILE = /mnt/ramdisk/book/sugar01.dbf
BLOCK = 134
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
Message 531 not found; product=RDBMS; facility=BBED
4.做一个无聊的测试,实现2个块对调,必须重新编码,测试自己的理解是否正确。
SCOTT@book> alter tablespace SUGAR online;
Tablespace altered.
SCOTT@book> select rowid,t1.* from t1;
ROWID ID NAME
------------------ ---------- --------------------
AAAVvZAAGAAAACGAAA 1 A1B2C3D4E5
AAAVvZAAGAAAACHAAA 2 F6G7H8I9J0
SCOTT@book> alter tablespace SUGAR offline;
Tablespace altered.
--先交换
bvi -b 1105920 -s 8192 /u01/backup/d6_a.bak => 另存为 135.bin
bvi -b 1114112 -s 8192 /u01/backup/d6_a.bak => 另存为 136.bin
dd if=135.bin of=/u01/backup/d6_a.bak seek=136 bs=8192 count=1 conv=notrunc
dd if=136.bin of=/u01/backup/d6_a.bak seek=135 bs=8192 count=1 conv=notrunc
2.bbed修改相关信息:
BBED> p filename '/u01/backup/d6_a.bak' block 135 rdba_kcbh
ub4 rdba_kcbh @4 0x01800088
BBED> p filename '/u01/backup/d6_a.bak' block 136 rdba_kcbh
ub4 rdba_kcbh @4 0x01800087
BBED> p filename '/u01/backup/d6_a.bak' block 135 tailchk
ub4 tailchk @8188 0xf4400687
BBED> p filename '/u01/backup/d6_a.bak' block 136 tailchk
ub4 tailchk @8188 0xf43a0686
--修改如下:
BBED> assign filename '/u01/backup/d6_a.bak' block 135 rdba_kcbh=0x01800087
ub4 rdba_kcbh @4 0x01800087
BBED> assign filename '/u01/backup/d6_a.bak' block 136 rdba_kcbh=0x01800088
ub4 rdba_kcbh @4 0x01800088
BBED> modify /x 0x86 filename '/u01/backup/d6_a.bak' block 135 offset 8188
File: /u01/backup/d6_a.bak (0)
Block: 135 Offsets: 8188 to 8191 Dba:0x00000000
---------------------------------------------------------------------
860640f4
<64 bytes per line>
BBED> modify /x 0x87 filename '/u01/backup/d6_a.bak' block 136 offset 8188
File: /u01/backup/d6_a.bak (0)
Block: 136 Offsets: 8188 to 8191 Dba:0x00000000
----------------------------------------------------------------------
87063af4
<64 bytes per line>
BBED> sum apply filename '/u01/backup/d6_a.bak' block 135
Check value for File 0, Block 135:
current = 0xa596, required = 0xa596
BBED> sum apply filename '/u01/backup/d6_a.bak' block 136
Check value for File 0, Block 136:
current = 0xac6a, required = 0xac6a
RMAN> validate backupset 87;
Starting validate at 2016-11-17 15:46:39
using channel ORA_DISK_1
channel ORA_DISK_1: starting validation of datafile backup set
channel ORA_DISK_1: reading from backup piece /u01/backup/d6_a.bak
channel ORA_DISK_1: piece handle=/u01/backup/d6_a.bak tag=TAG20161117T114012
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: validation complete, elapsed time: 00:00:01
Finished validate at 2016-11-17 15:46:40
RMAN> restore tablespace sugar;
Starting restore at 2016-11-17 15:47:21
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00006 to /mnt/ramdisk/book/sugar01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/d6_a.bak
channel ORA_DISK_1: piece handle=/u01/backup/d6_a.bak tag=TAG20161117T114012
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2016-11-17 15:47:22
RMAN> recover tablespace sugar;
Starting recover at 2016-11-17 15:47:41
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 2016-11-17 15:47:41
SCOTT@book> alter tablespace SUGAR online;
Tablespace altered.
SCOTT@book> select rowid,t1.* from t1;
ROWID ID NAME
------------------ ---------- --------------------
AAAVvZAAGAAAACGAAA 2 F6G7H8I9J0
AAAVvZAAGAAAACHAAA 1 A1B2C3D4E5
--对比前面实现了2个数据块对调,也验证我的判断是对的。