Tuesday, September 4, 2012

Database Refresh using RMAN

Database Refresh using RMAN


Duplicate command based on SCN
find the SCN from PRD database
 
#!/usr/bin/ksh
export ORAENV_ASK='NO'
export ORACLE_SID=PRD
/usr/local/bin/oraenv

export NLS_LANG=American_america.us7ascii;
export NLS_DATE_FORMAT="Mon DD YYYY HH24:MI:SS";

$ORACLE_HOME/bin/rman target / nocatalog log=/tmp/duplicate_tape_TEST.log <<EOF
connect auxiliary
sys/PASSWORD@TEST;
run
{
allocate auxiliary channel aux1 device type disk;
set until SCN 42612597059;
duplicate target database to "TEST" pfile='/u01/app/xxxx/product/10.2.0/db_1/dbs/initTEST.ora' NOFILENAMECHECK;
}
EOF
mailx -s "PRD_Tape to TEST duplication result" "
hello@gmail.com.au" < /tmp/duplicate_tape_TEST.log

Duplicate command based on data and time

#!/usr/bin/ksh
export ORAENV_ASK='NO'
export ORACLE_SID=PRD
. oraenv

export NLS_LANG=American_america.us7ascii;
export NLS_DATE_FORMAT="Mon DD YYYY HH24:MI:SS";

$ORACLE_HOME/bin/rman target / nocatalog log=/tmp/duplicate_TEST.log <<EOF
connect auxiliary
sys/PASSWORD@TEST;
run
{
allocate auxiliary channel aux1 device type disk;
set until time 'Jan 14 2011 01:00:00';
duplicate target database to "ASIAMI" pfile='/u01/app/xxx/product/10.2.0/db_1/dbs/initTEST.ora' NOFILENAMECHECK;
}
EOF
mailx -s "PRD to TEST duplication result" "
HELLO@gmail.com" < /tmp/duplicate_TEST.log

Restore command until time

#!/usr/bin/ksh
. ~/.profile
export ORAENV_ASK='NO'
export ORACLE_SID=TEST
. oraenv
cd u02/test/scripts
export NOW=`date +"%Y%m%d%H%M"`


export NLS_LANG=American_america.us7ascii;
export NLS_DATE_FORMAT="Mon DD YYYY HH24:MI:SS";

#restore TEST to 'Aug 23 2010 07:00:00'
db_restore() {
$ORACLE_HOME/bin/rman target / nocatalog log =/u01/app/XXX/admin/TEST/logs/TESTrestore.$NOW.log <<EOF
run
{
allocate channel c1 device type disk;
SET UNTIL TIME 'Aug 23 2010 07:00:00';
RESTORE DATABASE;
RECOVER DATABASE;
}
EOF
}

#Send email after restore is done
email_result(){
mailx -s "TEST restore result" "
hello@gmail.com.au" < /u01/app/xxx/admin/TEST/logs/TESTrestore.$NOW.log
}

#execute function
db_restore
email_result

 

No comments:

Post a Comment

About Me

My photo
Sydney, NSW, Australia
An experienced IT professional (14+ years) worked in multiple industries such as consulting, education, financial, retail sectors. Carries good work experience in relational database design, analysis, modeling, development, administration, implementation, trouble shooting, support etc. Experienced in Oracle/SQL Server/MySQL DBA involving setup, configuration, tuning, backups, disaster recovery, high availability Oracle 11g/12C/19C RAC clusters; SQL server 2008/2012/2016 clusters, Oracle Engineered Systems such as EXADATA, ODA and Oracle and Azure Cloud. Performed Software Installations, Migrations, Database Capacity Planning, Automation of backup implementation, Cloud migration Tuning Oracle in windows/Unix platforms. In addition, experienced in UNIX administration, Shell scripting. PowerShell scripting A team player with communication skills.