Duplicate Database from Active Database — Just Works!

Jul 2, 2013 / By Yury Velikanov

Tags: , , ,

My friend Øyvind Isene suggested that I store a DUPLICATE RMAN script that works in a safe place in this tweet.


I couldn’t find a safer place for the script than the Pythian blog :). Here goes the DUPLICATE DATABASE … from an ACTIVE DATABASE script that works for me beautifully.

I like the fact that we don’t need to worry about any time-consuming tasks anymore. For example, you don’t need the init.ora parameter on the destination side. Oracle creates it all for us. If you want to change any parameters (e.g. reduce memory footprint), you just specify it within the DUPLICATE command (e.g. set sga_target=4G).

Details

Version = 11.2.0.3 on both sides
Source db = prod
Destination db = test

On the source (prod):
— tns aliases to be created to point to prod and test databases
On the destination (test):
— the same version of Oracle SW installed
— directory structure created
— copy $ORACLE_HOME/dbs/orapwprod (from prod) to $ORACLE_HOME/dbs/orapwtest
— configure static listener configuration (allow you to connect as sysdba from prod)
— start an empty test instance “export ORACLE_HOME=….; export ORACLE_SID=….; sqlplus => statup nomount;”

Notes:
– No SPFILE is needed. It will be taken case of while running DUPLICATE.
– Prod db files are located under /u01/oradata/prod.
– Test db files to be located under /u02/oradata/test.
– It doesn’t matter from where you execute the command (prod or test).

Script

cat run_active_duplicate_prod_test_01.sh
. prod.env
echo $ORACLE_HOME $ORACLE_SID $TNS_ADMIN
export NLS_DATE_FORMAT="YYYY/MM/DD HH24:MI:SS"
rman TARGET sys/password@prod AUXILIARY sys/password@test
DUPLICATE DATABASE TO test
FROM ACTIVE DATABASE
SPFILE parameter_value_convert 'prod','test'
set db_file_name_convert='u01/oradata/prod','u02/oradata/test'
set log_file_name_convert='u01/oradata/prod','u02/oradata/test'
set control_files='/u02/oradata/test/cntrl01.dbf';
EOF

Kick off

nohup ./run_active_duplicate_prod_test_01.sh 2>&1 \
1>./run_active_duplicate_prod_test_01.`date +%Y%m%d_%H%M%S`.log &
ls -lptr ./run_active_duplicate_prod_test_01.`date +%Y%m%d_%H%M%S`.log

Verification


tail -f ./run_active_duplicate_prod_test_01.*.log
...
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 2013/07/01 05:42:30

RMAN

Recovery Manager complete.

6 Responses to “Duplicate Database from Active Database — Just Works!”

  • Rene Antunez says:

    Great post Yury, the only thing that I would make an emphasis on whoever uses this method and is in a RAC environment, make sure to shutdown the static listener after and just use this for the DUPLICATE. I’ve seen in the past conflicts with this, as people leave the static listener and share the tns entry of the static listener, making connections to this , instead of the scan listener.

  • Greg says:

    Cool stuff Yury! Do we need leading ‘/’ here u01/oradata/prod ?
    Regards
    Greg

    • Hi Greg,

      Nope. There is no mistake. As both prod and test have leading “/” in the path we don’t need to specify it in convert parameters. it is enough to specify the patterns to be replaced only (different parts of the string).

      Yury

  • Hendra says:

    Thank you Yury, i got enlightenment by read your post.

    • Hendra says:

      Oh.. another thing is when you get RMAN-05001 don’t panic. its not error, oracle RMAN just want to show you that your path for convert is wrong path for the source. follow path on message cause its the true path.

      Thank you Yury, it does spent me a day for process duplication.

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>