Oracle 10g備份與恢復高階使用者指南--第七章 RMAN備份過程與方法

panpong發表於2017-01-05

第七章        RMAN恢復過程與方法

1.                  非歸檔模式恢復

         非歸檔模式資料庫恢復與歸檔模式下恢復相似,不同的是非歸檔模式下恢復只能使用冷備份,並且不能進行介質恢復(因為無歸檔日誌);

         非歸檔模式下,使用增量備份恢復案例;場景,非歸檔模式資料庫trgt,使用了catalog,在星期日做了一次一致性關閉後的0級增量備份,後在星期三和星期五一致性關閉後做了1級差異增量備份;資料庫在星期六出現介質故障,一半資料檔案和redo日誌損壞;恢復方法如下:

STARTUP FORCE NOMOUNT;

RESTORE CONTROLFILE;  # restore control file from consistent backup

ALTER DATABASE MOUNT;

RESTORE DATABASE;  # restore datafiles from consistent backup

RECOVER DATABASE NOREDO;  # specify NOREDO because online redo logs are lost

ALTER DATABASE OPEN RESETLOGS;

 

2.                  異機恢復


利用RMAN備份,在新主機上還原與恢復資料庫;

1)  準備工作

a.       記錄資料庫DBID

b.       確保新主機上初始化引數檔案可用

c.       確保新主機上備份集可用

2)  還原恢復過程

假設場景:

A.      主機hostahostb都是linux系統,且相互連通

B.      Target db:trgta(hosta),catalog:catdb

C.      要還原和恢復到hostb,同時hosta上的trgta執行

D.      Hostbhosta的目錄結構不同,分別是/net/hosta/dev3/oracle/dbs /net/hostb/oracle/oradata/test

E.       Trgta使用spfile

F.       ORACLE_SIDtrgta,還原後保持不變

G.      已經記錄trgtaDBID

H.      介質管理器兩臺主機都可以訪問

I.        資料檔案的備份在磁帶上

J.        必要的歸檔日誌也已經備份

K.       控制檔案和spfile已經自動備份到磁帶上

下面是執行過程:

a.       Dfaf

% rman TARGET / NOCATALOG

SET DBID 1340752057;

STARTUP NOMOUNT

RUN

{

  ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS='...';

  RESTORE SPFILE TO PFILE '?/oradata/test/inittrgta.ora' FROM AUTOBACKUP;

  SHUTDOWN ABORT;

}

修改引數檔案中有關目錄位置,然後

STARTUP FORCE NOMOUNT PFILE='?/oradata/test/inittrgta.ora';

RUN

{

  ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS='...';

  RESTORE CONTROLFILE FROM AUTOBACKUP;

  ALTER DATABASE MOUNT;

}

% sqlplus '/ AS SYSDBA'

Run the following query in SQL*Plus:

SQL> COLUMN NAME FORMAT a60

SQL> SPOOL LOG 'db_filenames.out'

SQL> SELECT FILE# AS "File/Grp#", NAME FROM V$DATAFILE

     UNION

     SELECT GROUP#,MEMBER FROM V$LOGFILE;

SQL> SPOOL OFF

SQL EXIT

 

RUN

{

  # allocate a channel to the tape device

  ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS='...';

 

  # rename the datafiles and online redo logs

  SET NEWNAME FOR DATAFILE 1 TO '?/oradata/test/system01.dbf';

  SET NEWNAME FOR DATAFILE 2 TO '?/oradata/test/undotbs01.dbf';

  SET NEWNAME FOR DATAFILE 3 TO '?/oradata/test/cwmlite01.dbf';

  SET NEWNAME FOR DATAFILE 4 TO '?/oradata/test/drsys01.dbf';

  SET NEWNAME FOR DATAFILE 5 TO '?/oradata/test/example01.dbf';

  SET NEWNAME FOR DATAFILE 6 TO '?/oradata/test/indx01.dbf';

  SET NEWNAME FOR DATAFILE 7 TO '?/oradata/test/tools01.dbf';

  SET NEWNAME FOR DATAFILE 8 TO '?/oradata/test/users01.dbf';

  SQL "ALTER DATABASE RENAME FILE ''/dev3/oracle/dbs/redo01.log''

      TO ''?/oradata/test/redo01.log'' ";

  SQL "ALTER DATABASE RENAME FILE ''/dev3/oracle/dbs/redo02.log''

      TO ''?/oradata/test/redo02.log'' ";

 

  # Do a SET UNTIL to prevent recovery of the online logs

  SET UNTIL SCN 123456;

  # restore the database and switch the datafile names

  RESTORE DATABASE;

  SWITCH DATAFILE ALL;

 

  # recover the database

  RECOVER DATABASE;

}

EXIT

 

% rman TARGET / NOCATALOG

RMAN> @reco_test.rman

 

RMAN> ALTER DATABASE OPEN RESETLOGS;


3.                  控制檔案恢復

利用自動備份的控制檔案恢復資料庫,無catalog,步驟如下:

CONNECT TARGET /

STARTUP NOMOUNT;

SET DBID 676549873;

RUN

{

  # Optionally, set upper limit for eligible time stamps of control file

  # backups

  # SET UNTIL TIME '09/10/2000 13:45:00';

  # Specify a nondefault autobackup format only if required

  # SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK

  #   TO '?/oradata/%F.bck';

  ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS='...'; # allocate manually

  RESTORE CONTROLFILE FROM AUTOBACKUP

    MAXSEQ 100           # start at sequence 100 and count down

    MAXDAYS 180;         # start at UNTIL TIME and search back 6 months

  ALTER DATABASE MOUNT DATABASE;

}

# uses automatic channels configured in restored control file

RESTORE DATABASE UNTIL SEQUENCE 13243;

RECOVER DATABASE UNTIL SEQUENCE 13243; # recovers to latest archived log

 

ALTER DATABASE OPEN RESETLOGS; 
 
  


4.                  災難恢復

         災難恢復是指當目標資料檔案、引數檔案、控制檔案、線上日誌檔案、目錄資料庫檔案等遭受災難性毀滅情況下的恢復;要想完成災難恢復最小的要求是有資料檔案備份、有備份後的歸檔日誌備份、有至少一份自動備份的控制檔案;

         災難恢復基本過程:一還原引數檔案,這樣可以啟動例項;二啟動例項後還原控制檔案,這樣就可以mount資料庫;三mount狀態下,還原資料檔案;四恢復資料庫;五resetlog開啟資料庫;

         災難恢復基本命令如下:

#登入

% rman TARGET SYS/oracle@trgt

#還原引數檔案spfile

# Set the DBID for the target database

RMAN> SET DBID 676549873;

RMAN> STARTUP FORCE NOMOUNT;  # rman starts instance with dummy parameter file

RUN

{

  ALLOCATE CHANNEL t1 DEVICE TYPE sbt;

  RESTORE SPFILE FROM AUTOBACKUP;

}

#還原控制檔案、資料檔案

RMAN> STARTUP FORCE NOMOUNT; # Restart instance with restored server parameter file

RMAN> RUN

{

  ALLOCATE CHANNEL t1 DEVICE TYPE sbt;

  RESTORE CONTROLFILE FROM AUTOBACKUP;

  ALTER DATABASE MOUNT;#相同路徑還原(如果路徑不同需要SET NEWNAME

  SET UNTIL SEQUENCE 1124 THREAD 1;

  RESTORE DATABASE;(如果路徑不同SWITCH DATAFILE ALL

  RECOVER DATABASE;

}

RMAN> ALTER DATABASE OPEN RESETLOGS; # Reset the online logs after recovery completes

 

5.                  RMAN塊介質恢復

         BLOCKRECOVER可以執行壞塊介質恢復;

RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 13 DATAFILE 2 BLOCK 19;

指定特定備份進行塊恢復

  #指定備份集還原

RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 13 DATAFILE 2 BLOCK 19 FROM BACKUPSET;

 #指定映象複製還原

RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 13 DATAFILE 2 BLOCK 19 FROM DATAFILECOPY;

 #指定特定標籤TAG還原

RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 13 DATAFILE 2 BLOCK 199 FROM TAG = mondayam;

 #指定特定時間段的備份還原

RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 13 DATAFILE 2 BLOCK 19 RESTORE UNTIL 'SYSDATE-7';

 #指定特定SCN段的備份還原

RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 13 DATAFILE 2 BLOCK 19 RESTORE UNTIL SCN 100;

 #指定特定日誌序號的還原

RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 13 DATAFILE 2 BLOCK 19 RESTORE UNTIL SEQUENCE 7024;

 #批次壞塊還原

SQL> SELECT * FROM V$DATABASE_BLOCK_CORRUPTION;

RMAN> BLOCKRECOVER CORRUPTION LIST RESTORE UNTIL TIME 'SYSDATE-10';

 

6.                  RMAN恢復案例

案例1:異機還原資料檔案映象

RMAN>LIST COPY;

#複製資料檔案映象到目標機器上

% cp -r /tmp/*dbf /net/new_host/oracle/oradata/trgt

#解除編目

RMAN>CHANGE COPY OF DATAFILE 1,2,3,4,5,6,7,8 UNCATALOG;

#重新編目(新地址)

RMAN>CATALOG START WITH '?/oradata/trgt/';

或:

RMAN>CATALOG DATAFILECOPY

  '?/oradata/trgt/system01.dbf', '?/oradata/trgt/undotbs01.dbf',

  '?/oradata/trgt/cwmlite01.dbf', '?/oradata/trgt/drsys01.dbf',

  '?/oradata/trgt/example01.dbf', '?/oradata/trgt/indx01.dbf',

  '?/oradata/trgt/tools01.dbf', '?/oradata/trgt/users01.dbf';

 #最後按照災難恢復執行

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

相關文章