#!/bin/sh
v_dbname=orcl
su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/srvctl stop database -d $v_dbname -o abort"
su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/sqlplus /nolog" <<EOF
 conn / as sysdba
 startup mount exclusive
EOF

rm -f /home/oracle/example01.dbf 2>/dev/null

su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target /" <<EOF
 backup as copy datafile 5 format '/home/oracle/example01.dbf';
EOF

dd if=/dev/zero of=/home/oracle/example01.dbf bs=8192 count=1 seek=175 conv=notrunc

su - oracle -c "export ORACLE_HOME=/u01/app/oracle/product/11.2.0/grid ; export ORACLE_SID=+ASM ; /u01/app/oracle/product/11.2.0/grid/bin/asmcmd" <<EOF
 rm -f +data/$v_dbname/DATAFILE/example*
EOF

su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target /" <<EOF
 run {
 set maxcorrupt for datafile 5 to 1;
 backup as copy  datafilecopy '/home/oracle/example01.dbf' format '+data';
 }
EOF

sleep 3

su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target /" <<EOF
 delete noprompt datafilecopy '/home/oracle/example01.dbf';
 switch datafile 5 to copy;
EOF


su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/sqlplus /nolog" <<EOF
 conn / as sysdba
 alter database open;
EOF
