Rman自动化恢复数据库脚本

Posted 我爱睡莲

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Rman自动化恢复数据库脚本相关的知识,希望对你有一定的参考价值。

    天天进步,记录一次Rman自动化恢复数据库脚本,断断续续经过一个星期的努力,终于憋出来了成品,感觉收获还是挺大的,毕竟是一个星期前shell命令连看懂都很费劲。

    做这个的目的是,有开发需要每隔一段时间就需要回复一下数据库。所以就做了一个定期恢复的脚本,使用rman来恢复。

附上rman整备和rman恢复的脚本:

RmanFullBackup.sh

#!/bin/bash #这个是rman全备shell脚本 #date 2019-02-27#定义全局变量ORACLE_SID、ORACLE_HOME、ORACLE_BASE、NLS_LANGexport ORACLE_SID=oggsource export ORACLE_BASE=/u01/app/oracleexport ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1#export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK" #定义变量backuptime,用于保存备份文件和备份日志#backuptime=`date+"20%y%m%d%H%M%S"`backup_dir=/u01/app/$backuptimeif [ ! -e "$backup_dir" ]then mkdir -p $backup_dir touch $backup_dir/log chown -R oracle:oinstall $backup_dir chmod -R 775 $backup_dirfisu - oracle 1>$backup_dir/log 2>&1 <<EOFcd $ORACLE_HOME/bin echo "$backup_dir/log"rman target / run{ allocate channel c1 device type disk; allocate channel c2 device type disk; allocate channel c3 device type disk; crosscheck backup; sql 'alter system archive log current'; backup database format '$backup_dir/db_%d_%T_%U'; sql 'alter system archive log current'; backup archivelog all format '$backup_dir/arc_%t_%s' delete all input; backup current controlfile format '$backup_dir/cntrl_%s_%p_%s'; crosscheck archivelog all; delete noprompt expired backup; delete noprompt obsolete; delete noprompt backup of database completed before 'sysdate - 30'; release channel c1; release channel c2; release channel c3; } EOF echo "backup complete!"

RmanRecover.sh

#!/bin/bash #定义全局变量ORACLE_SID、ORACLE_HOME、ORACLE_BASE、NLS_LANG#export ORACLE_SID=orcl #export ORACLE_BASE=/u01/app/oracle#export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1#export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK" #定义全局变量bwd=`ls -lt /u01/app/rmanbackup/ |grep cntrl|head -n 1|awk '{print $6,$7,$8}'`pwd=`ls -lt /u01/app/rmanbackup/ |grep cntrl|head -n 1|awk '{print $9}'`echo -e "Start restoring the latest control files:\n$bwd$pwd"backup_dir=/u01/app/rmanbackupif [ ! -e "$backup_dir" ]then mkdir -p $backup_dir touch $backup_dir/log chown -R oracle:oinstall $backup_dir chmod -R 775 $backup_dirfi#su - oracle -c "rman target / cmdfile ${dbconf} msglog ${dblog}"su - oracle 1>$backup_dir/log 2>&1 <<EOFcd $ORACLE_HOME/bin rman target /shutdown immediate;startup nomount;restore controlfile from '/u01/app/rmanbackup/$pwd';alter database mount;yes | catalog start with '/u01/app/rmanbackup/';run{allocate channel c1 device type disk; allocate channel c2 device type disk; allocate channel c3 device type disk;restore database;release channel c1; release channel c2; release channel c3;recover database;alter database open resetlogs;shutdown immediate;startup;}EOFecho "RmanRecovery Complited!"


以上是关于Rman自动化恢复数据库脚本的主要内容,如果未能解决你的问题,请参考以下文章

Oracle RMAN 自动恢复

关于Oracle RMAN 自动恢复

使用 Enterprise Manager 生成 RMAN 脚本并使用 chron 作业自动化它们

rman的存储脚本

RMAN跨版本恢复--从Oracle10.2.0.5恢复到Oracle11.2.0.4

基于catalog 创建RMAN存储脚本