1. Step 2: Build a Rman Script. There are a couple of ways to recover to a point in
time and we have decided to use SCN numbers. Since this process needs to be
automated, we query productions rman catalog and determine the proper SCN to use
and build an rman script. Here it is:
set feedback off
set echo off
set serverout on
spool $HOME/scripts/prod_to_vis.sql
declare
vmax_fuzzy number;
vmax_ckp number;
scn number;
db_name varchar2(3) := 'VIS';
log_file_dest1 varchar2(30) := '/dbf/visdata/';
begin
select max(absolute_fuzzy_change#)+1,
max(checkpoint_change#)+1
into vmax_fuzzy, vmax_ckp
from rc_backup_datafile;
if vmax_fuzzy > vmax_ckp then
scn := vmax_fuzzy;
else
scn := vmax_ckp;
end if;
dbms_output.put_line('run {');
dbms_output.put_line('set until scn '||to_char(scn)||';');
dbms_output.put_line('allocate auxiliary channel ch1 type disk;');
dbms_output.put_line('allocate auxiliary channel ch2 type disk;');
dbms_output.put_line('duplicate target database to '||db_name);
dbms_output.put_line('logfile group 1 ('||chr(39)||
log_file_dest1||'log01a.dbf'||chr(39)||',');
dbms_output.put_line(chr(39)||log_file_dest1||'log01b.dbf'||chr(39)||') size
10m,');
dbms_output.put_line('group 2 ('||chr(39)||log_file_dest1||'log02a.dbf'||
chr(39)||',');
dbms_output.put_line(chr(39)||log_file_dest1||'log02b.dbf'||chr(39)||') size
10m;}');
dbms_output.put_line('exit;');
end;
/
spool off;
This script produces a spool file called, prod_to_vis.sql:
run {
set until scn 14085390202;
allocate auxiliary channel ch1 type disk;
allocate auxiliary channel ch2 type disk;
duplicate target database to VIS
logfile group 1 ('/dbf/visdata/log01a.dbf',
'/dbf/visdata/log01b.dbf') size 10m,
group 2 ('/oradata/dbf/visdata/log02a.dbf',
'/dbf/visdata/log02b.dbf') size 10m;}
exit;
Note: Our production nightly backups are on disk which are NFS mounted to our
test server.
Step 3: Execute the rman script. Launch rman, connect to the target, catalog,
auxiliary and execute the script above:
ie.
rman> connect target sys/syspasswd@PROD catalog rmancat/catpasswd@REPO auxiliary
/
2. You may want to put some error checking around rman to alert you if it fails. We
have a wrapper script which supplies the connection information and calls the
rman script above. Our refresh is critical so if it fails we need to be paged.
rman @$SCRIPTS/prod_to_vis.sql
if [ $? != 0 ]
then
echo Failed
echo "RMAN Dupcliate Failed!"|mailx -s "Test refresh failed"
pageremail@mycompany.com
exit 1
fi
Step 4: If production is in archivelog mode but test isn't, then mount the
database and alter database noarchivelog;