[20171121]rman backup as copy 2.txt--//昨天測試backup as copy ,備份時備份文件的文件頭什麼時候更新.是最後完成後還是順序寫入備份文件.--//我測試的數據文件使用數據文件2(表空間sysaux),也許是文件不夠大,應該減慢備份速度來測試看看.1. ...
[20171121]rman backup as copy 2.txt
--//昨天測試backup as copy ,備份時備份文件的文件頭什麼時候更新.是最後完成後還是順序寫入備份文件.
--//我測試的數據文件使用數據文件2(表空間sysaux),也許是文件不夠大,應該減慢備份速度來測試看看.
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
$ cat dump_head.sh
#! /bin/bash
for i in $(seq 1000)
do
# echo $i
xxd -c32 -g 2 -s 8192 -l 32 $1 >> /tmp/dump_head.txt 2>/dev/null
sleep 1
done
2.測試:
--//首先啟動dump_head.sh腳本,session 1:
$ . dump_head.sh /home/oracle/backup/tea01.dbf &
--//在sesion 2,在rman下執行備份:
RMAN> CONFIGURE CHANNEL 1 DEVICE TYPE DISK RATE 1M;
using target database control file instead of recovery catalog
new RMAN configuration parameters:
CONFIGURE CHANNEL 1 DEVICE TYPE DISK RATE 1 M;
new RMAN configuration parameters are successfully stored
RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET;
old RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 3 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters are successfully stored
--//設置DISK RATE 1M,這樣可以減慢備份的速度,便於觀察.並且僅僅打開1個並行.
RMAN> backup as copy datafile 6 format '/home/oracle/backup/%b';
Starting backup at 2017-11-21 09:43:09
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/mnt/ramdisk/book/tea01.dbf
output file name=/home/oracle/backup/tea01.dbf tag=TAG20171121T094309 RECID=17 STAMP=960630229
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
channel ORA_DISK_1: throttle time: 0:00:40
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Finished backup at 2017-11-21 09:43:54
Starting Control File and SPFILE Autobackup at 2017-11-21 09:43:54
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/autobackup/2017_11_21/o1_mf_s_960630234_f1716tsv_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2017-11-21 09:43:55
--//註意看下劃線內容,throttle time: 0:00:40.
throttle
英 [?θr?tl] 美 [?θrɑ:tl]
n.
節流閥;喉嚨,氣管;[機]風門
vt.& vi.
扼殺,壓制;勒死,使窒息;使節流;(用節汽閥等)調節
vi.
節流,減速;窒息
-----------------------------------------------
--//而我的備份文件就是40M+8k的數據文件.
$ ls -lh /home/oracle/backup/tea01.dbf
-rw-r----- 1 oracle oinstall 41M 2017-11-21 09:43:49 /home/oracle/backup/tea01.dbf
$ ls -l /home/oracle/backup/tea01.dbf
-rw-r----- 1 oracle oinstall 41951232 2017-11-21 09:43:49 /home/oracle/backup/tea01.dbf
--//session 1:
$ fg
. dump_head.sh /home/oracle/backup/tea01.dbf
^C^
3.檢查/tmp/dump_head.txt輸出記錄:
$ uniq -c /tmp/dump_head.txt
1 0002000: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 ................................
40 0002000: 00a2 0000 0100 8001 0000 0000 0000 0105 81a6 0000 0000 0000 0000 0000 0000 0000 ................................
14 0002000: 0ba2 0000 0100 8001 0000 0000 0000 0104 61c1 0000 0000 0000 0004 200b 6e21 b74f ................a?....... .n!.O
--//^_^,再次驗證我的判斷.
--//從以上輸出可以發現使用backup as copy備份,一定先建立一個空文件,輸出一堆0000(需要大約1秒),大小與數據文件一致,這樣可以先檢測是否磁碟滿足備份需求.
--//然後寫入開頭00a2,出現40次(我腳本執行sleep 1,不考慮其它消耗正好是40秒).
--//到最後才更新as copy方式的備份映像的文件頭.
--//oracle的設計確實考慮許多因素,與備份文件集模式一樣最後寫入文件頭信息,這樣保證使用備份image是正確的,
--//設想一下,如果順序寫入備份image文件,如果備份過程中發生中斷,而那這個image備份文件來恢復,會發生什麼情況呢?
--//而現在這樣設計意味著發生中斷,備份image的文件頭是"壞"的,意味著不能用於恢復.
--//還有一個疑問,寫入備份image的文件頭信息是 開始備份前讀取的文件頭信息,然後最後完成備份在讀取文件頭信息呢?
--//我只要在備份過程發出alter system checkpoint就知道.
--// 重覆測試看看.
RMAN> delete datafilecopy all ;
SYS@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE# , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name FROM v$datafile_header;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME CREATION_CHANGE# RESETLOGS_CHANGE# STATUS CHECKPOINT_COUNT FUZ NAME TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- -------------------------------- ---------------
1 13279819419 2017-11-21 10:22:57 7 925702 ONLINE 1246 YES /mnt/ramdisk/book/system01.dbf SYSTEM
2 13279819419 2017-11-21 10:22:57 1834 925702 ONLINE 1247 YES /mnt/ramdisk/book/sysaux01.dbf SYSAUX
3 13279819419 2017-11-21 10:22:57 923328 925702 ONLINE 1156 YES /mnt/ramdisk/book/undotbs01.dbf UNDOTBS1
4 13279819419 2017-11-21 10:22:57 16143 925702 ONLINE 1243 YES /mnt/ramdisk/book/users01.dbf USERS
5 13279819419 2017-11-21 10:22:57 952916 925702 ONLINE 1152 YES /mnt/ramdisk/book/example01.dbf EXAMPLE
6 13279819419 2017-11-21 10:22:57 13276257767 925702 ONLINE 634 YES /mnt/ramdisk/book/tea01.dbf TEA
6 rows selected.
--//session 1:
RMAN> backup as copy datafile 6 format '/home/oracle/backup/%b';
Starting backup at 2017-11-21 10:26:10
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/mnt/ramdisk/book/tea01.dbf
....等
--//session 2:
SYS@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE# , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name FROM v$datafile_header;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME CREATION_CHANGE# RESETLOGS_CHANGE# STATUS CHECKPOINT_COUNT FUZ NAME TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- -------------------------------- ----------------
1 13279819419 2017-11-21 10:22:57 7 925702 ONLINE 1246 YES /mnt/ramdisk/book/system01.dbf SYSTEM
2 13279819419 2017-11-21 10:22:57 1834 925702 ONLINE 1247 YES /mnt/ramdisk/book/sysaux01.dbf SYSAUX
3 13279819419 2017-11-21 10:22:57 923328 925702 ONLINE 1156 YES /mnt/ramdisk/book/undotbs01.dbf UNDOTBS1
4 13279819419 2017-11-21 10:22:57 16143 925702 ONLINE 1243 YES /mnt/ramdisk/book/users01.dbf USERS
5 13279819419 2017-11-21 10:22:57 952916 925702 ONLINE 1152 YES /mnt/ramdisk/book/example01.dbf EXAMPLE
6 13279819660 2017-11-21 10:26:10 13276257767 925702 ONLINE 635 YES /mnt/ramdisk/book/tea01.dbf TEA
--//註意看數據文件6的CHECKPOINT_CHANGE#=13279819660(備份開始前CHECKPOINT_CHANGE#=13279819419),說明在備份開始時要做文件檢查點, 更新文件頭scn.
SYS@book> alter system checkpoint ;
System altered.
SYS@book> alter system checkpoint ;
System altered.
SYS@book> alter system checkpoint ;
System altered.
--//在備份的過程中我發3次alter system checkpoint ;
--//session 1:
RMAN> backup as copy datafile 6 format '/home/oracle/backup/%b';
Starting backup at 2017-11-21 10:26:10
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/mnt/ramdisk/book/tea01.dbf
output file name=/home/oracle/backup/tea01.dbf tag=TAG20171121T102610 RECID=19 STAMP=960632810
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
channel ORA_DISK_1: throttle time: 0:00:39
Finished backup at 2017-11-21 10:26:55
Starting Control File and SPFILE Autobackup at 2017-11-21 10:26:55
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/autobackup/2017_11_21/o1_mf_s_960632816_f173qj22_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2017-11-21 10:26:57
--//session 2:
SYS@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE# , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name FROM v$datafile_header;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME CREATION_CHANGE# RESETLOGS_CHANGE# STATUS CHECKPOINT_COUNT FUZ NAME TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- -------------------------------------------------- ------------------------------
1 13279819678 2017-11-21 10:26:26 7 925702 ONLINE 1249 YES /mnt/ramdisk/book/system01.dbf SYSTEM
2 13279819678 2017-11-21 10:26:26 1834 925702 ONLINE 1250 YES /mnt/ramdisk/book/sysaux01.dbf SYSAUX
3 13279819678 2017-11-21 10:26:26 923328 925702 ONLINE 1159 YES /mnt/ramdisk/book/undotbs01.dbf UNDOTBS1
4 13279819678 2017-11-21 10:26:26 16143 925702 ONLINE 1246 YES /mnt/ramdisk/book/users01.dbf USERS
5 13279819678 2017-11-21 10:26:26 952916 925702 ONLINE 1155 YES /mnt/ramdisk/book/example01.dbf EXAMPLE
6 13279819678 2017-11-21 10:26:26 13276257767 925702 ONLINE 638 YES /mnt/ramdisk/book/tea01.dbf TEA
6 rows selected.
--//看看備份寫入的scn是13279819678還是13279819660呢?
BBED> p /d filename '/home/oracle/backup/tea01.dbf' block 1 kcvfh.kcvfhckp.kcvcpscn
struct kcvcpscn, 8 bytes @484
ub4 kscnbas @484 394917772
ub2 kscnwrp @488 3
BBED> p /d filename '/mnt/ramdisk/book/tea01.dbf' block 1 kcvfh.kcvfhckp.kcvcpscn
struct kcvcpscn, 8 bytes @484
ub4 kscnbas @484 394917790
ub2 kscnwrp @488 3
SYS@book> select power(2,32)*3+394917772 from dual ;
POWER(2,32)*3+394917772
-----------------------
13279819660
SYS@book> select power(2,32)*3+394917790 from dual ;
POWER(2,32)*3+394917790
-----------------------
13279819678
--//從CHECKPOINT_CHANGE#的scn號可以看出是備份文件的文件頭信息是備份時讀取的文件頭信息,而不是經過多次alter system checkpint後的信息.
--//也就是備份時已經讀取這部分信息到記憶體(下麵的補充測試也說明問題),最後在寫入備份image的文件頭的.
--//我再次修改我的測試腳本,-s 8676對應的CHECKPOINT_CHANGE#號信息.再次重覆測試,僅僅貼出結果.
$ cat dump_head.sh
#! /bin/bash
for i in $(seq 1000)
do
# echo $i
xxd -c32 -g 2 -s 8192 -l 32 $1 >> /tmp/dump_head.txt 2>/dev/null
xxd -c32 -g 2 -s 8676 -l 32 $1 >> /tmp/dump_head.txt 2>/dev/null
sleep 1
done
$ grep "^0002000:" /tmp/dump_head.txt | uniq -c
40 0002000: 00a2 0000 0100 8001 0000 0000 0000 0105 81a6 0000 0000 0000 0000 0000 0000 0000 ................................
39 0002000: 0ba2 0000 0100 8001 0000 0000 0000 0104 1292 0000 0000 0000 0004 200b 6e21 b74f .......................... .n!.O
$ grep "^00021e4:" /tmp/dump_head.txt | uniq -c
40 00021e4: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 ................................
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77 00021e4: 73fc 8917 0300 0000 f91b 4239 0100 0000 c003 0000 875a 0100 1000 313b 0200 0000 s?.....?B9....?...Z....1;....
--//可以看出前面40秒,根本沒有寫入文件頭scn信息.最後才寫入的.
--//收尾還原:
RMAN> configure channel 1 device type disk clear;
old RMAN configuration parameters:
CONFIGURE CHANNEL 1 DEVICE TYPE DISK RATE 1 M;
old RMAN configuration parameters are successfully deleted
released channel: ORA_DISK_1
RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 3 BACKUP TYPE TO BACKUPSET;
old RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 3 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters are successfully stored