oracle 10g rman 指令碼

zhengbao_jun發表於2009-11-05

RMAN恢復指令碼

這些恢復指令碼考慮到不同的資料庫失敗的情況下,採取什麼樣的恢復方式。以下恢復指令碼存放在$ORACLE_HOME/rmanscripts目錄下,DBA可以直接通過命令列方式呼叫這些指令碼

例如:

su oracle

cd $ORACLE_HOME/rmanscripts

$ rman nocatalog target /  cmdfile= hot_database_restore.rcv

1  線上全恢復指令碼(hot_database_restore.rcv

run{

#Loss of all the database files except the redo logs and the control files

startup mount;

allocate channel t1 type disk;

allocate channel t2 type disk;

restore database;

recover database;

alter database open;

release channel t1;

release channel t2;

}

適用於:

DBA執行過線上熱備份

ORCL資料庫的一個(多個)資料檔案被破壞,但日誌和控制檔案完好

執行方式:

su oracle

$cd $ORACLE_HOME/rmanscripts

$ rman nocatalog target / cmdfile= hot_database_restore.rcv

:

如果ORCL臨時表空間TEMP的檔案也破壞了, rman不會自動恢復臨時表空間 (也不需要恢復),可以在恢復完資料庫後,重新建立臨時表空間TEMP:

su - oracle

SQL>connect / as sysdba

SQL>create temporary tablespace TEMP2 TEMPFILE '/app/u1/oradata/orcl/temp201.dbf' SIZE 512M REUSE AUTOEXTEND off;

SQL>alter database default temporary tablespace TEMP2;

SQL>drop tablespace TEMP including contents and datafiles;

SQL> create temporary tablespace TEMP tempfile '/app/u1/oradata/orcl/temp01.dbf'  size 1048576000 reuse autoextend off;

SQL> alter database default temporary tablespace TEMP;

SQL> drop tablespace TEMP2 including contents and datafiles;

2  線上全恢復指令碼2hot_database_restore2.rcv

存回控制檔案(restore controlfile):把備份的控制檔案/app/u1/oradata/orcl/rmanbackup/cntrl01.dbf存回目錄/app/u1/oradata/orcl/

run{

#Loss of all the database files except the redo log files

startup nomount;

allocate channel t1 type disk;

release channel t1;

alter database mount;

allocate channel t1 type disk;

allocate channel t2 type disk;

restore database;

recover database;

sql 'alter database open resetlogs';

release channel t1;

release channel t2;

# please run reset database after restore;

}

適用於:

DBA執行過線上熱備份

ORCL資料庫的一個(多個)資料檔案被破壞,控制檔案也被破壞,但日誌檔案完好

執行方式:

su oracle

$ cp /app/u1/oradata/orcl/rmanbackup/cntrl01.dbf /app/u1/oradata/orcl/cntrl01.dbf

$ cp /app/u1/oradata/orcl/rmanbackup/cntrl01.dbf /app/u1/oradata/orcl/cntrl02.dbf

$ cp /app/u1/oradata/orcl/rmanbackup/cntrl01.dbf /app/u1/oradata/orcl/cntrl03.dbf

$cd $ORACLE_HOME/rmanscripts

$ rman nocatalog target / cmdfile= hot_database_restore2.rcv

$ rman nocatalog target /

RMAN>reset database;

:

如果ORCL臨時表空間TEMP的檔案也破壞了, rman不會自動恢復臨時表空間 (也不需要恢復),可以在恢復完資料庫後,重新建立臨時表空間TEMP:

SQL>create temporary tablespace TEMP2 TEMPFILE '/app/u1/oradata/orcl/temp201.dbf' SIZE 512M REUSE AUTOEXTEND off;

SQL>alter database default temporary tablespace TEMP2;

SQL>drop tablespace TEMP including contents and datafiles;

SQL> create temporary tablespace TEMP tempfile '/app/u1/oradata/orcl/temp01.dbf'  size 1048576000 reuse autoextend off;

SQL> alter database default temporary tablespace TEMP;

SQL> drop tablespace TEMP2 including contents and datafiles;

3  線上全恢復指令碼3hot_database_restore3.rcv

存回控制檔案(restore controlfile):把備份的控制檔案/app/u1/oradata/orcl/rmanbackup/cntrl01.dbf存回目錄/app/u1/oradata/orcl/

run{

#Loss of all the database files including the redo log and the control files

startup nomount;

allocate channel t1 type disk;

alter database mount;

release channel t1;

allocate channel t1 type disk;

allocate channel t2 type disk;

restore database;

recover database;

release channel t1;

release channel t2;

#The recover database failed

#So we did the following at the command line Administering the database

#SQL> recover database using backup controlfile until cancel;

#SQL> cancel;

#SQL> alter database open resetlogs;

#SQL> exit;

}

適用於:

DBA執行過線上熱備份

ORCL資料庫的資料檔案,控制檔案,日誌檔案都被破壞

執行方式:

su oracle

$ cp /app/u1/oradata/orcl/rmanbackup/cntrl01.dbf /app/u1/oradata/orcl/cntrl01.dbf

$ cp /app/u1/oradata/orcl/rmanbackup/cntrl01.dbf /app/u1/oradata/orcl/cntrl02.dbf

$ cp /app/u1/oradata/orcl/rmanbackup/cntrl01.dbf /app/u1/oradata/orcl/cntrl03.dbf

$ rman nocatalog target / cmdfile=hot_database_restore3.rcv

su oracle

sqlplus /nolog

connect / as sysdba

SQL> recover database using backup controlfile until cancel;

cancel

SQL> alter database open resetlogs;

SQL> exit;

:

如果ORCL臨時表空間TEMP的檔案也破壞了, rman不會自動恢復臨時表空間 (也不需要恢復),可以在恢復完資料庫後,重新建立臨時表空間TEMP:

su oracle

sqlplus /nolog

connect / as sysdba

SQL>create temporary tablespace TEMP2 TEMPFILE '/app/u1/oradata/orcl/temp201.dbf' SIZE 512M REUSE AUTOEXTEND off;

SQL>alter database default temporary tablespace TEMP2;

SQL>drop tablespace TEMP including contents and datafiles;

SQL> create temporary tablespace TEMP tempfile '/app/u1/oradata/orcl/temp01.dbf'  size 1048576000 reuse autoextend off;

SQL> alter database default temporary tablespace TEMP;

SQL> drop tablespace TEMP2 including contents and datafiles;

 

刪除/app/u1/oradata/orcl/rmanbackup/目錄下的無用的備份記錄, 做恢復後的ORCL資料庫的全備份。

4  不完全恢復,恢復到之前的一個時間點

# su oracle

$ export NLS_DATE_FORMAT=YYYY-MM-DD-HH24:MI:SS

$ rman target / nocatalog  log=/tmp/rman.log

RMAN> run{

startup mount;

allocate channel t1 type disk;

allocate channel t2 type disk;

set until time ='2004-10-11-15:11:10';

restore database;

recover database;

sql 'alter database open resetlogs';

release channel t1;

release channel t2;

}

執行了不完全恢復後,刪除/app/u1/oradata/orcl/rmanbackup/目錄下的無用的備份記錄, 做恢復後的ORCL資料庫的全備份。

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

相關文章