Script de récupération semi-automatique Oracle rman - phase de restauration

#!/bin/bash
##############################################
#NAME: rman_auto_restore.sh
#DESC:restore oracle db from prod  environment to test environment very quickly.
#Note: Linux USER - execute as oracle instance user
#Use: nohup ./rman_auto_restore.sh > ./rman_auto_restore.sh.log &
#History:
#       v1.0 2022-03-08 yangshixian
##############################################

. /home/${
    
    USER}/.bash_profile
#
#define Oracle env 配置EBS环境变量
#

export ORACLE_SID=PROD #针对linux的配置文件中实例名大小写敏感
export ORACLE_HOME=/data/ebs/uat/db/tech_st/11.2.0 #目标环境ORACLE_HOME路径
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PERL5LIB=$ORACLE_HOME/perl/lib/5.10.0:$ORACLE_HOME/perl/lib/uate_perl/5.10.0:$ORACLE_HOME/appsutil/perl
export PATH=$ORACLE_HOME/perl/bin:$ORACLE_HOME/bin:$PATH


#
#rman env conf 配置rman环境变量#
#

RMAN_BAK_PATH=/data1/rman_data_of_prod/ #rman备份文件存放绝对路径
RMAN_CONTROLFILE=`ls $RMAN_BAK_PATH | grep C0_ |head -1` #控制文件绝对路径
TARGET_DATA_FILE_PATH=/data/ebs/uat/db/apps_st/data #目标环境数据文件位置

#
#unmount:execute rman restore scripts
#
echo "restore controlfile begin ..."
rman target / <<EOF
run
{
startup nomount;
RESTORE CONTROLFILE FROM '$RMAN_BAK_PATH$RMAN_CONTROLFILE';
alter database mount;
catalog start with '$RMAN_BAK_PATH' noprompt;
}
exit
EOF

echo "restore controlfile end Status $?"

#
#mount:execute rman restore scripts
#
echo "gen restore rman_scripts begin ...."

sqlplus -s / as sysdba <<EOF
set heading off feed off verify off echo off pages 0 trimspool on
set lines 132 pagesize 0
spo restore.rman
select 'run{' from dual;
select
'set newname for datafile ' || file# || ' to '|| '''' || '$TARGET_DATA_FILE_PATH' || substr(name,INSTR(name,'/',-1,1)) || '''' || ';'
from v\$datafile;
select
'restore database;' || chr(10) ||
'switch datafile all;' || chr(10) ||
'recover database until scn '|| controlfile_change# || ';' || chr(10) ||
'alter database open resetlogs;' || chr(10) ||
'}'
from  v\$database;
spo off
exit;
EOF

echo "gen restore rman_scripts end status $?"

echo "Rman restore begin ....."
echo `date`
rman target / log rman_auto_restore_`date -I`.log @restore.rman
echo "Rman restore over! status: $?"
echo `date`

おすすめ

転載: blog.csdn.net/x6_9x/article/details/123361715
おすすめ