Using RMAN backups, we can duplicate a database to different environments for testing purposes, or validate the backup itself.
Here is the procedure and command examples,
The high level procedure
0) using dbca create an empty database (only needed for first time) 1) generate asm file list (see instructions below) 2) alter system set cluster_database=FALSE scope=spfile; 3) srvctl stop database -d TEST2 -o immediate 4) drop asm files (see instructions below) 5) srvctl start instance -d TEST2 -i TEST21 -o nomount 6) rman auxiliary / catalog rcat/rcat@rcat msglog logfile cmdfile rman_script 7) alter system set cluster_database=TRUE scope=spfile; 8) srvctl stop database -d TEST2 -o immediate 9) srvctl start database -d TEST2
How to generate asm file list
SQL> spool file_list.txt SQL> select file_name from cdb_data_files; SQL> select file_name from cdb_temp_files; SQL> select member from v$logfile; SQL> alter session set container = pdb$SEED; SQL> select file_name from dba_data_files; SQL> select file_name from dba_temp_files; SQL> spool off
How to drop asm file
SQL> alter diskgroup "DG1" drop file '+DG1/TEST1/615776D7ECB497D5E053425A030AC5D8/DATAFILE/users.9257.963829293';
Example ramn script
run
{
ALLOCATE auxiliary CHANNEL c1 TYPE 'SBT' parms='BLKSIZE=..,SBT_LIBRARY=..,ENV=(..)';
ALLOCATE auxiliary CHANNEL c2 TYPE 'SBT' parms='BLKSIZE=..,SBT_LIBRARY=..,ENV=(..)';
ALLOCATE auxiliary CHANNEL c3 TYPE 'SBT' parms='BLKSIZE=..,SBT_LIBRARY=..,ENV=(..)';
ALLOCATE auxiliary CHANNEL c4 TYPE 'SBT' parms='BLKSIZE=..,SBT_LIBRARY=..,ENV=(..)';
set until time="to_date('2017-12-28 09:00:00', 'YYYY-MM-DD HH24:MI:SS')";
duplicate database TEST1 to TEST2 ;
}