[20161031]rman备份与数据文件OS块.txt
[20161031]rman備份與數據文件OS塊.txt
--每個數據文件都有一個OS塊,位于數據文件的第1塊(也是0塊).通過bbed無法訪問:
BBED> set dba 7,0
BBED-00205: illegal or out of range DBA (File 7, Block 0)
BBED> set dba 7,1
??????? DBA???????????? 0x01c00001 (29360129 7,1)
BBED> dump
File: /mnt/ramdisk/book/tea01.dbf (7)
Block: 1??????????????????????????????????????????????????? Offsets:??? 0 to?? 63?????????????????????????????????????????????? Dba:0x01c00001
------------------------------------------------------------------------------------------------------------------------------------------------
0ba20000 0100c001 00000000 00000104 14b50000 00000000 0004200b 6e21b74f 424f4f4b 00000000 6a4b0000 000f0000 00200000 07000300 00000000 00000000
<64 bytes per line>
--可以通過如下方法查看在bbed:
BBED> set file 7 block 0
??????? FILE#?????????? 7
??????? BLOCK#????????? 0
BBED> dump
File: /mnt/ramdisk/book/tea01.dbf (7)
Block: 0??????????????????????????????????????????????????? Offsets:??? 0 to?? 63?????????????????????????????????????????????? Dba:0x01c00000
------------------------------------------------------------------------------------------------------------------------------------------------
00a20000 0000c0ff 00000000 00000000 66f50000 00200000 000f0000 7d7c7b7a a0810000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
??????????????????????????????????????????????????????????????? ~~~~~~~~
<64 bytes per line>
--//使用查看二進制的工具可以發現:
$ xxd -c 16 -l 128 tea01.dbf
0000000: 00a2 0000 0000 c0ff 0000 0000 0000 0000? ......?........
0000010: 66f5 0000 0020 0000 000f 0000 7d7c 7b7a? f?.. ......}|{z
?????????????????????????????????????? ~~~~~~~~~
0000020: a081 0000 0000 0000 0000 0000 0000 0000? ................
0000030: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000040: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000050: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000060: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000070: 0000 0000 0000 0000 0000 0000 0000 0000? ................
}
--你可以看到1個特征串7d7c7b7a。
--如果你建立一個數據文件,實際上從os看文件大小是30M+8k.
CREATE TABLESPACE SUGAR DATAFILE
? '/mnt/ramdisk/book/sugar01.dbf' SIZE 30M AUTOEXTEND ON NEXT 16M MAXSIZE UNLIMITED
NOLOGGING
ONLINE
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;
$ ls -l sugar01.dbf
-rw-r----- 1 oracle oinstall 31465472 2016-10-31 08:49:39 sugar01.dbf
--30*1024*1024+8192=31465472 .
--如果想了解更多細節,可以參考http://www.killdb.com/2011/09/05/%e4%b8%8d%e5%ae%8c%e5%85%a8%e8%af%a6%e8%a7%a3os-block-header.html
--//簡單介紹這些,看看rman是否備份這個塊。注意不要在生產系統做這樣的測試:
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
RMAN> delete backupset ;
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=68 device type=DISK
specification does not match any backup in the repository
--在一些空地方插入一些垃圾數據,在偏移0x100=256位置替換A1B2C3D4E5。
$ bvi -s 8192 -b 0 /mnt/ramdisk/book/sugar01.dbf
$ xxd -c 16 -l 320 sugar01.dbf
0000000: 00a2 0000 0000 c0ff 0000 0000 0000 0000? ......?........
0000010: 66f5 0000 0020 0000 000f 0000 7d7c 7b7a? f?.. ......}|{z
0000020: a081 0000 0000 0000 0000 0000 0000 0000? ................
0000030: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000040: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000050: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000060: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000070: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000080: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000090: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000a0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000b0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000c0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000d0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000e0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000f0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000100: 4131 4232 4333 4434 4535 0000 0000 0000? A1B2C3D4E5......
0000110: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000120: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000130: 0000 0000 0000 0000 0000 0000 0000 0000? ................
}
--//注意:千萬不要在生產系統做這樣的測試,另外這樣并不會影響數據庫的啟動。關閉數據庫,重啟看看。
2.備份數據文件:
SYS@book> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@book> startup
ORACLE instance started.
Total System Global Area? 634732544 bytes
Fixed Size????????????????? 2255792 bytes
Variable Size???????????? 197133392 bytes
Database Buffers????????? 427819008 bytes
Redo Buffers??????????????? 7524352 bytes
Database mounted.
Database opened.
--你可以檢查A1B2C3D4E5字符串 依舊存在。
$ strings -t d sugar01.dbf? | grep 'A1B2C3'
??? 256 A1B2C3D4E5
$ strings -t x sugar01.dbf? | grep 'A1B2C3'
??? 100 A1B2C3D4E5
--可以發現在偏移量256位置出現A1B2C3D4E5.
RMAN> backup datafile 6 format '/u01/backup/d6_A_%U' ;
Starting backup at 2016-10-31 09:19:56
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=46 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-10-31 09:19:57
channel ORA_DISK_1: finished piece 1 at 2016-10-31 09:19:58
piece handle=/u01/backup/d6_A_0hrjnqlt_1_1 tag=TAG20161031T091957 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-10-31 09:19:58
--//檢查備份可以發現,沒有出現A1B2C3D4E5字符串。
$ strings -t d /u01/backup/d6_A_0hrjnqlt_1_1 | grep A1B2
$ strings -t d /u01/backup/d6_A_0hrjnqlt_1_1 | grep "}|{z"
???? 28 }|{z
$ xxd -c 16 -l 320 /u01/backup/d6_A_0hrjnqlt_1_1
0000000: 00a2 0000 0000 c0ff 0000 0000 0000 0000? ......?........
0000010: a2fa 0000 0020 0000 c400 0000 7d7c 7b7a? .?.. ..?..}|{z
0000020: a081 0000 0000 0000 0000 0000 0000 0000? ................
0000030: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000040: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000050: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000060: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000070: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000080: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000090: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000a0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000b0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000c0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000d0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000e0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000f0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000100: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000110: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000120: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000130: 0000 0000 0000 0000 0000 0000 0000 0000? ................
}
--//你可以發現rman的備份集合也有OS塊。按照鏈接http://www.killdb.com/2011/09/05/%e4%b8%8d%e5%ae%8c%e5%85%a8%e8%af%a6%e8%a7%a3os-block-header.html,
--//offset 0x18-0x19 對應的datafile的大小,實際上是block個數.
$ xxd -c 16 -l 320 sugar01.dbf
0000000: 00a2 0000 0000 c0ff 0000 0000 0000 0000? ......?........
0000010: 66f5 0000 0020 0000 000f 0000 7d7c 7b7a? f?.. ......}|{z
0000020: a081 0000 0000 0000 0000 0000 0000 0000? ................
--f00 = 3840, 數據文件大小30M,30*1024*1024/8192=3840.正好對上。
$ xxd -c 16 -l 320 /u01/backup/d6_A_0hrjnqlt_1_1
0000000: 00a2 0000 0000 c0ff 0000 0000 0000 0000? ......?........
0000010: a2fa 0000 0020 0000 c400 0000 7d7c 7b7a? .?.. ..?..}|{z
0000020: a081 0000 0000 0000 0000 0000 0000 0000? ................
}
$ ls -l /u01/backup/d6_A_0hrjnqlt_1_1
-rw-r----- 1 oracle oinstall 1613824 2016-10-31 09:19:57 /u01/backup/d6_A_0hrjnqlt_1_1
--c4 = 196, 備份文件大小1613824, 1613824/8192=197,這樣扣除1個OS塊,大小也是196.也能對上,就是講備份集也存在1個OS塊。
3.做一個恢復看看。
SYS@book> alter tablespace sugar offline ;
Tablespace altered.
$ mv sugar01.dbf sugar01.dbf_20161031
RMAN> restore tablespace sugar ;
Starting restore at 2016-10-31 09:37:10
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_0hrjnqlt_1_1
channel ORA_DISK_1: piece handle=/u01/backup/d6_A_0hrjnqlt_1_1 tag=TAG20161031T091957
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2016-10-31 09:37:12
$ xxd -c 16 -l 320 sugar01.dbf
0000000: 00a2 0000 0000 c0ff 0000 0000 0000 0000? ......?........
0000010: 66f5 0000 0020 0000 000f 0000 7d7c 7b7a? f?.. ......}|{z
0000020: a081 0000 0000 0000 0000 0000 0000 0000? ................
0000030: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000040: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000050: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000060: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000070: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000080: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000090: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000a0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000b0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000c0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000d0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000e0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
00000f0: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000100: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000110: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000120: 0000 0000 0000 0000 0000 0000 0000 0000? ................
0000130: 0000 0000 0000 0000 0000 0000 0000 0000? ................
--你可以發現恢復數據文件頭沒有A1B2字符串。}
RMAN> recover tablespace sugar ;
Starting recover at 2016-10-31 09:37:37
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 2016-10-31 09:37:37
SYS@book> alter tablespace sugar online ;
Tablespace altered.
--從以上測試可以證明rman并沒有備份數據文件的OS塊。
4.做一個strace看看:
$ strace -f -o /tmp/bb.txt rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Oct 31 09:41:54 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates.? All rights reserved.
connected to target database: BOOK (DBID=1337401710)
RMAN> backup datafile 6 format '/u01/backup/d6_B_%U' ;
Starting backup at 2016-10-31 09:42:23
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=46 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-10-31 09:42:24
channel ORA_DISK_1: finished piece 1 at 2016-10-31 09:42:25
piece handle=/u01/backup/d6_B_0irjns00_1_1 tag=TAG20161031T094224 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-10-31 09:42:25
$ grep pread /tmp/bb.txt | grep ", 0"
3053? pread(259, "\0\242\0\0\0\0\300\377\0\0\0\0\0\0\0\0f\365\0\0\0 \0\0\0\17\0\0}|{z"..., 8192, 0) = 8192
3053? pread(259, "\0\242\0\0\0\0\300\377\0\0\0\0\0\0\0\0f\365\0\0\0 \0\0\0\17\0\0}|{z"..., 8192, 0) = 8192
3053? pread(260, "\0\242\0\0\0\0\300\377\0\0\0\0\0\0\0\0f\365\0\0\0 \0\0\0\17\0\0}|{z"..., 8192, 0) = 8192
3053? pread(260, "\0\242\0\0\0\0\300\377\0\0\0\0\0\0\0\0f\365\0\0\0 \0\0\0\17\0\0}|{z"..., 8192, 0) = 8192
3053? pread(261, "\0\242\0\0\0\0\300\377\0\0\0\0\0\0\0\0f\365\0\0\0 \0\0\0\17\0\0}|{z"..., 8192, 0) = 8192
3053? pread(261, "\0\242\0\0\0\0\300\377\0\0\0\0\0\0\0\0f\365\0\0\0 \0\0\0\17\0\0}|{z"..., 8192, 0) = 8192
$ grep pwrite /tmp/bb.txt | grep ", 0"
$ grep pwrite /tmp/bb.txt | grep ", 8192"
3053? pwrite(258, "\v\242\0\0\1\0\200\1\0\0\0\0\0\0\1\4\276\250\0\0\0\0\0\0\0\4 \vn!\267O"..., 8192, 8192) = 8192
3053? pwrite(259, "\23\242\0\0\1\0\0\0K\364#\0\0\0\1\4\257I\0\0\0\4 \v\0\4 \vn!\267O"..., 1040384, 8192) = 1040384
$ grep pwrite /tmp/bb.txt | grep "= 8192"
3053? pwrite(258, "\v\242\0\0\1\0\200\1\0\0\0\0\0\0\1\4\276\250\0\0\0\0\0\0\0\4 \vn!\267O"..., 8192, 8192) = 8192
--從以上跟蹤看,有讀第0塊的操作,沒有出現一次寫的操作。也就是rman不備份這數據文件OS塊。
總結
以上是生活随笔為你收集整理的[20161031]rman备份与数据文件OS块.txt的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 高度固定,行数不固定的文字垂直居中问题
- 下一篇: java时间间隔的判断