Friday, 13 December 2019

Schema refresh automation script from prod to test database


Automate two schemas refresh from prod

refresh.sh

#!/bin/sh
export ORACLE_HOME=/u01/oracle/product/12.2.0.1/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH:/usr/local/bin
export ORACLE_SID=TESTDB
datetime() { echo `date '+%a%d%b%Y %H:%M:%S'` ;}
echo =======
echo Export command
echo =======
echo $(datetime)" ORACLE_HOME="$ORACLE_HOME >> /u01/datapump/logs/progress.log
echo $(datetime)" ORACLE_SID="$ORACLE_SID >> /u01/datapump/logs/progress.log
cd /u01/datapump/refresh_backup
rm drop_objts_CEN510DM_GWR602DM.sql
#drop objects of the schemas sch1,sch2
echo $(datetime)" droping schemas sch1 and sch2 is going on " >> /u01/datapump/logs/progress.log
@/u01/datapump/scripts/drop_objts_sch1_sch2.sh $ORACLE_HOME $ORACLE_SID
#import schemas from PR with DB link
echo $(datetime)" import from PR is going on for schemas sch1 and sch2 " >> /u01/datapump/logs/progress.log
impdp \'/as sysdba\'  network_link=REFRESH directory=REFRESH_DIR logfile=impdpsch1sch2.log schemas=pdata1,pdata2 remap_schema=pdata1:sch1,pdata2:sch2 TRANSFORM=DISABLE_ARCHIVE_LOGGING:Y
egrep -q "ORA-|Linux-x86_64 Error|stopped|Failed|FATAL" /u01/datapump/prod_backup/import_data.log
if [ $? -ne 0 ]; then
 echo $(datetime)" import success"  >> /u01/datapump/logs/progress.log
else
  echo $(datetime) " import is failed, check import logfile " >> /u01/datapump/logs/Error.log
 exit 1
fi



drop_objts_sch1_sch2.sh

#!/bin/sh
export ORACLE_HOME=$1
export ORACLE_SID=$2
export PATH=$ORACLE_HOME/bin:$PATH
sqlplus /nolog 
conn / as sysdba
set pages 10000
set echo off
set head off
spool /mnt/resource/datapump/prod_backup/drop_objts_SCH1_SCH2.sql
select 'drop '||object_type||' '||owner||'.'||object_name||';' from dba_objects where owner in('SCH1','SCH2');
spool off
@/u01/datapump/refresh_backup/drop_objts_SCH1_SCH2.sql
@/u01/datapump/refresh_backup/drop_objts_SCH1_SCH2.sql
@/u01/datapump/refresh_backup/drop_objts_SCH1_SCH2.sql

exit;

No comments:

Post a Comment