RMAN恢復實踐(轉)

post0發表於2007-08-14
RMAN恢復實踐(轉)[@more@]

  關鍵詞:Oracle、恢復、RMAN

  

  談恢復肯定離不開備份,不過今天我們的重點不在於此,我在在這裡將備份分為兩類:作業系統備份和資料庫備份,而資料庫備份工作我們大部分都是用RMAN 來做。對於使用RMAN 我強烈建議使用catalog mode。

  

  測試環境:WIN2K ADV+ORACLE817

  

  RMAN:target database named ORA,catalog database named RCVDB

  

  

  

  一、Control file的恢復

  

  說明:RMAN 的備份必須在catalog mode下進行,否則備份了control file也沒有用;但即使是這樣有時候可能還會出現很多問題。建議:control file 用SQL或作業系統的方式做備份和恢復。

  

  1、RMAN備份的恢復

  

  備份:

  

  run {

  

  allocate channel c1 type disk;

  

  backup current controlfile;

  

  }

  

  恢復:

  

  run {

  

  allocate channel c1 type disk;

  

  restore controlfile to '/oracle/oradata/ora/control01.ctl';

  

  replicate controlfile from '/oracle/oradata/ora/control01.ctl';

  

  restore database;

  

  sql 'alter database mount';

  

  recover database until cancel;

  

  sql 'alter database open resetlogs';

  

  release channel c1;

  

  }

  

  使用resetlogs之後需在catalog database 上進行reset database,原有備份資訊將不可用,所以要及時進行新的完全備份。

  

  2、SQL備份的恢復

  

  備份:

  

  alter database backup controlfile to trace;

  

  恢復:

  

  先將資料庫shutdown,然後從備份所產生的trace檔案中拷出建立恢復所用的SQL執行一遍

  

  即可。如果你之前沒有做這樣的備份那也沒關係,形式如下你可以照著寫一個:

  

  #--------------------------------BEGIN-----------------------------------------

  

  # The following commands will create a new control file and use it

  

  # to open the database.

  

  # Data used by the recovery manager will be lost. Additional logs may

  

  # be required for media recovery of offline data files. Use this

  

  # only if the current version of all online logs are available.

  

  STARTUP NOMOUNT

  

  CREATE CONTROLFILE REUSE DATABASE "ORA" NORESETLOGS

  

  NOARCHIVELOG

  

  MAXLOGFILES 32

  

  MAXLOGMEMBERS 2

  

  MAXDATAFILES 32

  

  MAXINSTANCES 16

  

  MAXLOGHISTORY 680

  

  LOGFILE

  

  GROUP 1 (

  

  'C:ORACLEORADATAORAREDO01.LOG',

  

  'C:ORACLEORADATAORAREDO01_1.LOG'

  

  ) SIZE 1M,

  

  GROUP 2 (

  

  'C:ORACLEORADATAORAREDO02.LOG',

  

  'C:ORACLEORADATAORAREDO02_1.LOG'

  

  ) SIZE 1M,

  

  GROUP 3 (

  

  'C:ORACLEORADATAORAREDO03_1.LOG',

  

  'C:ORACLEORADATAORAREDO03_2.LOG'

  

  ) SIZE 1M

  

  DATAFILE

  

  'C:ORACLEORADATAORASYSTEM01.DBF',

  

  'C:ORACLEORADATAORARBS01.DBF',

  

  'C:ORACLEORADATAORAUSERS01.DBF',

  

  'C:ORACLEORADATAORATEMP01.DBF',

  

  'C:ORACLEORADATAORATOOLS01.DBF',

  

  'C:ORACLEORADATAORAINDX01.DBF'

  

  CHARACTER SET ZHS16GBK

  

  ;

  

  # Recovery is required if any of the datafiles are restored backups,

  

  # or if the last shutdown was not normal or immediate.

  

  RECOVER DATABASE

  

  # Database can now be opened normally.

  

  ALTER DATABASE OPEN;

  

  #----------------------------------END-----------------------------------------

  

  3、OS 備份的恢復

  

  備份:

  

  OS copy

  

  恢復:

  

  OS copy回來即可,要注意的是這個備份必須是最新有效的。

  

  二、Database的恢復

  

  A、To restore the database from host_a to host_b with the same file system

  

  #此處使用recovery catalog;

  

  #如果不是catalog mode,就用OS COPY直接將control file

  

  #copy過來並mount database。

  

  1、copy the init.ora file from host_a to host_b using o/s utility

  

  2、rman target sys/sys@host_b catalog rman/rman@rcat

  

  3、startup nomount

  

  4、run {

  

  allocate channel c1 type disk;

  

  restore controlfile;

  

  sql ‘alter database mount’;

  

  }

  

  5、select min(scn) from (

  

  select max(next_change#) scn from v$archived_log

  

  group by thread#);

  

  6、run {

  

  set until scn=500; #use appropriate SCN for incomplete recovery

  

  allocate channel c1 type ‘sbt_type’;

  

  restore database;

  

  recover database;

  

  sql ‘alter database open resetlogs’;

  

  }

  

  B、To restore the database from host_a to host_b with a different filesystem

  

  步驟和A差不多,不同的是在啟動資料庫之前要修改init.ora檔案中所有和路徑相關的引數,

  

  如:*_DEST,*_PATH 等。然後執行如下指令碼:

  

  run {

  

  set until scn=500;

  

  allocate channel c1 type disk;

  

  set newname for datafile 1 to ‘/disk’/%U’;

  

  set newname for datafile 2 to ‘/disk’/%U’;

  

  set newname for datafile 3 to ‘/disk’/%U’;

  

  set newname for datafile 4 to ‘/disk’/%U’;

  

  set newname for datafile 5 to ‘/disk’/%U’;

  

  set newname for datafile 6 to ‘/disk’/%U’;

  

  set newname for datafile 7 to ‘/disk’/%U’;

  

  sql ‘alter database mount’;

  

  restore database;

  

  switch datafile all; #points the control file to the renamed datafiles

  

  recover database;

  

  .... ....

  

  sql ‘alter database open resetlogs’;

  

  }

  

  三、Tablespace and datafile的恢復

  

  run {

  

  allocate channel c1 type disk;

  

  sql ‘alter tablespace users offline immediate’; #must be in archive log mode

  

  #如下改變datafile位置

  

  set newname for datafile 'c:/oracle/oradata/ora/users01.dbf'

  

  to 'c:/oracle/oradata/orabk/user01.dbf';

  

  restore tablespace users;

  

  switch datafile all;

  

  recover tablespace users;

  

  sql ‘alter tablespace users online’;

  

  }

  

  如果不在archive log mode下,執行以上SQL時會出錯:ORA-01145。你將不得不shutdown。

  

  四、關於set until 選項

  

  set until後面可以跟time、scn和logseq三個不同的選項,當資料庫執行在noarchivelog

  

  mode 下時可以使用until cancel選項進行資料庫的不完全恢復。所有這些的具體過程和以上

  

  的資料庫恢復都差不多,不再贅述。

  


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

相關文章