Disclaimer

Saturday, 23 November 2024

How to duplicate database using RMAN Backup Set | from Different location

 

Though we can the active duplication method, to clone a database from live running database. But sometime we may need to clone a database from a RMAN backup set. Below example will cover the steps for that.



STEPS: OEMDB (RAC201) to SAMDB (RAC202) Cloning


1. Take full rman backup from Source DB:-

If you already have any existing latest valid full backup, then you can use that instead of taking fresh backup.


RMAN> backup database plus archivelog;

Starting backup at 23-NOV-24
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=77 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=10 RECID=2 STAMP=1185809341
input archived log thread=1 sequence=11 RECID=1 STAMP=1185809325
input archived log thread=1 sequence=12 RECID=3 STAMP=1185809342
input archived log thread=1 sequence=13 RECID=4 STAMP=1185809345
input archived log thread=1 sequence=14 RECID=5 STAMP=1185809347
input archived log thread=1 sequence=15 RECID=6 STAMP=1185809459
input archived log thread=1 sequence=16 RECID=7 STAMP=1185809625
input archived log thread=1 sequence=17 RECID=8 STAMP=1185809887
input archived log thread=1 sequence=18 RECID=9 STAMP=1185809916
input archived log thread=1 sequence=19 RECID=10 STAMP=1185810951
channel ORA_DISK_1: starting piece 1 at 23-NOV-24
channel ORA_DISK_1: finished piece 1 at 23-NOV-24
piece handle=/data1/OEMDB_RMAN_BKP/0q3as2g8_26_1_1 tag=TAG20241123T155551 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 23-NOV-24

Starting backup at 23-NOV-24
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/data2/OEMDB/system01.dbf
input datafile file number=00003 name=/data2/OEMDB/sysaux01.dbf
input datafile file number=00004 name=/data2/OEMDB/undotbs01.dbf
input datafile file number=00007 name=/data2/OEMDB/users01.dbf
channel ORA_DISK_1: starting piece 1 at 23-NOV-24
channel ORA_DISK_1: finished piece 1 at 23-NOV-24
piece handle=/data1/OEMDB_RMAN_BKP/0r3as2g9_27_1_1 tag=TAG20241123T155553 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 23-NOV-24

Starting backup at 23-NOV-24
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=20 RECID=11 STAMP=1185810960
channel ORA_DISK_1: starting piece 1 at 23-NOV-24
channel ORA_DISK_1: finished piece 1 at 23-NOV-24
piece handle=/data1/OEMDB_RMAN_BKP/0s3as2gh_28_1_1 tag=TAG20241123T155601 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 23-NOV-24

Starting Control File and SPFILE Autobackup at 23-NOV-24
piece handle=/data1/OEMDB_RMAN_BKP/c-853306698-20241123-04 comment=NONE
Finished Control File and SPFILE Autobackup at 23-NOV-24

RMAN> list backup;


List of Backup Sets
===================


BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
26      201.00M    DISK        00:00:00     23-NOV-24
        BP Key: 26   Status: AVAILABLE  Compressed: NO  Tag: TAG20241123T155551
        Piece Name: /data1/OEMDB_RMAN_BKP/0q3as2g8_26_1_1

  List of Archived Logs in backup set 26
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    10      2138103    14-NOV-24 2177535    23-NOV-24
  1    11      2177535    23-NOV-24 2177548    23-NOV-24
  1    12      2177548    23-NOV-24 2177583    23-NOV-24
  1    13      2177583    23-NOV-24 2178241    23-NOV-24
  1    14      2178241    23-NOV-24 2178250    23-NOV-24
  1    15      2178250    23-NOV-24 2178319    23-NOV-24
  1    16      2178319    23-NOV-24 2178701    23-NOV-24
  1    17      2178701    23-NOV-24 2179098    23-NOV-24
  1    18      2179098    23-NOV-24 2179151    23-NOV-24
  1    19      2179151    23-NOV-24 2180272    23-NOV-24

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
27      Full    1.52G      DISK        00:00:05     23-NOV-24
        BP Key: 27   Status: AVAILABLE  Compressed: NO  Tag: TAG20241123T155553
        Piece Name: /data1/OEMDB_RMAN_BKP/0r3as2g9_27_1_1
  List of Datafiles in backup set 27
  File LV Type Ckp SCN    Ckp Time  Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- --------- ----------- ------ ----
  1       Full 2180290    23-NOV-24              NO    /data2/OEMDB/system01.dbf
  3       Full 2180290    23-NOV-24              NO    /data2/OEMDB/sysaux01.dbf
  4       Full 2180290    23-NOV-24              NO    /data2/OEMDB/undotbs01.dbf
  7       Full 2180290    23-NOV-24              NO    /data2/OEMDB/users01.dbf

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
28      4.00K      DISK        00:00:00     23-NOV-24
        BP Key: 28   Status: AVAILABLE  Compressed: NO  Tag: TAG20241123T155601
        Piece Name: /data1/OEMDB_RMAN_BKP/0s3as2gh_28_1_1

  List of Archived Logs in backup set 28
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    20      2180272    23-NOV-24 2180299    23-NOV-24

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
29      Full    10.20M     DISK        00:00:00     23-NOV-24
        BP Key: 29   Status: AVAILABLE  Compressed: NO  Tag: TAG20241123T155602
        Piece Name: /data1/OEMDB_RMAN_BKP/c-853306698-20241123-04
  SPFILE Included: Modification time: 23-NOV-24
  SPFILE db_unique_name: OEMDB
  Control File Included: Ckp SCN: 2180315      Ckp time: 23-NOV-24

RMAN>

RMAN> crosscheck backup;

using channel ORA_DISK_1
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/OEMDB_RMAN_BKP/0q3as2g8_26_1_1 RECID=26 STAMP=1185810952
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/OEMDB_RMAN_BKP/0r3as2g9_27_1_1 RECID=27 STAMP=1185810953
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/OEMDB_RMAN_BKP/0s3as2gh_28_1_1 RECID=28 STAMP=1185810961
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/OEMDB_RMAN_BKP/c-853306698-20241123-04 RECID=29 STAMP=1185810962
Crosschecked 4 objects


2. Copy the backup pieces to the target host:If you are duplicating the database on a different host, then copy the backup pieces target  host.

[oracle@rac201 OEMDB_RMAN_BKP]$ ls -lrt
total 1817748
-rw-r-----. 1 oracle oinstall  210763264 Nov 23 15:55 0q3as2g8_26_1_1
-rw-r-----. 1 oracle oinstall 1629282304 Nov 23 15:55 0r3as2g9_27_1_1
-rw-r-----. 1 oracle oinstall       4608 Nov 23 15:56 0s3as2gh_28_1_1
-rw-r-----. 1 oracle oinstall   10600448 Nov 23 15:56 snapcf_OEMDBP.f
-rw-r-----. 1 oracle oinstall   10715136 Nov 23 15:56 c-853306698-20241123-04

[oracle@rac201 OEMDB_RMAN_BKP ]$ scp * oracle@192.168.0.202:/data1/OEMDB_RMAN_BKP
Mount the /data1/OEMDB_RMAN_BKP - Mount point on rac202 sever (192.168.0.202)



3. Prepare pfile for the new DB (SAMDB- RAC202):

[oracle@rac202 dbs]$ cat initSAMDB.ora
*._allow_insert_with_update_check=TRUE
*.audit_file_dest='/u01/app/oracle/oracle_base/admin/SAMDB/adump'
*.audit_trail='db'
*.compatible='19.0.0'
*.control_files='/data2/SAMDB/control01.ctl','/data2/SAMDB/control02.ctl'
*.db_block_size=8192
*.db_name='SAMDB'
*.diagnostic_dest='/u01/app/oracle/oracle_base'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=SAMDBXDB)'
*.log_archive_dest='/data2/SAMDB/arch'
*.nls_language='AMERICAN'
*.nls_territory='AMERICA'
*.open_cursors=300
*.pga_aggregate_target=770m
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=2308m
*.undo_tablespace='UNDOTBS1'
*.db_file_name_convert='/data2/OEMDB','/data2/SAMDB'
*.log_file_name_convert='/data2/OEMDB','/data2/SAMDB'



4. Create required directory structure for SAMDB


mkdir -p /u01/app/oracle/oracle_base/admin/SAMDB/adump
mkdir -p /data2/SAMDB
mkdir -p /data2/SAMDB/arch



5. Start the database in (Nomount)  stage - SAMDB:


[oracle@rac202 admin]$ cd SAMDB
[oracle@rac202 SAMDB]$ mkdir adump
[oracle@rac202 SAMDB]$
[oracle@rac202 SAMDB]$ sqlplus '/as sysdba'

SQL*Plus: Release 19.0.0.0.0 - Production on Sat Nov 23 16:51:14 2024
Version 19.21.0.0.0

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

Connected to an idle instance.

SQL> startup nomount;
ORACLE instance started.

Total System Global Area 2432695120 bytes
Fixed Size                  8928080 bytes
Variable Size             536870912 bytes
Database Buffers         1879048192 bytes
Redo Buffers                7847936 bytes




6. Run duplicate command by connecting auxiliary instance :-

 

[oracle@rac202 dbs]$ rman auxiliary /

SYNTAX – > DUPLICATE DATABASE TO <DB_NEW_NAME> BACKUP LOCATION ‘<<BACKUP_LOC>’ NOFILENAMECHECK;

[oracle@rac202 dbs]$ rman auxiliary /

Recovery Manager: Release 19.0.0.0.0 - Production on Sat Nov 23 17:17:33 2024
Version 19.21.0.0.0

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

connected to auxiliary database: SAMDB (not mounted)

RMAN> DUPLICATE DATABASE TO SAMDB BACKUP LOCATION '/data1/OEMDB_RMAN_BKP/' NOFILENAMECHECK;

Starting Duplicate Db at 23-NOV-24
searching for database ID
found backup of database ID 853306698

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    2432695120 bytes

Fixed Size                     8928080 bytes
Variable Size                536870912 bytes
Database Buffers            1879048192 bytes
Redo Buffers                   7847936 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''OEMDB'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name =
 ''SAMDB'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone primary controlfile from  '/data1/OEMDB_RMAN_BKP/c-853306698-20241123-04';
   alter clone database mount;
}
executing Memory Script

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

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

Oracle instance shut down

Oracle instance started

Total System Global Area    2432695120 bytes

Fixed Size                     8928080 bytes
Variable Size                536870912 bytes
Database Buffers            1879048192 bytes
Redo Buffers                   7847936 bytes

Starting restore at 23-NOV-24
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=37 device type=DISK

channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/data2/SAMDB/control01.ctl
output file name=/data2/SAMDB/control02.ctl
Finished restore at 23-NOV-24

database mounted
released channel: ORA_AUX_DISK_1
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=37 device type=DISK

contents of Memory Script:
{
   set until scn  2180299;
   set newname for datafile  1 to
 "/data2/SAMDB/system01.dbf";
   set newname for datafile  3 to
 "/data2/SAMDB/sysaux01.dbf";
   set newname for datafile  4 to
 "/data2/SAMDB/undotbs01.dbf";
   set newname for datafile  7 to
 "/data2/SAMDB/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

Starting restore at 23-NOV-24
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /data2/SAMDB/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /data2/SAMDB/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /data2/SAMDB/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00007 to /data2/SAMDB/users01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /data1/OEMDB_RMAN_BKP/0r3as2g9_27_1_1
channel ORA_AUX_DISK_1: piece handle=/data1/OEMDB_RMAN_BKP/0r3as2g9_27_1_1 tag=TAG20241123T155553
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 23-NOV-24

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

datafile 1 switched to datafile copy
input datafile copy RECID=6 STAMP=1185816005 file name=/data2/SAMDB/system01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=7 STAMP=1185816005 file name=/data2/SAMDB/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=1185816005 file name=/data2/SAMDB/undotbs01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=9 STAMP=1185816005 file name=/data2/SAMDB/users01.dbf

contents of Memory Script:
{
   set until scn  2180299;
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 23-NOV-24
using channel ORA_AUX_DISK_1

starting media recovery

channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=20
channel ORA_AUX_DISK_1: reading from backup piece /data1/OEMDB_RMAN_BKP/0s3as2gh_28_1_1
channel ORA_AUX_DISK_1: piece handle=/data1/OEMDB_RMAN_BKP/0s3as2gh_28_1_1 tag=TAG20241123T155601
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/data2/SAMDB/arch1_20_1185046732.dbf thread=1 sequence=20
channel clone_default: deleting archived log(s)
archived log file name=/data2/SAMDB/arch1_20_1185046732.dbf RECID=1 STAMP=1185816006
media recovery complete, elapsed time: 00:00:00
Finished recover at 23-NOV-24
Oracle instance started

Total System Global Area    2432695120 bytes

Fixed Size                     8928080 bytes
Variable Size                536870912 bytes
Database Buffers            1879048192 bytes
Redo Buffers                   7847936 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''SAMDB'' 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 =  ''SAMDB'' 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    2432695120 bytes

Fixed Size                     8928080 bytes
Variable Size                536870912 bytes
Database Buffers            1879048192 bytes
Redo Buffers                   7847936 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "SAMDB" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP     1 ( '/data2/SAMDB/redo01.log' ) SIZE 200 M  REUSE,
  GROUP     2 ( '/data2/SAMDB/redo02.log' ) SIZE 200 M  REUSE,
  GROUP     3 ( '/data2/SAMDB/redo03.log' ) SIZE 200 M  REUSE
 DATAFILE
  '/data2/SAMDB/system01.dbf'
 CHARACTER SET AL32UTF8


contents of Memory Script:
{
   set newname for tempfile  1 to
 "/data2/SAMDB/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/data2/SAMDB/sysaux01.dbf",
 "/data2/SAMDB/undotbs01.dbf",
 "/data2/SAMDB/users01.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /data2/SAMDB/temp01.dbf in control file

cataloged datafile copy
datafile copy file name=/data2/SAMDB/sysaux01.dbf RECID=1 STAMP=1185816046
cataloged datafile copy
datafile copy file name=/data2/SAMDB/undotbs01.dbf RECID=2 STAMP=1185816046
cataloged datafile copy
datafile copy file name=/data2/SAMDB/users01.dbf RECID=3 STAMP=1185816046

datafile 3 switched to datafile copy
input datafile copy RECID=1 STAMP=1185816046 file name=/data2/SAMDB/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=2 STAMP=1185816046 file name=/data2/SAMDB/undotbs01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=3 STAMP=1185816046 file name=/data2/SAMDB/users01.dbf

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

database opened
Cannot remove created server parameter file
Finished Duplicate Db at 23-NOV-24

RMAN>




7. Check the status of the database :-


[oracle@rac202 dbs]$ sqlplus '/as sysdba'

SQL*Plus: Release 19.0.0.0.0 - Production on Sat Nov 23 18:08:09 2024
Version 19.21.0.0.0

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


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.21.0.0.0

SQL> select name,open_mode from v$database;

NAME      OPEN_MODE
--------- -----------
SAMDB     READ WRITE














No comments:

Post a Comment

How to recovery PDB when PDB database is dropped in Oracle

  How to recovery PDB when PDB database is dropped :) [oracle@rac01 ~]$ sqlplus '/as sysdba' SQL*Plus: Release 21.0.0.0.0 - Product...