Thursday, 2 October 2014

RMAN Automatic Script : Restore & Recover Datafile

export ORACLE_SID=TEST2

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


checkdf.sql

col file_name for a40
sqlplus rman/rman_oracledba as sysdba
select df.file_name, d.status
from dba_data_files df,
v$datafile d
where df.file_id=d.file#;
exit;

No comments:

Post a Comment