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. 在线全恢复脚本2(hot_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. 在线全恢复脚本3(hot_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/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/235507/viewspace-618209/