Wednesday 17 January 2018

Restore RMAN backup to Different Server with Same Database Name in 12c Database


Restore RMAN backup to Different Server with Same Database Name


RMAN Restoration to New Server with Same Database Name and Same Directory

Pre-requisite:

On Target  host , Same version of 12C Database Binary should be installed

You may need to restore a database to a new server due to the following reasons:

1) confirming your disaster recovery strategy
2) moving the database to a new server

The steps can be summarized as:

1) Take a backup of the database on the existing host
2) Create Parameter file and transferred to destination and make necessary changes in parameter file as per target host 
3) on the new host, restore the controlfiles, datafiles and tempfiles 

Source database CDB3 is residing on host01 server and need to be restored it on host02

login as: oracle
oracle@9.118.255.254's password:
Last login: Mon Feb 29 08:34:12 2016 from 9.124.210.138

Take RMAN Full backup for source database including archive log on below location.

[oracle@host01 db01]$ cd backup
[oracle@host01 backup]$ pwd
/u01/ora/db01/backup
[oracle@host01 backup]$
[oracle@host01 backup]$
[oracle@host01 backup]$ ps -ef|grep pmon
oracle   18424 18153  0 08:49 pts/1    00:00:00 grep pmon
oracle   32412     1  0 Feb28 ?        00:00:01 ora_pmon_CDB3
[oracle@host01 ~]$ export ORACLE_SID=CDB3
[oracle@host01 ~]$
[oracle@host01 backup]$ echo $ORACLE_SID
CDB3
[oracle@host01 backup]$ rman

Recovery Manager: Release 12.1.0.2.0 - Production on Mon Feb 29 08:50:05 2016

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

RMAN> connect target

connected to target database: CDB3 (DBID=602323566)

RMAN> run
2> {
3> allocate channel c1 type disk format '/u01/ora/db01/backup/df_%d_%s_%p_%T.bus';
4> backupdata     database tag LAB2_CDB3_feb29;
5> release channel c1;
6> }

or

RMAN> run
 {
allocate channel ch1 device type disk;
crosscheck archivelog all;
 backup as compressed backupset database format '/u02/backup/rman/Fullback_%T_%U'
 plus archivelog format '/u02/backup/rman/Archive_%T_%U';
 backup current controlfile format '/u02/backup/rman/Controlback_%T_%U';
 release channel ch1;
}

using target database control file instead of recovery catalog
allocated channel: c1
channel c1: SID=257 device type=DISK

Starting backup at 29-FEB-16
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00009 name=/u01/CDB3/2CD1CF93F0327B86E053FEFF760995F4/datafile/o1_mf_usertbs_cf5fztxb_.dbf
input datafile file number=00008 name=/u01/CDB3/2CD1CF93F0327B86E053FEFF760995F4/datafile/o1_mf_sysaux_cf5fztx9_.dbf
input datafile file number=00010 name=/u01/CDB3/DATAFILE/tbs_emp01.dbf
input datafile file number=00007 name=/u01/CDB3/2CD1CF93F0327B86E053FEFF760995F4/datafile/o1_mf_system_cf5fztwq_.dbf
channel c1: starting piece 1 at 29-FEB-16
channel c1: finished piece 1 at 29-FEB-16
piece handle=/u01/ora/db01/backup/df_CDB3_18_1_20160229.bus tag=LAB2_CDB3_FEB29 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:45
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00006 name=/u01/CDB3/DATAFILE/pdbseed/usertbs01.dbf
input datafile file number=00004 name=/u01/CDB3/DATAFILE/pdbseed/sysaux01.dbf
input datafile file number=00002 name=/u01/CDB3/DATAFILE/pdbseed/system01.dbf
channel c1: starting piece 1 at 29-FEB-16
channel c1: finished piece 1 at 29-FEB-16
piece handle=/u01/ora/db01/backup/df_CDB3_19_1_20160229.bus tag=LAB2_CDB3_FEB29 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:45
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/CDB3/DATAFILE/undotbs01.dbf
input datafile file number=00001 name=/u01/CDB3/DATAFILE/system01.dbf
input datafile file number=00003 name=/u01/CDB3/DATAFILE/sysaux01.dbf
channel c1: starting piece 1 at 29-FEB-16
channel c1: finished piece 1 at 29-FEB-16
piece handle=/u01/ora/db01/backup/df_CDB3_20_1_20160229.bus tag=LAB2_CDB3_FEB29 comment=NONE
channel c1: backup set complete, elapsed time: 00:01:05
Finished backup at 29-FEB-16

Starting Control File and SPFILE Autobackup at 29-FEB-16
piece handle=/u01/CDB3/autobackup/2016_02_29/o1_mf_s_905072224_cf7gn9bk_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 29-FEB-16

released channel: c1

Archive backup

RMAN> run
2> { allocate channel c1 type disk format '/u01/ora/db01/backup/arch_%d_%p.arch';                                                         ;
3> backup
4> format '/u01/ora/db01/backup/df_%d_%s_%p_%T.bus'                   arch_%d_%p.arch '
5> archive log    log all delete all input;
6> } release channel c1;
7> }

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

Starting backup at 29-FEB-16
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=142 RECID=1 STAMP=905021941
input archived log thread=1 sequence=143 RECID=2 STAMP=905021961
input archived log thread=1 sequence=144 RECID=3 STAMP=905022610
input archived log thread=1 sequence=145 RECID=4 STAMP=905023399
input archived log thread=1 sequence=146 RECID=5 STAMP=905045431
input archived log thread=1 sequence=147 RECID=6 STAMP=905072281
input archived log thread=1 sequence=148 RECID=7 STAMP=905072283
input archived log thread=1 sequence=149 RECID=8 STAMP=905072284
input archived log thread=1 sequence=150 RECID=9 STAMP=905072286
input archived log thread=1 sequence=151 RECID=10 STAMP=905072829
channel c1: starting piece 1 at 29-FEB-16
channel c1: finished piece 1 at 29-FEB-16
piece handle=/u01/ora/db01/backup/arch_CDB3_1.arc tag=TAG20160229T090709 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:03
channel c1: deleting archived log(s)
archived log file name=/u01/CDB3/archivelog/2016_02_28/o1_mf_1_142_cf5xjwk1_.arc RECID=1 STAMP=905021941
archived log file name=/u01/CDB3/archivelog/2016_02_28/o1_mf_1_143_cf5xkk9g_.arc RECID=2 STAMP=905021961
archived log file name=/u01/CDB3/archivelog/2016_02_28/o1_mf_1_144_cf5y5t7x_.arc RECID=3 STAMP=905022610
archived log file name=/u01/CDB3/archivelog/2016_02_28/o1_mf_1_145_cf5yyh1x_.arc RECID=4 STAMP=905023399
archived log file name=/u01/CDB3/archivelog/2016_02_29/o1_mf_1_146_cf6ngzfj_.arc RECID=5 STAMP=905045431
archived log file name=/u01/CDB3/archivelog/2016_02_29/o1_mf_1_147_cf7gp0vz_.arc RECID=6 STAMP=905072281
archived log file name=/u01/CDB3/archivelog/2016_02_29/o1_mf_1_148_cf7gp35h_.arc RECID=7 STAMP=905072283
archived log file name=/u01/CDB3/archivelog/2016_02_29/o1_mf_1_149_cf7gp4wc_.arc RECID=8 STAMP=905072284
archived log file name=/u01/CDB3/archivelog/2016_02_29/o1_mf_1_150_cf7gp62f_.arc RECID=9 STAMP=905072286
archived log file name=/u01/CDB3/archivelog/2016_02_29/o1_mf_1_151_cf7h75tn_.arc RECID=10 STAMP=905072829
Finished backup at 29-FEB-16

Starting Control File and SPFILE Autobackup at 29-FEB-16
piece handle=/u01/CDB3/autobackup/2016_02_29/o1_mf_s_905072833_cf7h79vc_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 29-FEB-16

released channel: c1

RMAN> exit


Recovery Manager complete.



RMAN Backup completed for Source Database and created below files


[oracle@host01 backup]$ ls -ltr
total 2725284
-rw-r----- 1 oracle oinstall  716947456 Feb 29 08:55 df_CDB3_18_1_20160229.bus
-rw-r----- 1 oracle oinstall  709591040 Feb 29 08:55 df_CDB3_19_1_20160229.bus
-rw-r----- 1 oracle oinstall 1255571456 Feb 29 08:57 df_CDB3_20_1_20160229.bus
-rw-r----- 1 oracle oinstall  105830400 Feb 29 09:07 arch_CDB3_1.arc
[oracle@host01 backup]$ pwd
/u01/ora/db01/backup

Create Parameter file and take Control file backup on Source host and transferred to Target Host

[oracle@host01 backup]$ sqlplus

SQL*Plus: Release 12.1.0.2.0 Production on Mon Feb 29 09:08:43 2016

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

Enter user-name: / as sysdba

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> create pfie le  ='/u01/ora/db01/backup/initCDB3_A .ora' from spfile;

File created.

SQL> alter database backup controlfile to '/u01/ora/db01/backup/controlfile_restore.ctl'; ;

Database altered.

SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
[oracle@host01 backup]$
[oracle@host01 backup]$
[oracle@host01 backup]$ ls -ltr
total 2742864
-rw-r----- 1 oracle oinstall  716947456 Feb 29 08:55 df_CDB3_18_1_20160229.bus
-rw-r----- 1 oracle oinstall  709591040 Feb 29 08:55 df_CDB3_19_1_20160229.bus
-rw-r----- 1 oracle oinstall 1255571456 Feb 29 08:57 df_CDB3_20_1_20160229.bus
-rw-r----- 1 oracle oinstall  105830400 Feb 29 09:07 arch_CDB3_1.arc
-rw-r--r-- 1 oracle oinstall        883 Feb 29 09:10 initCDB3_A.ora
-rw-r----- 1 oracle oinstall   17973248 Feb 29 09:12 controlfile_restore.ctl

Transfer RMAN full backup,archive backup,parameter file and controlfile from Source server to Target Server


[oracle@host01 backup]$ scp -r * oracle@9.118.255.239:/u01/backup/
oracle@9.118.255.239's password:

arch_CDB3_1.arc                                                                                                                                                                                                                        0%    0     0.0KB/s   --:-- ETA
arch_CDB3_1.arc                                                                                                                                                                                                                       41%   42MB  41.9MB/s   00:01 ETA
arch_CDB3_1.arc                                                                                                                                                                                                                       83%   84MB  41.9MB/s   00:00 ETA
arch_CDB3_1.arc                                                                                                                                                                                                                      100%  101MB  50.5MB/s   00:02 

controlfile_restore.ctl                                                                                                                                                                                                                0%    0     0.0KB/s   --:-- ETA
controlfile_restore.ctl                                                                                                                                                                                                              100%   17MB  17.1MB/s   00:00 

df_CDB3_18_1_20160229.bus                                                                                                                                                                                                              0%    0     0.0KB/s   --:-- ETA
df_CDB3_18_1_20160229.bus                                                                                                                                                                                                              5%   37MB  37.1MB/s   00:17 ETA
df_CDB3_18_1_20160229.bus                                                                                                                                                                                                             11%   76MB  37.3MB/s   00:16 ETA
df_CDB3_18_1_20160229.bus                                                                                                                                                                                                       


All file transferred on target server(host02) and make necessary changes on parameter file (control file location, dump file location) and make sure the same oracle home binary is installed on target server

Backup Location 

[oracle@host02 backup]$ ls -ltr
total 2742904
-rw-r----- 1 oracle oinstall  105830400 Feb 29 09:58 arch_CDB3_1.arc
-rw-r----- 1 oracle oinstall   17973248 Feb 29 09:58 controlfile_restore.ctl
-rw-r----- 1 oracle oinstall  716947456 Feb 29 09:58 df_CDB3_18_1_20160229.bus
-rw-r----- 1 oracle oinstall  709591040 Feb 29 09:59 df_CDB3_19_1_20160229.bus
-rw-r--r-- 1 oracle oinstall        889 Feb 29 10:00 initCDB3_A.ora
-rw-r----- 1 oracle oinstall 1255571456 Feb 29 10:00 df_CDB3_20_1_20160229.bus
drwxr-xr-x 2 oracle oinstall       4096 Feb 29 10:21 775
-rw-r--r-- 1 oracle oinstall        887 Feb 29 10:35 initCDB3.ora


 create same directory structure on Target server.


[oracle@NEW-SERVER ~]$ mkdir -p /u01/app/oracle/admin/CDB3/adump/
[oracle@NEW-SERVER ~]$ mkdir -p /u01/CDB3/DATAFILE/
[oracle@NEW-SERVER ~]$ mkdir -p /u01/app/oracle/fast_recovery_area/CDB3/
[oracle@NEW-SERVER ~]$ mkdir -p /u01/archive/


[oracle@host02 backup]$ export ORACLE_SID=CDB3
[oracle@host02 backup]$ echo $ORACLE_HOME
/u01/app/oracle/product/12.1.0.2/db_1
[oracle@host02 backup]$ echo $SID
CDB3

[oracle@host02 backup]$ sqlplus

SQL*Plus: Release 12.1.0.2.0 Production on Mon Feb 29 10:57:49 2016

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

Enter user-name: / as sysdba
Connected to an idle instance.

SQL> startup mount pfile=initCDB3_A.ora
ORACLE instance started.

Total System Global Area  629145600 bytes
Fixed Size    2927528 bytes
Variable Size  327156824 bytes
Database Buffers  293601280 bytes
Redo Buffers    5459968 bytes
Database mounted.

SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
[oracle@host02 backup]$
[oracle@host02 backup]$ rman

Recovery Manager: Release 12.1.0.2.0 - Production on Mon Feb 29 11:26:32 2016

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

RMAN> connect target

connected to target database: CDB3 (DBID=602323566, not open)

RMAN>

RMAN> run
2> {
3> allocate channel ch01 type disk;
4> allocate channel cho 02 type disk;
5> restore database;
6> recover database;
7> release channel ch01;
8> release channel cho 02;
9> }

using target database control file instead of recovery catalog
allocated channel: ch01
channel ch01: SID=12 device type=DISK

allocated channel: ch02
channel ch02: SID=253 device type=DISK

Starting restore at 29-FEB-16

skipping datafile 1; already restored to file /u01/CDB3/DATAFILE/system01.dbf
skipping datafile 3; already restored to file /u01/CDB3/DATAFILE/sysaux01.dbf
skipping datafile 5; already restored to file /u01/CDB3/DATAFILE/undotbs01.dbf
skipping datafile 7; already restored to file /u01/CDB3/datafile/o1_mf_system_cf7otxxm_.dbf
skipping datafile 8; already restored to file /u01/CDB3/datafile/o1_mf_sysaux_cf7otxs4_.dbf
skipping datafile 9; already restored to file /u01/CDB3/datafile/o1_mf_usertbs_cf7otxrd_.dbf
skipping datafile 10; already restored to file /u01/CDB3/DATAFILE/tbs_emp01.dbf
channel ch01: starting datafile backup set restore
channel ch01: specifying datafile(s) to restore from backup set
channel ch01: restoring datafile 00002 to /u01/CDB3/DATAFILE/pdbseed/system01.dbf
channel ch01: restoring datafile 00004 to /u01/CDB3/DATAFILE/pdbseed/sysaux01.dbf
channel ch01: restoring datafile 00006 to /u01/CDB3/DATAFILE/pdbseed/usertbs01.dbf
channel ch01: reading from backup piece /u01/ora/db01/backup/df_CDB3_19_1_20160229.bus
channel ch01: piece handle=/u01/ora/db01/backup/df_CDB3_19_1_20160229.bus tag=LAB2_CDB3_FEB29
channel ch01: restored backup piece 1
channel ch01: restore complete, elapsed time: 00:01:05
Finished restore at 29-FEB-16

Starting recover at 29-FEB-16

starting media recovery

channel ch01: starting archived log restore to default destination
channel ch01: restoring archived log
archived log thread=1 sequence=147
channel ch01: restoring archived log
archived log thread=1 sequence=148
channel ch01: restoring archived log
archived log thread=1 sequence=149
channel ch01: restoring archived log
archived log thread=1 sequence=150
channel ch01: restoring archived log
archived log thread=1 sequence=151
channel ch01: reading from backup piece /u01/ora/db01/backup/arch_CDB3_1.arc
channel ch01: piece handle=/u01/ora/db01/backup/arch_CDB3_1.arc tag=TAG20160229T090709
channel ch01: restored backup piece 1
channel ch01: restore complete, elapsed time: 00:00:03
archived log file name=/u01/CDB3/archivelog/2016_02_29/o1_mf_1_147_cf7qktht_.arc thread=1 sequence=147
channel default: deleting archived log(s)
archived log file name=/u01/CDB3/archivelog/2016_02_29/o1_mf_1_147_cf7qktht_.arc RECID=15 STAMP=905081364
archived log file name=/u01/CDB3/archivelog/2016_02_29/o1_mf_1_148_cf7qktmn_.arc thread=1 sequence=148
channel default: deleting archived log(s)
archived log file name=/u01/CDB3/archivelog/2016_02_29/o1_mf_1_148_cf7qktmn_.arc RECID=13 STAMP=905081362
archived log file name=/u01/CDB3/archivelog/2016_02_29/o1_mf_1_149_cf7qktjj_.arc thread=1 sequence=149
channel default: deleting archived log(s)
archived log file name=/u01/CDB3/archivelog/2016_02_29/o1_mf_1_149_cf7qktjj_.arc RECID=12 STAMP=905081362
archived log file name=/u01/CDB3/archivelog/2016_02_29/o1_mf_1_150_cf7qkto9_.arc thread=1 sequence=150
channel default: deleting archived log(s)
archived log file name=/u01/CDB3/archivelog/2016_02_29/o1_mf_1_150_cf7qkto9_.arc RECID=14 STAMP=905081362
archived log file name=/u01/CDB3/archivelog/2016_02_29/o1_mf_1_151_cf7qktj0_.arc thread=1 sequence=151
channel default: deleting archived log(s)
archived log file name=/u01/CDB3/archivelog/2016_02_29/o1_mf_1_151_cf7qktj0_.arc RECID=11 STAMP=905081362
media recovery complete, elapsed time: 00:02:01
Finished recover at 29-FEB-16
released channel: ch01
released channel: ch02

RMAN> sql 'alter database open resetlogs';

sql statement: alter database open resetlogs



[oracle@host02 backup]$

Finally, Database has been recovered on target server as below


[oracle@host02 backup]$ sqlplus

SQL*Plus: Release 12.1.0.2.0 Production on Mon Feb 29 11:35:37 2016

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

Enter user-name: / as sysdba

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> select name,open_mode from v$database;

NAME  OPEN_MODE
--------- --------------------
CDB3  READ WRITE

SQL> select instance_name ,host_name from v$instance;

INSTANCE_NAME HOST_NAME
--------------------------------------------
CDB3 host02


SQL>





If the backuppieces are  residing in a new location at the new host you’ll got to catalog them else not needed to set catalog.

For example, your production backup location is ‘/u02/backup/rman/‘ and New server backup location is ‘/u02/backup/‘ then you can follow below command to set catalog.
 Here, in this case we have residing all backup files on your New Server in same location as of Production Server.

RMAN> catalog start with '/u02/backup/';

Restore the Database :

RMAN> run
 {
 allocate channel ch1 device type disk;
  restore database;
 switch datafile all;
 switch tempfile all;
 release channel ch1;
 }

Recover the Database :

RMAN> list backup of archivelog 

RMAN> run
 {
 allocate channel ch1 device type disk;
 recover database until sequence 25;
 release channel ch1;
 }

RMAN> alter database open RESETLOGS;

Statement processed


Check Datafiles and Tempfiles :

 select DBID, NAME, DB_UNIQUE_NAME, DATABASE_ROLE, OPEN_MODE from v$database;

 select FILE_ID, FILE_NAME, TABLESPACE_NAME, BYTES/1024/1024/1024 "Size In GB" from dba_data_files;

select FILE_ID, FILE_NAME, TABLESPACE_NAME, BYTES/1024/1024/1024 "Size In GB" from dba_temp_files;

col MEMBER for a60

select * from v$logfile;


No comments:

Post a Comment