RMAN備份與恢復(新舊控制檔案及歸檔日誌)測試(敘)

gaopengtttt發表於2009-06-09

(我的學習過程)

繼上一次做的試驗,過後我又思考了下,當然其中的4點結論沒有問題,但是卻忽略了一點,上次的試驗證明了在不使用恢復目錄的情況下,做恢復時使用的歸檔重做日誌檔案只能是在控制檔案中有記錄的,
backup format "${BACKUP_DB_TARGET}/db_${ORACLE_SID}_${DATE_TAG}_%s_%p_%t"
database plus archivelog delete all input
format "${BACKUP_DB_TARGET}/arch_${ORACLE_SID}_${DATE_TAG}_%s_%p_%t";
就這樣的一個語句,雖然不錯,但是有一個缺點,他的備份順序是
1、切換日誌
2、備份歸檔
3、備份資料檔案
4、備份SPFILE,CONTROLFILE
5、再切換
6、在備份切換出來的歸檔日誌檔案

好像有一個明顯的缺點,也就是最後歸檔的備份資訊是不會記錄在控制檔案中的,可以考慮一下這樣有何不拓的地方,如果我只取一次備份週期的全備包括歸檔日誌檔案,是不能夠進行恢復,他會報找不到日誌組**,而這個日誌組相當重要,
沒有他資料檔案就不能同步(應為進行熱備的時候各個資料檔案的SCN是不一致的,恢復的時候需要滾動歸檔日誌檔案來進行同步),所以如果我們要恢復我們只能取的是最新的控制檔案,而資料檔案只能取上次備份的資料檔案,這樣才能進行不完全恢復。我覺得最好的調整是把順序調整為:
1、切換日誌
2、備份歸檔
3、備份資料檔案
4、再切換
5、在備份切換出來的歸檔日誌檔案
6、備份SPFILE,CONTROLFILE
這樣就非常合理了,下面用試驗進行證明(同樣紅色標記為試驗過程,粉色標記為重點)


使用語句
backup format "/oradatatest/rman/datafile/db_%s_%p_%T"
database plus archivelog delete all input
format "/oradatatest/rman/archive/arch_%s_%p_%T";
進行兩次備份中間同樣用SWITCH LOGFILE模擬日誌切換。存檔
貼出備份全過程:
RMAN> backup format "/oradatatest/rman/datafile/db_%s_%p_%T"
2> database plus archivelog delete all input
3> format "/oradatatest/rman/archive/arch_%s_%p_%T";


Starting backup at 02-JUN-09
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=12 recid=30 stamp=688467805
input archive log thread=1 sequence=13 recid=31 stamp=688467967
channel ORA_DISK_1: starting piece 1 at 02-JUN-09
channel ORA_DISK_1: finished piece 1 at 02-JUN-09
piece handle=/oradatatest/rman/archive/arch_5_1_20090602 tag=TAG20090602T090607 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/logmin/archive/1_12_677591436.dbf recid=30 stamp=688467805
archive log filename=/logmin/archive/1_13_677591436.dbf recid=31 stamp=688467967
Finished backup at 02-JUN-09

Starting backup at 02-JUN-09
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/oradata/pp/pp/system01.dbf
input datafile fno=00004 name=/oradata/pp/pp/users01.dbf
input datafile fno=00003 name=/oradata/pp/pp/sysaux01.dbf
input datafile fno=00002 name=/oradata/pp/pp/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 02-JUN-09
channel ORA_DISK_1: finished piece 1 at 02-JUN-09
piece handle=/oradatatest/rman/datafile/db_6_1_20090602 tag=TAG20090602T090612 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:35
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 02-JUN-09
channel ORA_DISK_1: finished piece 1 at 02-JUN-09
piece handle=/oradatatest/rman/datafile/db_7_1_20090602 tag=TAG20090602T090612 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 02-JUN-09

Starting backup at 02-JUN-09
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=14 recid=32 stamp=688468070
channel ORA_DISK_1: starting piece 1 at 02-JUN-09
channel ORA_DISK_1: finished piece 1 at 02-JUN-09
piece handle=/oradatatest/rman/archive/arch_8_1_20090602 tag=TAG20090602T090750 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/logmin/archive/1_14_677591436.dbf recid=32 stamp=688468070
Finished backup at 02-JUN-09

這裡做了切換
RMAN> backup format "/oradatatest/rman/datafile/db_%s_%p_%T"
2> database plus archivelog delete all input
3> format "/oradatatest/rman/archive/arch_%s_%p_%T";


Starting backup at 02-JUN-09
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=15 recid=33 stamp=688468104
input archive log thread=1 sequence=16 recid=34 stamp=688468112
input archive log thread=1 sequence=17 recid=35 stamp=688468115
input archive log thread=1 sequence=18 recid=36 stamp=688468230
channel ORA_DISK_1: starting piece 1 at 02-JUN-09
channel ORA_DISK_1: finished piece 1 at 02-JUN-09
piece handle=/oradatatest/rman/archive/arch_9_1_20090602 tag=TAG20090602T091030 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/logmin/archive/1_15_677591436.dbf recid=33 stamp=688468104
archive log filename=/logmin/archive/1_16_677591436.dbf recid=34 stamp=688468112
archive log filename=/logmin/archive/1_17_677591436.dbf recid=35 stamp=688468115
archive log filename=/logmin/archive/1_18_677591436.dbf recid=36 stamp=688468230
Finished backup at 02-JUN-09

Starting backup at 02-JUN-09
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/oradata/pp/pp/system01.dbf
input datafile fno=00004 name=/oradata/pp/pp/users01.dbf
input datafile fno=00003 name=/oradata/pp/pp/sysaux01.dbf
input datafile fno=00002 name=/oradata/pp/pp/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 02-JUN-09
channel ORA_DISK_1: finished piece 1 at 02-JUN-09
piece handle=/oradatatest/rman/datafile/db_10_1_20090602 tag=TAG20090602T091032 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:26
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 02-JUN-09
channel ORA_DISK_1: finished piece 1 at 02-JUN-09
piece handle=/oradatatest/rman/datafile/db_11_1_20090602 tag=TAG20090602T091032 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 02-JUN-09

Starting backup at 02-JUN-09
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=19 recid=37 stamp=688468321
channel ORA_DISK_1: starting piece 1 at 02-JUN-09
channel ORA_DISK_1: finished piece 1 at 02-JUN-09
piece handle=/oradatatest/rman/archive/arch_12_1_20090602 tag=TAG20090602T091201 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/logmin/archive/1_19_677591436.dbf recid=37 stamp=688468321
Finished backup at 02-JUN-09

RMAN>
重順序很容易看出剛才所說的,然後進行恢復測試,先取第一個備份的控制檔案和資料檔案,肯定不能進行不完全恢復我猜測。
RMAN> restore controlfile from '/oradatatest/rman/datafile/db_7_1_20090602';

Starting restore at 02-JUN-09
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:04
output filename=/oradata/pp/pp/control01.ctl
output filename=/oradata/pp/pp/control02.ctl
output filename=/oradata/pp/pp/control03.ctl
Finished restore at 02-JUN-09
RMAN> sql'alter database mount';

sql statement: alter database mount
released channel: ORA_DISK_1

RMAN> list backup;


List of Backup Sets
===================

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
3       36.89M     DISK        00:00:03     02-JUN-09     
        BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: TAG20090602T090607
        Piece Name: /oradatatest/rman/archive/arch_5_1_20090602

  List of Archived Logs in backup set 3
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    12      503557     01-JUN-09 532840     02-JUN-09
  1    13      532840     02-JUN-09 532945     02-JUN-09

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4       Full    932.13M    DISK        00:01:30     02-JUN-09     
        BP Key: 4   Status: AVAILABLE  Compressed: NO  Tag: TAG20090602T090612
        Piece Name: /oradatatest/rman/datafile/db_6_1_20090602
  List of Datafiles in backup set 4
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 532950     02-JUN-09 /oradata/pp/pp/system01.dbf
  2       Full 532950     02-JUN-09 /oradata/pp/pp/undotbs01.dbf
  3       Full 532950     02-JUN-09 /oradata/pp/pp/sysaux01.dbf
  4       Full 532950     02-JUN-09 /oradata/pp/pp/users01.dbf
可以看到14的那個歸檔檔案根本不在這裡,
RMAN> recover database until sequence 14;

Starting recover at 02-JUN-09
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 06/02/2009 09:20:37
RMAN-06556: datafile 1 must be restored from backup older than scn 532840
這裡可以看到其實我要RESTORE的資料檔案已經在13之後了,比他更新,所以我們要使用14來進行恢復
RMAN> recover database until sequence 15;

Starting recover at 02-JUN-09
using channel ORA_DISK_1

starting media recovery

unable to find archive log
archive log thread=1 sequence=14
Oracle Error:
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/oradata/pp/pp/system01.dbf'

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 06/02/2009 09:21:58
RMAN-06054: media recovery requesting unknown log: thread 1 seq 14 lowscn 532992
可以看出我的猜測是正確的,不能使用14日誌,因為這個備份集沒有記錄在控制檔案中,
然後使用第2次的控制檔案第一次的資料檔案進行恢復,也只有這樣了,

貼出過程:
[oracle@localhost datafile]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Tue Jun 2 09:24:00 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

connected to target database: pp (not mounted)

RMAN> restore controlfile from '/oradatatest/rman/datafile/db_11_1_20090602';

Starting restore at 02-JUN-09
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:04
output filename=/oradata/pp/pp/control01.ctl
output filename=/oradata/pp/pp/control02.ctl
output filename=/oradata/pp/pp/control03.ctl
Finished restore at 02-JUN-09

RMAN> sql'alter database mount';

sql statement: alter database mount
released channel: ORA_DISK_1

RMAN> list backup;


List of Backup Sets
===================

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
3       36.89M     DISK        00:00:03     02-JUN-09     
        BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: TAG20090602T090607
        Piece Name: /oradatatest/rman/archive/arch_5_1_20090602

  List of Archived Logs in backup set 3
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    12      503557     01-JUN-09 532840     02-JUN-09
  1    13      532840     02-JUN-09 532945     02-JUN-09

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4       Full    932.13M    DISK        00:01:30     02-JUN-09     
        BP Key: 4   Status: AVAILABLE  Compressed: NO  Tag: TAG20090602T090612
        Piece Name: /oradatatest/rman/datafile/db_6_1_20090602
  List of Datafiles in backup set 4
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 532950     02-JUN-09 /oradata/pp/pp/system01.dbf
  2       Full 532950     02-JUN-09 /oradata/pp/pp/undotbs01.dbf
  3       Full 532950     02-JUN-09 /oradata/pp/pp/sysaux01.dbf
  4       Full 532950     02-JUN-09 /oradata/pp/pp/users01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
5       Full    6.80M      DISK        00:00:02     02-JUN-09     
        BP Key: 5   Status: AVAILABLE  Compressed: NO  Tag: TAG20090602T090612
        Piece Name: /oradatatest/rman/datafile/db_7_1_20090602
  Control File Included: Ckp SCN: 532992       Ckp time: 02-JUN-09
  SPFILE Included: Modification time: 02-JUN-09

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
6       25.50K     DISK        00:00:01     02-JUN-09     
        BP Key: 6   Status: AVAILABLE  Compressed: NO  Tag: TAG20090602T090750
        Piece Name: /oradatatest/rman/archive/arch_8_1_20090602

  List of Archived Logs in backup set 6
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    14      532945     02-JUN-09 532996     02-JUN-09

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
7       12.00K     DISK        00:00:01     02-JUN-09     
        BP Key: 7   Status: AVAILABLE  Compressed: NO  Tag: TAG20090602T091030
        Piece Name: /oradatatest/rman/archive/arch_9_1_20090602

  List of Archived Logs in backup set 7
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    15      532996     02-JUN-09 533012     02-JUN-09
  1    16      533012     02-JUN-09 533016     02-JUN-09
  1    17      533016     02-JUN-09 533018     02-JUN-09
  1    18      533018     02-JUN-09 533072     02-JUN-09

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
8       Full    932.13M    DISK        00:01:19     02-JUN-09     
        BP Key: 8   Status: AVAILABLE  Compressed: NO  Tag: TAG20090602T091032
        Piece Name: /oradatatest/rman/datafile/db_10_1_20090602
  List of Datafiles in backup set 8
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 533076     02-JUN-09 /oradata/pp/pp/system01.dbf
  2       Full 533076     02-JUN-09 /oradata/pp/pp/undotbs01.dbf
  3       Full 533076     02-JUN-09 /oradata/pp/pp/sysaux01.dbf
  4       Full 533076     02-JUN-09 /oradata/pp/pp/users01.dbf
  可以看到這次的控制檔案包含了14日誌組,所以這個檔案可以恢復到日誌18,但是歸檔日誌組19是沒有的,這也是這個方法的弊端
  必須使用上一次備份的資料檔案來進行全恢復,但是起碼可以恢復。
  RMAN> restore database from tag=TAG20090602T090612;

Starting restore at 02-JUN-09
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /oradata/pp/pp/system01.dbf
restoring datafile 00002 to /oradata/pp/pp/undotbs01.dbf
restoring datafile 00003 to /oradata/pp/pp/sysaux01.dbf
restoring datafile 00004 to /oradata/pp/pp/users01.dbf
channel ORA_DISK_1: reading from backup piece /oradatatest/rman/datafile/db_6_1_20090602
channel ORA_DISK_1: restored backup piece 1
piece handle=/oradatatest/rman/datafile/db_6_1_20090602 tag=TAG20090602T090612
channel ORA_DISK_1: restore complete, elapsed time: 00:01:25
Finished restore at 02-JUN-09

RMAN> recover database until sequence 19;

Starting recover at 02-JUN-09
using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 18 is already on disk as file /oradata/pp/pp/redo02.log
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=14
channel ORA_DISK_1: reading from backup piece /oradatatest/rman/archive/arch_8_1_20090602
channel ORA_DISK_1: restored backup piece 1
piece handle=/oradatatest/rman/archive/arch_8_1_20090602 tag=TAG20090602T090750
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archive log filename=/logmin/archive/1_14_677591436.dbf thread=1 sequence=14
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=15
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=16
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=17
channel ORA_DISK_1: reading from backup piece /oradatatest/rman/archive/arch_9_1_20090602
channel ORA_DISK_1: restored backup piece 1
piece handle=/oradatatest/rman/archive/arch_9_1_20090602 tag=TAG20090602T091030
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/logmin/archive/1_15_677591436.dbf thread=1 sequence=15
archive log filename=/logmin/archive/1_16_677591436.dbf thread=1 sequence=16
archive log filename=/logmin/archive/1_17_677591436.dbf thread=1 sequence=17
archive log filename=/oradata/pp/pp/redo02.log thread=1 sequence=18
media recovery complete, elapsed time: 00:00:03
Finished recover at 02-JUN-09
RMAN> sql'alter database open resetlogs';

sql statement: alter database open resetlogs


對嗎?最後的試驗結果確實如此。所以改進的辦法就是如下順序進行備份
1、切換日誌
2、備份歸檔
3、備份資料檔案(其實這裡全備會自動備份控制檔案
4、再切換
5、在備份切換出來的歸檔日誌檔案
6、備份SPFILE,CONTROLFILE(手動的進行
這樣任何一個備份週期的備份集都能夠恢復,但是每一次的全備資料檔案都會自動備份CONTROLFILE,所以我們所能做的是額外的在手工備份一次控制檔案,當然沿用以前的辦法只要取出兩個週期的全備一樣的可以進行不完全恢復,這裡還涉及到在儲存備份資訊的冗餘上,最好使用天數而不使用份數,不然ORACLE會覺得你的控制檔案份數太多,會刪除我們手動進行的備份。
另外說下作為DBA要多多考慮下備份,畢竟備份是最重要的,效能調優等其實都相對而言次要一些,如果有一天你的資料庫掛掉了,你對老闆說我先前考慮的備份方案有誤,現在不能恢復了,我想後果是很嚴重的。所以儘量把事情往壞處想,做好準備,在突發事件面前才不會發呆,呵呵,亂說了一下^_^。

我考慮不對的地方希望看過的朋友可以告訴我謝謝。。。我也是新手上路

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7728585/viewspace-605622/,如需轉載,請註明出處,否則將追究法律責任。

相關文章