#!/bin/bash
. /home/${USER}/.bash_profile
export PATH=/data/ebs/sit/db/tech_st/11.2.0/perl/bin:/data/ebs/sit/db/tech_st/11.2.0/bin:$PATH
export PERL5LIB=/data/ebs/sit/db/tech_st/11.2.0/perl/lib/5.10.0:/data/ebs/sit/db/tech_st/11.2.0/perl/lib/site_perl/5.10.0:/data/ebs/sit/db/tech_st/11.2.0/appsutil/perl
export ORACLE_SID=PROD
export ORACLE_HOME=/data/ebs/sit/db/tech_st/11.2.0
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
RMAN_BAK_PATH=/data1/backup/rman_bak_data/
RMAN_CONTROLFILE=`ls $RMAN_BAK_PATH | grep C0_ |head -1`
TARGET_DATA_FILE_PATH=/data/ebs/sit/db/apps_st/data
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 $?"
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) ||
'}'
from dual;
spo off
exit;
EOF
echo "gen restore rman_scripts end status $?"
echo "begin rman restore ....."
echo `date`
rman target / log rman_auto_restore_`date -I`.log @restore.rman
echo "begin rman restore over! status: $?"
echo `date`
|