Duplicating an Oracle Database from a Backup.

O RMAN (Recovery Manager) tem a capacidade de clonar ou duplicar um banco de dados através de um backup ou banco de dados ativo, neste artigo, irei clonar um database a partir de um backup, como também criar o banco de homologação chamado hml.

Banco de origem:

set lines 200
col DATABASE_HOST for a25;
col DB_UNIQUE_NAME for a25
col HOST_NAME for a15;
col DATABASE_ROLE for a10
col OPEN_MODE for a10
col STARTUP_TIME for a20
alter session set nls_date_format = 'DD/MM/YYYY HH24:MI:SS';
SELECT i.HOST_NAME "DATABASE_HOST" ,
i.INSTANCE_NAME "DB_NAME",
d.db_unique_name "DB_UNIQUE_NAME" , 
d.DATABASE_ROLE " DATABASE_ROLE",
i.VERSION,
d.OPEN_MODE " OPEN_MODE ",
d.LOG_MODE
,STARTUP_TIME 
from GV$DATABASE d, gv$instance i 
where i.INST_ID=d.INST_ID;
DATABASE_HOST             DB_NAME          DB_UNIQUE_NAME             DATABASE_ROLE   VERSION            OPEN_MODE           LOG_MODE     STARTUP_TIME
------------------------- ---------------- ------------------------- ---------------- ----------------- -------------------- ------------ --------------------
srv01                     lab12c           lab12c                    PRIMARY          12.2.0.1.0        READ WRITE           ARCHIVELOG   03/02/2023 09:37:59

Executando um backup level 0 com archivelogs do banco lab12c:

run
{
configure channel device type disk maxpiecesize 10G format '/u02/backups/12c/backupset/%d_full_%I-%s-%U.bak';
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u02/backups/12c/backupset/%F';
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
sql "alter system switch logfile";
sql "create pfile = ''/u02/backups/12c/backupset/initlab12c.ora'' from spfile";
BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL=0 DATABASE INCLUDE CURRENT CONTROLFILE TAG='db_full_cf' PLUS ARCHIVELOG TAG='arc_full_cf';
backup current controlfile tag='cf_current_full';
sql "alter system switch logfile";
}
[oracle@srv01 oradata]$ rman target /

Recovery Manager: Release 12.2.0.1.0 - Production on Fri Feb 3 09:40:35 2023

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

connected to target database: LAB12C (DBID=1830920858)

RMAN> run
{
configure channel device type disk maxpiecesize 10G format '/u02/backups/12c/backupset/%d_full_%I-%s-%U.bak';
CONFIGURE CO2> 3> 4> NTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u02/backups/12c/backupset/%F';
CONFIG5> 6> URE RETENTION POLICY TO REDUNDANCY 1;
sql "alter system switch logfile";
sql "create pfile = ''/u02/backups/12c/backupset/initla7> 8> b12c.ora'' from spfile";
BACKUP 9> AS COMPRESSED BACKUPSET INCREMENTAL LEVEL=0 DATABASE INCLUDE CURRENT CONTROLFILE TAG='db_full_cf' PLUS ARCHIVELOG TAG='arc_full_cf';
backup current controlfile tag='cf_current_full';
sql "alter system switch logfile";
}10> 11> 12>

using target database control file instead of recovery catalog
old RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK MAXPIECESIZE 10 G FORMAT   '/u02/backups/12c/backupset/%d_full_%I-%s-%U.bak';
new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK MAXPIECESIZE 10 G FORMAT   '/u02/backups/12c/backupset/%d_full_%I-%s-%U.bak';
new RMAN configuration parameters are successfully stored

old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u02/backups/12c/backupset/%F';
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u02/backups/12c/backupset/%F';
new RMAN configuration parameters are successfully stored

old RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO REDUNDANCY 3;
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
new RMAN configuration parameters are successfully stored

sql statement: alter system switch logfile

sql statement: create pfile = ''/u02/backups/12c/backupset/initlab12c.ora'' from spfile


Starting backup at 03-FEB-23
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=263 device type=DISK
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=10 RECID=5 STAMP=1115324766
input archived log thread=1 sequence=11 RECID=6 STAMP=1115324778
input archived log thread=1 sequence=12 RECID=7 STAMP=1115324784
input archived log thread=1 sequence=13 RECID=8 STAMP=1115325013
input archived log thread=1 sequence=14 RECID=9 STAMP=1125486540
input archived log thread=1 sequence=15 RECID=10 STAMP=1127813888
input archived log thread=1 sequence=16 RECID=11 STAMP=1127814045
input archived log thread=1 sequence=17 RECID=12 STAMP=1127814045
channel ORA_DISK_1: starting piece 1 at 03-FEB-23
channel ORA_DISK_1: finished piece 1 at 03-FEB-23
piece handle=/u02/backups/12c/backupset/LAB12C_full_1830920858-9-091ji4su_1_1.bak tag=ARC_FULL_CF comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 03-FEB-23

Starting backup at 03-FEB-23
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/lab12c/system01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/lab12c/sysaux01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/lab12c/undotbs01.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/lab12c/users01.dbf
channel ORA_DISK_1: starting piece 1 at 03-FEB-23
channel ORA_DISK_1: finished piece 1 at 03-FEB-23
piece handle=/u02/backups/12c/backupset/LAB12C_full_1830920858-10-0a1ji4sv_1_1.bak tag=DB_FULL_CF comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:05
channel ORA_DISK_1: starting compressed incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00010 name=/u01/app/oracle/oradata/lab12c/prod/sysaux01.dbf
input datafile file number=00009 name=/u01/app/oracle/oradata/lab12c/prod/system01.dbf
input datafile file number=00011 name=/u01/app/oracle/oradata/lab12c/prod/undotbs01.dbf
input datafile file number=00012 name=/u01/app/oracle/oradata/lab12c/prod/users01.dbf
channel ORA_DISK_1: starting piece 1 at 03-FEB-23
channel ORA_DISK_1: finished piece 1 at 03-FEB-23
piece handle=/u02/backups/12c/backupset/LAB12C_full_1830920858-11-0b1ji4v1_1_1.bak tag=DB_FULL_CF comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting compressed incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/u01/app/oracle/oradata/lab12c/pdbseed/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/lab12c/pdbseed/system01.dbf
input datafile file number=00008 name=/u01/app/oracle/oradata/lab12c/pdbseed/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 03-FEB-23
channel ORA_DISK_1: finished piece 1 at 03-FEB-23
piece handle=/u02/backups/12c/backupset/LAB12C_full_1830920858-12-0c1ji50e_1_1.bak tag=DB_FULL_CF comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting compressed incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 03-FEB-23
channel ORA_DISK_1: finished piece 1 at 03-FEB-23
piece handle=/u02/backups/12c/backupset/LAB12C_full_1830920858-13-0d1ji51r_1_1.bak tag=DB_FULL_CF comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 03-FEB-23

Starting backup at 03-FEB-23
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=18 RECID=13 STAMP=1127814207
channel ORA_DISK_1: starting piece 1 at 03-FEB-23
channel ORA_DISK_1: finished piece 1 at 03-FEB-23
piece handle=/u02/backups/12c/backupset/LAB12C_full_1830920858-14-0e1ji520_1_1.bak tag=ARC_FULL_CF comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 03-FEB-23

Starting backup at 03-FEB-23
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 03-FEB-23
channel ORA_DISK_1: finished piece 1 at 03-FEB-23
piece handle=/u02/backups/12c/backupset/LAB12C_full_1830920858-15-0f1ji521_1_1.bak tag=CF_CURRENT_FULL comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 03-FEB-23

Starting Control File and SPFILE Autobackup at 03-FEB-23
piece handle=/u02/backups/12c/backupset/c-1830920858-20230203-00 comment=NONE
Finished Control File and SPFILE Autobackup at 03-FEB-23

sql statement: alter system switch logfile

Listando arquivos de backups gerados:

[oracle@srv01 logs]$ ls -lat /u02/backups/12c/backupset
total 1062692
-rw-r----- 1 oracle oinstall  18825216 Feb  3 10:12 c-1830920858-20230203-01
drwxr-xr-x 1 oracle oinstall      1172 Feb  3 10:12 .
-rw-r----- 1 oracle oinstall  34348544 Feb  3 10:12 LAB12C_arc_1830920858-17-0h1ji6ov_1_1.bak
-rw-r----- 1 oracle oinstall  18825216 Feb  3 09:43 c-1830920858-20230203-00
-rw-r----- 1 oracle oinstall  18792448 Feb  3 09:43 LAB12C_full_1830920858-15-0f1ji521_1_1.bak
-rw-r----- 1 oracle oinstall     22016 Feb  3 09:43 LAB12C_full_1830920858-14-0e1ji520_1_1.bak
-rw-r----- 1 oracle oinstall   1114112 Feb  3 09:43 LAB12C_full_1830920858-13-0d1ji51r_1_1.bak
-rw-r----- 1 oracle oinstall 267657216 Feb  3 09:43 LAB12C_full_1830920858-12-0c1ji50e_1_1.bak
-rw-r----- 1 oracle oinstall 269115392 Feb  3 09:42 LAB12C_full_1830920858-11-0b1ji4v1_1_1.bak
-rw-r----- 1 oracle oinstall 425984000 Feb  3 09:41 LAB12C_full_1830920858-10-0a1ji4sv_1_1.bak
-rw-r----- 1 oracle oinstall   7196672 Feb  3 09:40 LAB12C_full_1830920858-9-091ji4su_1_1.bak
-rw-r--r-- 1 oracle oinstall      1255 Feb  3 09:40 initlab12c.ora

Init do banco de origem lab12c que irei usar no duplicate como modelo:

[oracle@srv01 backupset]$ strings initlab12c.ora
lab12c.__data_transfer_cache_size=0
lab12c.__db_cache_size=1744830464
lab12c.__inmemory_ext_roarea=0
lab12c.__inmemory_ext_rwarea=0
lab12c.__java_pool_size=16777216
lab12c.__large_pool_size=33554432
lab12c.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
lab12c.__pga_aggregate_target=805306368
lab12c.__sga_target=2415919104
lab12c.__shared_io_pool_size=117440512
lab12c.__shared_pool_size=486539264
lab12c.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/lab12c/adump'
*.audit_trail='db'
*.compatible='12.2.0'
*.control_files='/u01/app/oracle/oradata/lab12c/control01.ctl','/u01/app/oracle/recovery_area/lab12c/control02.ctl'
*.db_block_size=8192
*.db_name='lab12c' 
*.db_recovery_file_dest='/u01/app/oracle/recovery_area'
*.db_recovery_file_dest_size=12780m
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=lab12cXDB)'
*.enable_pluggable_database=true
*.local_listener='LISTENER_LAB12C'
*.log_archive_dest_1='LOCATION=/u02/backups/12c/archivelog/ MANDATORY'
*.log_archive_format='%t_%s_%r.arc'
*.nls_language='AMERICAN'
*.nls_territory='AMERICA'
*.open_cursors=300
*.pga_aggregate_target=767m
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=2299m
*.undo_tablespace='UNDOTBS1'

Init ajustado para usar o duplicate na criação do banco hml:

[oracle@srv01 backupset]$ cat initlab12c_hml.ora
hml.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
*.audit_file_dest='/u01/app/oracle/admin/hml/adump'
*.audit_trail='db'
*.compatible='12.2.0'
*.control_files='/u01/app/oracle/oradata/hml/control01.ctl','/u01/app/oracle/recovery_area/hml/control02.ctl'
*.db_block_size=8192
*.db_name='hml' <==============================
*.db_recovery_file_dest='/u01/app/oracle/recovery_area'
*.db_recovery_file_dest_size=12780m
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=lab12cXDB)'
*.enable_pluggable_database=true
*.log_archive_dest_1='LOCATION=/u02/backups/hml/archivelog/ MANDATORY'
*.log_archive_format='%t_%s_%r.arc'
*.nls_language='AMERICAN'
*.nls_territory='AMERICA'
*.open_cursors=300
*.pga_aggregate_target=767m
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=2299m
*.undo_tablespace='UNDOTBS1'
# CONVERTENDO OS DIRETORIOS DOS DATAFILES DA ORIGEM PARA O NOVO DESTINO
*.db_file_name_convert='/u01/app/oracle/oradata/lab12c/','/u01/app/oracle/oradata/hml/'
*.log_file_name_convert='/u01/app/oracle/oradata/lab12c/','/u01/app/oracle/oradata/hml/'

Criando os diretórios necessários para o banco hml.

[oracle@srv01 ]$ mkdir -p /u01/app/oracle/admin/hml/adump
[oracle@srv01 ]$ mkdir -p /u01/app/oracle/oradata/hml/
[oracle@srv01 ]$ mkdir -p /u01/app/oracle/recovery_area/hml/
[oracle@srv01 ]$ mkdir -p /u02/backups/hml/archivelog/

Iniciando o banco hml com o init criado em nomount:

[oracle@srv01 oradata]$ export ORACLE_SID=hml
[oracle@srv01 oradata]$ sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Fri Feb 3 09:56:25 2023

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup nomount pfile='/u02/backups/12c/scripts/initlab12c_hml.ora';
ORACLE instance started.

Total System Global Area 2415919104 bytes
Fixed Size                  8795616 bytes
Variable Size             654314016 bytes
Database Buffers         1744830464 bytes
Redo Buffers                7979008 bytes
SQL>
[oracle@srv01 scripts]$ ps aux | grep smon
oracle   24649  0.0  0.7 2797700 58572 ?       Ss   09:56   0:00 ora_smon_hml

Duplicando o database informando uma data e horário especifico:

[oracle@srv01 oradata]$ export NLS_DATE_FORMAT='DD/MM/YYYY HH24:MI:SS'
rman auxiliary / msglog /u02/backups/12c/logs/clonando_base_$HOJE.spool << EOF
RUN
{
set until time "to_date('03/02/2023 10:10:00','DD/MM/YYYY HH24:MI:SS')";
allocate auxiliary channel c1  type disk ;
duplicate target database to hml backup location='/u02/backups/12c/backupset';
}
EOF
[oracle@srv01 logs]$ cat clonando_base_20230203.spool

Recovery Manager: Release 12.2.0.1.0 - Production on Fri Feb 3 10:21:22 2023

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

connected to auxiliary database: HML (not mounted)

RMAN> 2> 3> 4> 5> 6> 7>
executing command: SET until clause

allocated channel: c1
channel c1: SID=237 device type=DISK

Starting Duplicate Db at 03/02/2023 10:21:23

contents of Memory Script:
{
   sql clone "create spfile from memory";
}
executing Memory Script

sql statement: create spfile from memory

contents of Memory Script:
{
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area    2415919104 bytes

Fixed Size                     8795616 bytes
Variable Size                654314016 bytes
Database Buffers            1744830464 bytes
Redo Buffers                   7979008 bytes
allocated channel: c1
channel c1: SID=237 device type=DISK

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''LAB12C'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name =
 ''hml'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone primary controlfile from  '/u02/backups/12c/backupset/c-1830920858-20230203-00';
   alter clone database mount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''LAB12C'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set  db_unique_name =  ''hml'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area    2415919104 bytes

Fixed Size                     8795616 bytes
Variable Size                654314016 bytes
Database Buffers            1744830464 bytes
Redo Buffers                   7979008 bytes
allocated channel: c1
channel c1: SID=255 device type=DISK

Starting restore at 03/02/2023 10:22:08

channel c1: restoring control file
channel c1: restore complete, elapsed time: 00:00:03
output file name=/u01/app/oracle/oradata/hml/control01.ctl
output file name=/u01/app/oracle/recovery_area/hml/control02.ctl
Finished restore at 03/02/2023 10:22:11

database mounted

contents of Memory Script:
{
   set until scn  1985379;
   set newname for datafile  1 to
 "/u01/app/oracle/oradata/hml/system01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/oradata/hml/sysaux01.dbf";
   set newname for datafile  4 to
 "/u01/app/oracle/oradata/hml/undotbs01.dbf";
   set newname for datafile  5 to
 "/u01/app/oracle/oradata/hml/pdbseed/system01.dbf";
   set newname for datafile  6 to
 "/u01/app/oracle/oradata/hml/pdbseed/sysaux01.dbf";
   set newname for datafile  7 to
 "/u01/app/oracle/oradata/hml/users01.dbf";
   set newname for datafile  8 to
 "/u01/app/oracle/oradata/hml/pdbseed/undotbs01.dbf";
   set newname for datafile  9 to
 "/u01/app/oracle/oradata/hml/prod/system01.dbf";
   set newname for datafile  10 to
 "/u01/app/oracle/oradata/hml/prod/sysaux01.dbf";
   set newname for datafile  11 to
 "/u01/app/oracle/oradata/hml/prod/undotbs01.dbf";
   set newname for datafile  12 to
 "/u01/app/oracle/oradata/hml/prod/users01.dbf";
   restore
   clone database
   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 03/02/2023 10:22:17

channel c1: starting datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
channel c1: restoring datafile 00001 to /u01/app/oracle/oradata/hml/system01.dbf
channel c1: restoring datafile 00003 to /u01/app/oracle/oradata/hml/sysaux01.dbf
channel c1: restoring datafile 00004 to /u01/app/oracle/oradata/hml/undotbs01.dbf
channel c1: restoring datafile 00007 to /u01/app/oracle/oradata/hml/users01.dbf
channel c1: reading from backup piece /u02/backups/12c/backupset/LAB12C_full_1830920858-10-0a1ji4sv_1_1.bak
channel c1: piece handle=/u02/backups/12c/backupset/LAB12C_full_1830920858-10-0a1ji4sv_1_1.bak tag=DB_FULL_CF
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:01:15
channel c1: starting datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
channel c1: restoring datafile 00005 to /u01/app/oracle/oradata/hml/pdbseed/system01.dbf
channel c1: restoring datafile 00006 to /u01/app/oracle/oradata/hml/pdbseed/sysaux01.dbf
channel c1: restoring datafile 00008 to /u01/app/oracle/oradata/hml/pdbseed/undotbs01.dbf
channel c1: reading from backup piece /u02/backups/12c/backupset/LAB12C_full_1830920858-12-0c1ji50e_1_1.bak
channel c1: piece handle=/u02/backups/12c/backupset/LAB12C_full_1830920858-12-0c1ji50e_1_1.bak tag=DB_FULL_CF
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:55
channel c1: starting datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
channel c1: restoring datafile 00009 to /u01/app/oracle/oradata/hml/prod/system01.dbf
channel c1: restoring datafile 00010 to /u01/app/oracle/oradata/hml/prod/sysaux01.dbf
channel c1: restoring datafile 00011 to /u01/app/oracle/oradata/hml/prod/undotbs01.dbf
channel c1: restoring datafile 00012 to /u01/app/oracle/oradata/hml/prod/users01.dbf
channel c1: reading from backup piece /u02/backups/12c/backupset/LAB12C_full_1830920858-11-0b1ji4v1_1_1.bak
channel c1: piece handle=/u02/backups/12c/backupset/LAB12C_full_1830920858-11-0b1ji4v1_1_1.bak tag=DB_FULL_CF
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:55
Finished restore at 03/02/2023 10:25:23

contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy RECID=12 STAMP=1127816723 file name=/u01/app/oracle/oradata/hml/system01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=13 STAMP=1127816723 file name=/u01/app/oracle/oradata/hml/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=14 STAMP=1127816724 file name=/u01/app/oracle/oradata/hml/undotbs01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=15 STAMP=1127816724 file name=/u01/app/oracle/oradata/hml/pdbseed/system01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=16 STAMP=1127816724 file name=/u01/app/oracle/oradata/hml/pdbseed/sysaux01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=17 STAMP=1127816724 file name=/u01/app/oracle/oradata/hml/users01.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=18 STAMP=1127816724 file name=/u01/app/oracle/oradata/hml/pdbseed/undotbs01.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=19 STAMP=1127816724 file name=/u01/app/oracle/oradata/hml/prod/system01.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=20 STAMP=1127816724 file name=/u01/app/oracle/oradata/hml/prod/sysaux01.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=21 STAMP=1127816724 file name=/u01/app/oracle/oradata/hml/prod/undotbs01.dbf
datafile 12 switched to datafile copy
input datafile copy RECID=22 STAMP=1127816725 file name=/u01/app/oracle/oradata/hml/prod/users01.dbf

contents of Memory Script:
{
   set until time  "to_date('FEB 03 2023 10:10:00', 'MON DD YYYY HH24:MI:SS')";
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 03/02/2023 10:25:26

starting media recovery

archived log for thread 1 with sequence 18 is already on disk as file /u02/backups/12c/backupset/1_18_1090420830.arc
archived log for thread 1 with sequence 19 is already on disk as file /u02/backups/12c/backupset/1_19_1090420830.arc
archived log file name=/u02/backups/12c/backupset/1_18_1090420830.arc thread=1 sequence=18
archived log file name=/u02/backups/12c/backupset/1_19_1090420830.arc thread=1 sequence=19
channel c1: starting archived log restore to default destination
channel c1: restoring archived log
archived log thread=1 sequence=20
channel c1: restoring archived log
archived log thread=1 sequence=21
channel c1: reading from backup piece /u02/backups/12c/backupset/LAB12C_arc_1830920858-17-0h1ji6ov_1_1.bak
channel c1: piece handle=/u02/backups/12c/backupset/LAB12C_arc_1830920858-17-0h1ji6ov_1_1.bak tag=ARC_$HOJE
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:01
archived log file name=/u02/backups/hml/archivelog/1_20_1090420830.arc thread=1 sequence=20
channel clone_default: deleting archived log(s)
archived log file name=/u02/backups/hml/archivelog/1_20_1090420830.arc RECID=11 STAMP=1127816727
archived log file name=/u02/backups/hml/archivelog/1_21_1090420830.arc thread=1 sequence=21
channel clone_default: deleting archived log(s)
archived log file name=/u02/backups/hml/archivelog/1_21_1090420830.arc RECID=12 STAMP=1127816727
media recovery complete, elapsed time: 00:00:03
Finished recover at 03/02/2023 10:25:31
released channel: c1
Oracle instance started

Total System Global Area    2415919104 bytes

Fixed Size                     8795616 bytes
Variable Size                654314016 bytes
Database Buffers            1744830464 bytes
Redo Buffers                   7979008 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''HML'' comment=
 ''Reset to original value by RMAN'' scope=spfile";
   sql clone "alter system reset  db_unique_name scope=spfile";
}
executing Memory Script

sql statement: alter system set  db_name =  ''HML'' comment= ''Reset to original value by RMAN'' scope=spfile

sql statement: alter system reset  db_unique_name scope=spfile
Oracle instance started

Total System Global Area    2415919104 bytes

Fixed Size                     8795616 bytes
Variable Size                654314016 bytes
Database Buffers            1744830464 bytes
Redo Buffers                   7979008 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "HML" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES     1024
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP   1 ( '/u01/app/oracle/oradata/hml/redo01.log' ) SIZE 200 M  REUSE,
  GROUP   2 ( '/u01/app/oracle/oradata/hml/redo02.log' ) SIZE 200 M  REUSE,
  GROUP   3 ( '/u01/app/oracle/oradata/hml/redo03.log' ) SIZE 200 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/hml/system01.dbf',
  '/u01/app/oracle/oradata/hml/pdbseed/system01.dbf',
  '/u01/app/oracle/oradata/hml/prod/system01.dbf'
 CHARACTER SET AL32UTF8


contents of Memory Script:
{
   set newname for tempfile  1 to
 "/u01/app/oracle/oradata/hml/temp01.dbf";
   set newname for tempfile  2 to
 "/u01/app/oracle/oradata/hml/pdbseed/temp012021-12-04_14-41-29-982-PM.dbf";
   set newname for tempfile  3 to
 "/u01/app/oracle/oradata/hml/prod/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/oradata/hml/sysaux01.dbf",
 "/u01/app/oracle/oradata/hml/undotbs01.dbf",
 "/u01/app/oracle/oradata/hml/pdbseed/sysaux01.dbf",
 "/u01/app/oracle/oradata/hml/users01.dbf",
 "/u01/app/oracle/oradata/hml/pdbseed/undotbs01.dbf",
 "/u01/app/oracle/oradata/hml/prod/sysaux01.dbf",
 "/u01/app/oracle/oradata/hml/prod/undotbs01.dbf",
 "/u01/app/oracle/oradata/hml/prod/users01.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata/hml/temp01.dbf in control file
renamed tempfile 2 to /u01/app/oracle/oradata/hml/pdbseed/temp012021-12-04_14-41-29-982-PM.dbf in control file
renamed tempfile 3 to /u01/app/oracle/oradata/hml/prod/temp01.dbf in control file

cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/hml/sysaux01.dbf RECID=1 STAMP=1127816774
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/hml/undotbs01.dbf RECID=2 STAMP=1127816774
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/hml/pdbseed/sysaux01.dbf RECID=3 STAMP=1127816774
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/hml/users01.dbf RECID=4 STAMP=1127816775
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/hml/pdbseed/undotbs01.dbf RECID=5 STAMP=1127816775
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/hml/prod/sysaux01.dbf RECID=6 STAMP=1127816775
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/hml/prod/undotbs01.dbf RECID=7 STAMP=1127816775
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/hml/prod/users01.dbf RECID=8 STAMP=1127816775

datafile 3 switched to datafile copy
input datafile copy RECID=1 STAMP=1127816774 file name=/u01/app/oracle/oradata/hml/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=2 STAMP=1127816774 file name=/u01/app/oracle/oradata/hml/undotbs01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=3 STAMP=1127816774 file name=/u01/app/oracle/oradata/hml/pdbseed/sysaux01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=4 STAMP=1127816775 file name=/u01/app/oracle/oradata/hml/users01.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=5 STAMP=1127816775 file name=/u01/app/oracle/oradata/hml/pdbseed/undotbs01.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=6 STAMP=1127816775 file name=/u01/app/oracle/oradata/hml/prod/sysaux01.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=7 STAMP=1127816775 file name=/u01/app/oracle/oradata/hml/prod/undotbs01.dbf
datafile 12 switched to datafile copy
input datafile copy RECID=8 STAMP=1127816775 file name=/u01/app/oracle/oradata/hml/prod/users01.dbf

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened

contents of Memory Script:
{
   sql clone "alter pluggable database all open";
}
executing Memory Script

sql statement: alter pluggable database all open
Finished Duplicate Db at 03/02/2023 10:26:43

Database hml disponível para uso:

set lines 200
col DATABASE_HOST for a25;
col DB_UNIQUE_NAME for a25
col HOST_NAME for a15;
col DATABASE_ROLE for a10
col OPEN_MODE for a10
col STARTUP_TIME for a20
alter session set nls_date_format = 'DD/MM/YYYY HH24:MI:SS';
SELECT i.HOST_NAME "DATABASE_HOST" ,
i.INSTANCE_NAME "DB_NAME",
d.db_unique_name "DB_UNIQUE_NAME" , 
d.DATABASE_ROLE " DATABASE_ROLE",
i.VERSION,
d.OPEN_MODE " OPEN_MODE ",
d.LOG_MODE
,STARTUP_TIME 
from GV$DATABASE d, gv$instance i 
where i.INST_ID=d.INST_ID;
DATABASE_HOST             DB_NAME          DB_UNIQUE_NAME             DATABASE_ROLE   VERSION            OPEN_MODE           LOG_MODE     STARTUP_TIME
------------------------- ---------------- ------------------------- ---------------- ----------------- -------------------- ------------ --------------------
srv01                     hml              HML                       PRIMARY          12.2.0.1.0        READ WRITE           ARCHIVELOG   03/02/2023 10:25:58

Para atualizar os ambientes de desenvolvimento ou homologação, utilizo o horário dinâmico no duplicate, ele irá duplicar a base até 30 minutos antes do horário corrente.
Por exemplo, se executar o script as 10h, ele irá criar a base com recover até 09h30.

[oracle@srv01 oradata]$ export NLS_DATE_FORMAT='DD/MM/YYYY HH24:MI:SS'
rman auxiliary / msglog /u02/backups/12c/logs/clonando_base_$HOJE.spool << EOF
RUN
{
set until time "sysdate - 30/(24*60)";
allocate auxiliary channel c1  type disk ;
duplicate target database to hml backup location='/u02/backups/12c/backupset';
}
EOF

Link da documentação:

Database Backup and Recovery Reference
https://docs.oracle.com/database/121/RCMRF/rcmsynta020.htm#RCMRF126

Leave a Reply

Your email address will not be published. Required fields are marked *

search previous next tag category expand menu location phone mail time cart zoom edit close