oracle 10g rman 脚本

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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/235507/viewspace-618209/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值