经常做恢复验证,每次都有些小不同,想省点事,搞个一键还原可好?适用于不同实例,源端和目标端最好版本一致,平台一致,开始吧。步骤介绍:#适用oracle 11g单机环境#备份在192.168.1.1的RESTORDIR目录下,采用rman备份的多个备份集文件,含参数文件(.par)、控制文件(c-xxx)、全库备份、归档备份#先清理本地的验证库环境,传备份片过来#恢复pfile文件后清理参数#恢复控制文件,注册备份信息#恢复数据库,调整重做日志#去掉归档模式#/bin/bash# restore database from rman# please first modify ORACLE_SID and RESTORDIR: . ~/.bash_profileRESTORDIR=/oradata/ORCL/20190131ORACLE_SID=ORCLexport ORACLE_SID=$ORACLE_SIDDBNAME=$ORACLE_SIDdbca -silent -deleteDatabase -sourceDB $DBNAME --先删库,再跑路:-)RMANDIR=/oradata/rmanbak/$DBNAMEssh [email protected] ln -s $RESTORDIR $RMANDIRBAKDIR=/oradata/$DBNAME/bakDATADIR=/oradata/$DBNAME/dbrm -fr $BAKDIR/*rm -fr $DATADIR/*rm -fr $ORACLE_HOME/dbs/*$DBNAME*mkdir -p $BAKDIRmkdir -p $DATADIRscp 192.168.1.1:$RMANDIR/* $BAKDIRCMDFILE=/tmp/rman1.txtPARFILE=`ls $BAKDIR/*.par`(catstartup nomountrestore spfile to pfile '$DATADIR/init.ora' from '$PARFILE';exitEOF)>$CMDFILErman target / cmdfile=$CMDFILEgrep -v ".__" $DATADIR/init.ora|grep -v cluster_database|grep -v "_listener"|grep -v "*.log_archive"|grep -v pga_aggregate_target|grep -v sga_max_size|grep -v sga_target|grep -v thread|grep -v control_files >/tmp/init2.oragrep -v db_cache_size /tmp/init2.ora|grep -v db_create_file_dest|grep -v "*.fal_"|grep -v instance_number|grep -v shared_pool_size>$DATADIR/init.oraecho "*.control_files=$DATADIR/control01.dbf" >>$DATADIR/init.oraecho "*.sga_max_size=4G" >> $DATADIR/init.oraecho "*.sga_target=4G" >> $DATADIR/init.oramkdir -p `grep audit_file_dest $DATADIR/init.ora |awk -F "'" '{print $2}'`CMDFILE=/tmp/rman2.txtCTLFILE=`ls $BAKDIR/c-*`(catstartup nomount pfile='$DATADIR/init.ora' forcerestore controlfile from '$CTLFILE';alter database mount;catalog start with '$BAKDIR/' noprompt;crosscheck backupset;delete noprompt expired backupset;exitEOF)>$CMDFILErman target / cmdfile=$CMDFILERMANLOG=/tmp/rman_log_$DBNAME.logCMDFILE=/tmp/rman_$DBNAME.txt(catrun {allocate channel c1 device type disk;allocate channel c2 device type disk;set newname for database to '$DATADIR/%b';restore database; switch datafile all;switch tempfile all;recover database;}exitEOF)>$CMDFILEtime nohup rman target / cmdfile=$CMDFILE log=$RMANLOG &(catset pagesize 9999 lin 250 echo off heading off verify off feedback off trims onspool /tmp/rename_log.sqlselect 'ALTER DATABASE RENAME FILE '''||member||''' to '||''''||'$DATADIR'||substr(member,instr(member,'/',-1)+1)||''';' cc from v$logfile;spool off@/tmp/rename_log.sqlspool /tmp/clear_log.sqlselect 'alter database clear logfile group '||group#||';' cc from v$log;spool off@/tmp/clear_log.sqlalter database open resetlogs;--alter database disable thread 2;--alter database drop logfile group 6,7,8,9,10;create spfile from pfile='$DATADIR/init.ora';shutdown immediatestartup mountalter database noarchivelog;alter database open;exit)>$CMDFILEsqlplus / as sysdba @$CMDFILEecho 'game over!'将上述代码保存为r.sh,放到目标端执行!基本上修改2处即可:要恢复的实例名和备份文件位置(备份服务器IP地址通常是固定的),如果没有配置信任关系执行时需要2次输入密码然后就是喝茶时间啦。 10-15 20:35