Backup Recovery Document 1338193.1
Backup Recovery Document 1338193.1
1
Copyright (c) 2023, Oracle. All rights reserved. Oracle Confidential.
How to Move/Restore DB to New Host and File System using RMAN (Doc ID 1338193.1)
In this Document
Goal
Assumptions
Solution
Offline backup
Step 1.2 - Transfer Backuppieces to New Host
Step 1.3 - Restore Database at New Host
APPLIES TO:
GOAL
NOTE: In the images and/or the document content below, the user information and environment data used represents
fictitious data from the Oracle sample schema(s), Public Documentation delivered with an Oracle database product or other
training material. Any similarity to actual environments, actual persons, living or dead, is purely coincidental and not
intended in any manner.
For the purposes of this document, the following fictitious environment is used as an example to describe the
procedure:
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=jvbe3sysz_4&id=1338193.1 1/20
1/21/23, 4:36 AM Document 1338193.1
Source Database:
DB_NAME: PRIM
Copied Database:
DB_NAME: TEST
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
NOTE: If your intention is to clone the database, you should use the RMAN duplicate command. Do not use a
restore/recover database to clone your database.
This note will work for all file systems - ASM, OCFS, raw, cooked etc.
Important Note: During the restore and recovery process, do NOT connect to the production database's recovery catalog,
even if you are using one to perform the backup. The production database's recovery catalog will get confused if there are
multiple databases with the same DBID.
http://docs.oracle.com/cd/E11882_01/backup.112/e10642/rcmadvre.htm#BRADV908
Assumptions
1) the existing and new hosts are running on the same operating system and RDBMS patchsets. Restoring to a different
platform and/or RDBMS patchset is quite complex and will not be addressed in this note.
SOLUTION
There are two solutions presented in this note as we wanted to give you the options of having either the concise steps and
commands in Unix format,
OR
Feel free to jump to whichever section you are most comfortable with.
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=jvbe3sysz_4&id=1338193.1 2/20
1/21/23, 4:36 AM Document 1338193.1
Online Backup
When in ARCHIVELOG mode, you can choose to perform either an offline or online backup. For an online backup, you do not
need to shutdown the database. You can just backup the database plus all archivelogs whilst the database is up and running:
$ . oraenv
ORACLE_SID = [prim] ? PRIM
$ rman target /
Offline backup
If the database is running in NOARCHIVELOG mode then it must be restarted in MOUNT mode to take an offline RMAN
backup:
$ . oraenv
ORACLE_SID = [prim] ? PRIM
$ rman target /
Once the backup is completed, transfer the backuppieces across to the new host in the same location using an operating
system utility such as cp, scp, ftp etc.
You can certainly place the backuppieces into another location and use the RMAN CATALOG command to tell RMAN about their
new location. In Unix you may also consider using symbolic links to the new location. Or use NFS to mount the backuppieces
to the new host.
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=jvbe3sysz_4&id=1338193.1 3/20
1/21/23, 4:36 AM Document 1338193.1
Once the backuppieces have been transferred to the new host, restore the database at the new host.
Step 1.3.1) Set the environment to point to the ORACLE_SID that you are about to restore:
For example:
$ . oraenv
ORACLE_SID = [prim] ? PRIM
Step 1.3.3) Check the init.ora parameters, and precreate the directories if required. Note that the AUDIT directory must pre-
exist before you can NOMOUNT the restored spfile
$ mkdir -p /<path>/admin/PRIM/adump
Step 1.3.4) Restore the controlfile from a known backuppiece and mount the database:
If the backuppieces are residing in a new location at the new host you'll need to catalog them:
Step 1.3.5) Restore the database, using SET NEWNAME to relocate the datafiles and tempfiles to their new locations if
required.
a) preview the restore - this will report the backuppieces required for the restore operation. It will not perform the actual
restore.
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=jvbe3sysz_4&id=1338193.1 4/20
1/21/23, 4:36 AM Document 1338193.1
b) If the preview looks valid, then go ahead and perform the actual restore to the new host:
RMAN> run {
# set newname for all datafiles to be mapped to a new path
# OR use SET NEWNAME FOR DATABASE if you wish to have all files located in the same directory
# eg. SET NEWNAME FOR DATABASE to '+DATA/inovadg/datafile/%b'
set newname for datafile 1 to 'new file path and name';
...
set newname for tempfile 1 to 'new file path and name';
restore database;
switch datafile all;
switch tempfile all;
}
Step 1.3.6) Confirm that all datafiles have been restored to the new location:
a) if recovering from an OFFLINE backup, and you do not have further archivelogs to apply from the original host, use recover
with NOREDO:
b) if the original database is running in archivelog mode and there are subsequent archivelogs generated after the initial
backup, you can back up these archivelogs and transfer them to the new host as well.
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=jvbe3sysz_4&id=1338193.1 5/20
1/21/23, 4:36 AM Document 1338193.1
Step 1.3.9) Once all files have been renamed, open the database with resetlogs.
a) if the source database had block change tracking, you will need to either precreate the block change tracking directory, or
disable and enable it before opening the database:
Step 1.3.10) confirm the location of your tempfiles, recreating them at the new location if required:
Step 1.3.11) If the old database is going to remain up and running on the old server, use NID to rename the DBNAME and
DBID of either the old or new database to avoid confusion.
For example:
How to Change the DBID, DBNAME Using NID Utility in version 10GgR2 onwards (Doc ID 863800.1)
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=jvbe3sysz_4&id=1338193.1 6/20
1/21/23, 4:36 AM Document 1338193.1
allocate channel t2 type disk;
allocate channel t3 type disk;
allocate channel t4 type disk;
backup format '<give location of backup>/%U' filesperset 4 (database);
Example
-----------
Script
-------
Backup log
--------------
Recovery Manager: Release 11.2.0.1.0 - Production on Tue Jan 17 16:21:15 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11>
using target database control file instead of recovery catalog
allocated channel: t1
channel t1: SID=192 device type=DISK
allocated channel: t2
channel t2: SID=10 device type=DISK
allocated channel: t3
channel t3: SID=68 device type=DISK
allocated channel: t4
channel t4: SID=134 device type=DISK
Transfer the backup pieces from production to the non-production server. Prior to 10g you must locate them in the same
directory path. From 10g and onwards we can catalog backuppieces so this is no longer a requirement.
You will also need to bring across the database parameter file.
Note:
ORADIM does create a passwordfile if used like in this example in step 3
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=jvbe3sysz_4&id=1338193.1 9/20
1/21/23, 4:36 AM Document 1338193.1
C:\> ORADIM -new -sid ORACLE_SID -intpwd <password> -maxusers 10 -startmode auto -pfile '<your pfile location>'
at this point the DB_NAME still be to set as PRIM (Which is the name on the Source DB), it will be changed on step 2.7
C:\> ORADIM -new -sid ORACLE_SID -intpwd <password> -maxusers 10 -startmode auto -pfile '<your pfile location>'
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=jvbe3sysz_4&id=1338193.1 10/20
1/21/23, 4:36 AM Document 1338193.1
$rman target /
RMAN> restore controlfile from '<backup piece name of controlfile ie last step of backup >';
RMAN> alter database mount;
Example
----------
Here onward we will see at source we took backup to location at "D:\BACKUP\PRIM\" but we copied
backup at "D:\BACKUP\TEST" at new server
RMAN>
If backup pieces have been copied to a different location than source server then we need to catalog those backuppieces (only
applicable to 10g and above)
Example
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=jvbe3sysz_4&id=1338193.1 11/20
1/21/23, 4:36 AM Document 1338193.1
---------
RMAN> catalog start with 'D:\BACKUP\TEST\' noprompt;
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=jvbe3sysz_4&id=1338193.1 12/20
1/21/23, 4:36 AM Document 1338193.1
RMAN>
RMAN> crosscheck backup;
Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=D:\BACKUP\PRIM\0UN10JGO_1_1 RECID=22 STAMP=772820505
deleted backup piece
backup piece handle=D:\BACKUP\PRIM\0VN10JGP_1_1 RECID=23 STAMP=772820505
deleted backup piece
backup piece handle=D:\BACKUP\PRIM\0TN10JGO_1_1 RECID=24 STAMP=772820505
deleted backup piece
backup piece handle=D:\BACKUP\PRIM\0SN10JGO_1_1 RECID=25 STAMP=772820504
Deleted 4 EXPIRED objects
Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=D:\BACKUP\PRIM\14N10JHQ_1_1 RECID=27 STAMP=772820538
deleted backup piece
backup piece handle=D:\BACKUP\PRIM\13N10JHQ_1_1 RECID=28 STAMP=772820538
deleted backup piece
backup piece handle=D:\BACKUP\PRIM\12N10JHQ_1_1 RECID=29 STAMP=772820538
deleted backup piece
backup piece handle=D:\BACKUP\PRIM\11N10JHQ_1_1 RECID=30 STAMP=772820538
Deleted 4 EXPIRED objects
RMAN>
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=jvbe3sysz_4&id=1338193.1 14/20
1/21/23, 4:36 AM Document 1338193.1
Example.
RMAN>
If you need to the datafiles to be restored to a new location on the new host, you can use SET NEWNAME:
Example
---------
RMAN> run{
2> allocate channel t1 type disk;
3> allocate channel t2 type disk;
4> set newname for datafile 1 to '<path>\TEST\ORADATA\SYSTEM01.DBF';
5> set newname for datafile 2 to '<path>\TEST\ORADATA\SYSAUX01.DBF';
6> set newname for datafile 3 to '<path>\TEST\ORADATA\UNDOTBS01.DBF';
7> set newname for datafile 4 to '<path>\TEST\ORADATA\USERS01.DBF';
8> set until sequence 24;
9> restore database;
10> switch datafile all;
11> recover database;
12> }
allocated channel: t2
channel t2: SID=129 device type=DISK
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=jvbe3sysz_4&id=1338193.1 16/20
1/21/23, 4:36 AM Document 1338193.1
RMAN>
Before opening database please make sure online redo logs are in the appropriate location:
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=jvbe3sysz_4&id=1338193.1 17/20
1/21/23, 4:36 AM Document 1338193.1
SQL> alter database rename file '<old file location and name>' to '<new location and name>';
Example
----------
SQL> set lines 200
SQL> col member format a60
SQL> select a.thread#,a.group#,b.type,b.member,a.bytes/1048576 from v$log a,v$logfile b where a.group#=b.group#
order by a.group#;
Database altered.
Database altered.
Database altered.
SQL>
The newly restored database will have the same DBID and DB_NAME as the original database so we will need to change them.
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=jvbe3sysz_4&id=1338193.1 18/20
1/21/23, 4:36 AM Document 1338193.1
How to Change the DBID, DBNAME Using NID Utility in version 10gR2 onwards (Document ID 863800.1)
SQL> alter database backup controlfile to trace as '<location and name of trace file>';
SQL> oradebug setmypid;
SQL> oradebug tracefile_name;
Edit the trace file generated above, and change this line:
CREATE CONTROLFILE REUSE DATABASE "PRIM" NORESETLOGS ARCHIVELOG ====>assuming production database name is
PRIM
to
CREATE CONTROLFILE set DATABASE "TEST" RESETLOGS ARCHIVELOG FORCE LOGGING ====>assuming Non-Prod
database name is TEST
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=jvbe3sysz_4&id=1338193.1 19/20
1/21/23, 4:36 AM Document 1338193.1
set ORACLE_SID=TEST
Confirm the location of your tempfiles, recreate them at the new location if required:
REFERENCES
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=jvbe3sysz_4&id=1338193.1 20/20