rman Restore datafile (sh)


export ORACLE_SID=TEST2
echo 'shutting down TEST2 ABORT'
echo
sqlplus /nolog <<EOF
connect rman/rman_oracledba as sysdba
shutdown abort
exit
EOF
echo
echo 'removing datafile /data/oracle/TEST2/dataTEST2.dbf '
echo
rm /data/oracle/TEST2/dataTEST2.dbf
echo 'listing the directory to verify datafile does not exist'
ls -l /data/oracle/TEST2
sleep 5
echo
echo 'starting TEST2 in MOUNT mode'
echo
sqlplus /nolog <<EOF
connect rman/rman_oracledba as sysdba
startup mount
alter database datafile '/data/oracle/TEST2/dataTEST2.dbf' offline;
alter database open;
exit
EOF
echo
echo 'checking the status of datafiles'
echo
sqlplus /nolog @checkdf.sql
sleep 10
echo 'Restoring datafile using RMAN' 
rman <<EOF
connect target rman/rman_oracledba@test2 
connect catalog rman/rman_oracledba@test1
run { allocate channel d1 type disk;
restore datafile '/data/oracle/TEST2/dataTEST2.dbf';
recover datafile '/data/oracle/TEST2/dataTEST2.dbf';
}
EOF
sqlplus /nolog <<EOF
connect rman/rman_oracledba as sysdba
alter database datafile '/data/oracle/TEST2/dataTEST2.dbf' online;
exit
EOF
echo
echo 'checking the status of datafiles'
echo
sqlplus /nolog @checkdf.sql

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: