Friday, August 30, 2019

Restore RMAN backup to different server with different database name


Here we will restore oracle database from backup to another server and do the database clone from rman hot backup.



We have taken RMAN backup of PROD and  will  restore rman backup to different server with different database name.
Lets take two servers as below:
SERVER1—DBPROD
SERVER2---DBTEST

ON SERVER1:



DB Name: DBPROD

–Take backup of
DBPROD with archivelog,controlfile and spfile.
–Copy all backupsets from SERVER1(Location: /data1/bak/TEST/) to SERVER2(Location:/u01/backup/TEST/) , So that we will restore oracle database from cold backup.

ON SERVER2:

–Create pfile for database
DBTEST.
DB Name: DBTEST

#export ORACLE_SID=TEST
#rman target /
RMAN>startup nomount;
RMAN>restore controlfile from '/u01/backup/backup_db_c-300166359-20120316-00';   --- complete path of backup
RMAN>alter database mount;

–Since backup location on SERVER2 is different from SERVER1, so we have to use catalog command to 

update new backup location in controlfile.
Use below command for all backuppieces:


RMAN> CATALOG START WITH '/my/backup/location';
Or
RMAN>catalog backuppiece '/u01/backup/ora_df_020412_21_14_NSNDB_1635_1';
RMAN>catalog backuppiece '/u01/backup/ora_df_020412_21_14_NSNDB_1636_1';
RMAN>catalog backuppiece '/u01/backup/ora_arch_230412_13_43_NSNDB_23_1';
RMAN>catalog backuppiece '/u01/backup/ora_arch_230412_13_43_NSNDB_24_1';

–Since datafile location on SERVER2 is different from SERVER1, So we have to update controlfile for same with SET NEWNAME clause:



Now restore database backup on SERVER2:

RMAN>
run
{
set newname for datafile '/data02/oradata/system01.dbf' to '/u01/oradata/testbak/system01.dbf';
set newname for datafile '/data02/oradata/undotbs01.dbf' to '/u01/oradata/ testbak /undotbs1.dbf';
set newname for datafile '/data02/oradata/sysaux01.dbf' to '/u01/oradata/ testbak /sysaux01.dbf';
set newname for datafile '/data02/oradata/users01.dbf' to '/u01/oradata/ testbak /users01.dbf';
restore database;
switch datafile all;
}
RMAN>exit;

–Also update redo log file in controlfile on SERVER2:

#sqlplus "/as sysdba"
SQL>alter database rename file '/data02/oradata/redo07.log' to '/u01/oradata/ testbak /redo07.log';
SQL>alter database rename file '/data02/oradata/redo08.log' to '/u01/oradata/ testbak /redo08.log';
SQL>alter database rename file '/data02/oradata//redo09.log' to '/u01/oradata/ testbak /redo09.log';
SQL>exit;

#rman target /

RMAN>
run
{
recover database;
alter database open resetlogs; }
RMAN>exit;
#sqlplus "/as sysdba"

SQL>alter database tempfile '/u01/home/oracle/PROD/tempfiles/temp01_PROD.dbf' drop including datafiles;

sql>ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/oradata/nsnbak/temp01.dbf' size 200m reuse/size 500M;

sql>select name from v$tempfile;


To change DB name follow the below steps:-

To change the database name in addition to the DBID, specify the 
DBNAME parameter. This example changes the name to test_db:
Ensure that the target database is mounted but not open, and that it was shut down consistently prior to mounting. For example:
SHUTDOWN IMMEDIATE
STARTUP MOUNT
$nid TARGET=SYS/password DBNAME=test_db

SQL>
ALTER DATABASE OPEN RESETLOGS;

After that modify the parameter file as db_name

No comments:

Post a Comment