從RMAN備份集中還原Archive log


從RMAN備份集中還原Archive log

1、Rman的restore與recover是不同的概念:
   restore:指從已產生的備份集中,找出一個或多個物件(檔案),還原檔案到指定的位置。
   recover:通常透過重做交易(從redo log及archive log)來恢復資料庫的資料。
 
 
2、找出要restore 的 archive log
   RMAN> list backup of archivelog all;
 
   List of Backup Sets
   ===================
 
   BS Key  Size       Device Type Elapsed Time Completion Time
   ------- ---------- ----------- ------------ ---------------
   1662    58G        SBT_TAPE    00:45:28     12-DEC-12    
        BP Key: 1658   Status: AVAILABLE   Tag: TAG20121212T223215
        Piece Name: 7420_DB_Backup_incr_0.dbf

  List of Archived Logs in backup set 1662
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    4816    14339859122 12-DEC-12 14340109617 12-DEC-12
  1    4817    14340109617 12-DEC-12 14340408790 12-DEC-12
  1    4818    14340408790 12-DEC-12 14340520580 12-DEC-12
  1    4819    14340520580 12-DEC-12 14340681895 12-DEC-12
  1    4820    14340681895 12-DEC-12 14340901575 12-DEC-12

 
3、假設要 restore 的是 seq=4816,腳本可以是:
  run {allocate channel 'ci' type 'sbt_tape';
       restore archivelog from sequence 4816 until sequence 4816;
       release channel 'ci';}

  假設要 restore 的是 seq=4816、4817、4818,腳本可以是:
  run {allocate channel 'ci' type 'sbt_tape';
       restore archivelog from sequence 4816 until sequence 4818;
       release channel 'ci';}

  因為我的備份集是在磁帶上,所以指定channel的type為'sbt_tape'
 
  RMAN> run {allocate channel 'ci' type 'sbt_tape';
             restore archivelog from sequence 4823 until sequence 4823;
             release channel 'ci';}

  allocated channel: ci
  channel ci: sid=245 devtype=SBT_TAPE
  channel ci: Data Protector A.05.50/330
 
  Starting restore at 13-DEC-12

  channel ci: starting archive log restore to default destination
  channel ci: restoring archive log
  archive log thread=1 sequence=4823
  [Normal] From: OB2BAR_Oracle8@hp7420 "PROD"  Time: 12/13/12 10:32:32
  Starting OB2BAR Restore: hp7420:7420_DB_Backup_incr_0.dbf "Oracle8"

  [Normal] From: OB2BAR_Oracle8@hp7420 "PROD"  Time: 12/13/12 10:56:23
  Completed OB2BAR Restore: hp7420:7420_DB_Backup_incr_0.dbf "Oracle8"

  channel ci: restored backup piece 1
  piece handle=7420_DB_Backup_incr_0.dbf tag=TAG20121212T223215 params=NULL
  channel ci: restore complete
  Finished restore at 13-DEC-12

  released channel: ci
 
4、在還原archive log的過程中,可以查看磁帶機的狀態(HP-UX):
  hp7420: mc -p /dev/rac/c2t0d0 -r DS
 
  DT_slot_1 FULL
  ST_slot_1 FULL
  ST_slot_2 FULL
  ST_slot_3 EMPTY
  ST_slot_4 FULL
  ST_slot_5 FULL
  ST_slot_6 FULL
  ST_slot_7 FULL
  ST_slot_8 FULL
 
  因為要還原的備份集在第三捲磁帶內,所以磁帶就從ST_slot_3移到DT_slot_1