Disaster recovery includes the restore of and
recovery of the target database after the loss of the entire target
database, the recovery catalog database, all current control files, all
online redo log files, and all parameter files.
This scenario assumes that the Linux server on which your database was running has been damaged beyond repair. Fortunately, you backed up the database to Oracle Secure Backup and have the tapes available. The scenario assumes the following:
If you use the procedure in this section, then the DBID for the restored database will be the same as the DBID for the original database. You should not register a test database created in this way in the same recovery catalog as the source database. Because the DBID of the two databases is the same, the metadata for the test database can interfere with RMAN's ability to restore and recover the source database.
If your goal is to create a new copy of your target database for ongoing use on a new host, then use the RMAN
For the sake of illustration, assume that the directory structure of
Prerequisites of Disaster Recovery
To perform a disaster recovery, you must have the following:-
Backups of all datafiles
-
All archived redo logs generated after the creation time of the oldest backup that you intend to restore
-
At least one control file autobackup
-
A record of the DBID of the database
Recovering the Database After a Disaster
The procedure for disaster recovery is similar to the procedure for recovering the database with a backup control file inNOCATALOG
mode. If you are restoring the database to a new host, then you should also review the considerations described in "Restoring a Database on a New Host".This scenario assumes that the Linux server on which your database was running has been damaged beyond repair. Fortunately, you backed up the database to Oracle Secure Backup and have the tapes available. The scenario assumes the following:
-
Oracle Database is already installed on the new host.
-
You are restoring the database to a new Linux host with the same directory structure as the old host.
-
You have one tape drive containing backups of all the datafiles and
archived redo logs through log 1124, as well as autobackups of the
control file and server parameter file.
-
You do not use a recovery catalog with the database.
-
If possible, restore or re-create all relevant network files such as
tnsnames.ora
andlistener.ora
and a password file.
-
Start RMAN and connect to the target database instance.
At this stage, no initialization parameter file exists. If you have setORACLE_SID
andORACLE_HOME
, then you can use operating system authentication to connect asSYSDBA
. For example, start RMAN as follows:
% rman RMAN> CONNECT TARGET /
-
Specify the DBID for the target database with the
SET
DBID
command, as described in "Restoring the Server Parameter File".
For example, enter the following command:
SET DBID 676549873;
-
Run the
STARTUP
NOMOUNT
command.
When the server parameter file is not available, RMAN attempts to start the instance with a dummy server parameter file.
-
Allocate a channel to the media manager and then restore the server parameter file from autobackup.
For example, enter the following command to restore the server parameter file from Oracle Secure Backup:
RUN { ALLOCATE CHANNEL c1 DEVICE TYPE sbt; RESTORE SPFILE FROM AUTOBACKUP; }
-
Restart the instance with the restored server parameter file.
STARTUP FORCE NOMOUNT;
-
Write the a command file to perform the restore and recovery, and
then execute the command file. The command file should do the following:
-
Allocate a channel to the media manager.
-
Restore a control file autobackup (see "Performing Recovery with a Backup Control File and No Recovery Catalog").
-
Mount the restored control file.
-
Catalog any backups not recorded in the repository with the
CATALOG
command.
-
Restore the datafiles to their original locations. If volume names have changed, then run
SET
NEWNAME
commands before the restore and perform a switch after the restore to update the control file with the new locations for the datafiles, as shown in the following example.
-
Recover the datafiles. RMAN stops recovery when it reaches the log sequence number specified.
RMAN> RUN { # Manually allocate a channel to the media manager ALLOCATE CHANNEL t1 DEVICE TYPE sbt; # Restore autobackup of the control file. This example assumes that you have # accepted the default format for the autobackup name. RESTORE CONTROLFILE FROM AUTOBACKUP; # The set until command is used in case the database # structure has changed in the most recent backups, and you wish to # recover to that point-in-time. In this way RMAN restores the database # to the same structure that the database had at the specified time. ALTER DATABASE MOUNT; SET UNTIL SEQUENCE 1124 THREAD 1; RESTORE DATABASE; RECOVER DATABASE; }
The following example of theRUN
command shows the same scenario except with new filenames for the restored datafiles:
RMAN> RUN { # If you need to restore the files to new locations, # use SET NEWNAME commands: SET NEWNAME FOR DATAFILE 1 TO '/dev/vgd_1_0/rlvt5_500M_1'; SET NEWNAME FOR DATAFILE 2 TO '/dev/vgd_1_0/rlvt5_500M_2'; SET NEWNAME FOR DATAFILE 3 TO '/dev/vgd_1_0/rlvt5_500M_3'; ALLOCATE CHANNEL t1 DEVICE TYPE sbt; RESTORE CONTROLFILE FROM AUTOBACKUP; ALTER DATABASE MOUNT; SET UNTIL SEQUENCE 124 THREAD 1; RESTORE DATABASE; SWITCH DATAFILE ALL; # Update control file with new location of datafiles. RECOVER DATABASE; }
-
Allocate a channel to the media manager.
-
If recovery was successful, then open the database and reset the online logs:
ALTER DATABASE OPEN RESETLOGS;
Restoring a Database on a New Host
If your goal is to perform a test run of your disaster recovery procedures, or to permanently move a database to a new host, then you can use the procedure in this section. This procedure uses theRESTORE
and RECOVER
commands.If you use the procedure in this section, then the DBID for the restored database will be the same as the DBID for the original database. You should not register a test database created in this way in the same recovery catalog as the source database. Because the DBID of the two databases is the same, the metadata for the test database can interfere with RMAN's ability to restore and recover the source database.
If your goal is to create a new copy of your target database for ongoing use on a new host, then use the RMAN
DUPLICATE
command instead of this procedure. The DUPLICATE
command assigns a new DBID to the database it creates, enabling it to
be registered in the same recovery catalog as the original database.
See Also:
"Overview of RMAN Database Duplication" to learn how to duplicate a databasePreparing to Restore a Database on a New Host
To prepare for the restore of the database to a new host, take the following steps:-
Record the DBID for your source database. If you do not know the DBID for your database, then see "Determining the DBID of the Database" to learn how to determine the DBID.
-
Make the source database initialization parameter file accessible on
the new host. Copy the file from the old host to a new host by using an
operating system utility.
-
If you perform a test restore only, then make sure that RMAN is not
connected to the recovery catalog. Otherwise, RMAN records metadata
about the restored datafiles in the recovery catalog. This metadata
interferes with future attempts to restore and recover the primary
database.
If you must use a recovery catalog because the control file is not large enough to contain the RMAN repository data on all of the backups that you need to restore, then use Oracle Data Pump to export the catalog and import it into a different schema or database. Afterward, use the copied recovery catalog for the test restore. Otherwise, the recovery catalog considers the restored database as the current target database.
-
Make sure backups used for the restore are accessible on the restore
host. For example, if the backups were made with a media manager, then
make sure the tape device is connected to the new host. If you are using
disk copies, then use the procedure in the following section.
-
If you are performing a trial restore of the production database,
then perform either of the following actions before restoring the
database in the test environment:
-
If the test database will use a flash recovery area that is physically different from the recovery area used by the production database, then set
DB_RECOVERY_FILE_DEST
in the test database instance to the new location.
-
If the test database will use a flash recovery area that is physically the same as the recovery area used by the production database, then set
DB_UNIQUE_NAME
in the test database instance to a different name from the production database.
-
If the test database will use a flash recovery area that is physically different from the recovery area used by the production database, then set
Restoring Disk Backups to a New Host
To move the database to a new host by means of datafile copies or backup sets on disk, you must transfer the files manually to the new host. This example assumes that RMAN is using a recovery catalog.-
Start RMAN and connect to a target database and recovery catalog.
-
Run a
LIST
command to see a listing of backups of the datafile and control file autobackups.
For example, enter the following command to view datafile copies:
LIST COPY;
For example, enter the following command to view control file backups:
LIST BACKUP OF CONTROLFILE;
The piece name of the autobackup must use the%F
substitution variable, so the autobackup piece name will include the stringc-IIIIIIIIII-YYYYMMDD-QQ
, whereIIIIIIIIII
stands for the DBID,YYYYMMDD
is a time stamp in the Gregorian calendar of the day the backup is generated, andQQ
is the sequence in hexadecimal.
-
Copy the backups to the new host with an operating system utility.
Enter a command such as the following to copy all datafile copies to the?/oradata/trgt
directory on the new host:
% cp -r /disk1/*dbf /net/new_host/oracle/oradata/trgt
Enter a command such as the following to copy the autobackup backup piece to the/tmp
directory on the new host:
% cp -r /disk1/auto_bkp_loc/c-1618370911-20070208-00 /net/new_host/tmp
As explained in "Restoring the Server Parameter File from a Control File Autobackup", you will need to use theSET CONTROLFILE AUTOBACKUP FORMAT
command when restoring an autobackup from a nondefault location.
Testing the Restore of a Database on a New Host
This scenario assumes that you want to test whether you can restore your database to a new host. The scenario assumes that you have two networked Linux hosts,hosta
and hostb
. A target database named trgta
is on hosta
and is registered in recovery catalog catdb
. You want to test the restore and recovery of trgta
on hostb
, while keeping database trgta
up and running on hosta
.For the sake of illustration, assume that the directory structure of
hostb
is different from hosta
. The target database is located in /net/hosta/dev3/oracle/dbs
, but you want to restore the database to /net/hostb/oracle/oradata/test
.
You have tape backups of datafiles, control files, archived redo logs,
and the server parameter file on a media manager accessible by both
hosts. The ORACLE_SID
for the trgta
database is trgta
and will not change for the restored database
Caution:
If you are restoring the database for test purposes, then never connect RMAN to the test database and the recovery catalog.-
Ensure that the backups of the target database are accessible on the new host.
To test disaster recovery, you need to have a recoverable backup of the target database. When preparing your disaster recovery strategy, ensure that the backups of the datafiles, control files, and server parameter file are restorable onhostb
. Thus, you must configure the media management software so thathostb
is a media manager client and can read the backup sets created onhosta
. Consult the media management vendor for support on this issue.
-
Configure the
ORACLE_SID
onhostb
.
This scenario assumes that you want to start the RMAN client onhostb
and authenticate yourself through the operating system. However, you must be connected tohostb
either locally or through a net service name.
After logging in tohostb
with administrator privileges, edit the/etc/group
file so that you are included: in the DBA group:
dba:*:614:<your_user_name>
Set theORACLE_SID
environment variable onhostb
to the same value used onhosta
:
% setenv ORACLE_SID trgta
-
Start RMAN on
hostb
and connect to the target database without connecting to the recovery catalog.
For example, enter the following command:
% rman NOCATALOG RMAN> CONNECT TARGET /
-
Set the DBID and start the database instance without mounting the database.
For example, runSET
DBID
to set the DBID, then runSTARTUP
NOMOUNT
:
SET DBID 1340752057; STARTUP NOMOUNT
RMAN will fail to find the server parameter file, which has not yet been restored, but will start the instance with a "dummy" file. Sample output follows:
startup failed: ORA-01078: failure in processing system parameters LRM-00109: could not open parameter file '/net/hostb/oracle/dbs/inittrgta.ora' trying to start the Oracle instance without parameter files ... Oracle instance started
-
Restore and edit the server parameter file.
Because you enabled the control file autobackup feature when making your backups, the server parameter file is included in the backup. If you are restoring an autobackup that has a nondefault format, then use theSET CONTROLFILE AUTOBACKUP FORMAT
command to indicate the format.
Allocate a channel to the media manager, then restore the server parameter file as a client-side parameter file and use theSET
command to indicate the location of the autobackup (in this example, the autobackup is in/tmp
):
RUN { ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS '...'; SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/tmp/%F'; RESTORE SPFILE TO PFILE '?/oradata/test/inittrgta.ora' FROM AUTOBACKUP; SHUTDOWN ABORT; }
-
Edit the restored initialization parameter file.
Change any location-specific parameters, for example, those ending in_DEST
, to reflect the new directory structure. For example, edit the following parameters:
- IFILE - LOG_ARCHIVE_DEST_1 - CONTROL_FILES
-
Restart the instance with the edited initialization parameter file.
For example, enter the following command:
STARTUP FORCE NOMOUNT PFILE='?/oradata/test/inittrgta.ora';
-
Restore the control file from an autobackup and then mount the database.
For example, enter the following command:
RUN { ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS '...'; RESTORE CONTROLFILE FROM AUTOBACKUP; ALTER DATABASE MOUNT; }
RMAN restores the control file to whatever locations you specified in theCONTROL_FILES
initialization parameter.
-
Catalog the datafile copies that you copied in "Restoring Disk Backups to a New Host", using their new filenames or
CATALOG START
WITH
(if you know all the files are in directories with a common prefix easily addressed with aCATALOG START WITH
). For example, run:
CATALOG START WITH '/oracle/oradata/trgt/';
If you want to specify files individually, then you can execute aCATALOG
command as follows:
CATALOG DATAFILECOPY '/oracle/oradata/trgt/system01.dbf', '/oracle/oradata/trgt/undotbs01.dbf', '/oracle/oradata/trgt/cwmlite01.dbf', '/oracle/oradata/trgt/drsys01.dbf', '/oracle/oradata/trgt/example01.dbf', '/oracle/oradata/trgt/indx01.dbf', '/oracle/oradata/trgt/tools01.dbf', '/oracle/oradata/trgt/users01.dbf';
-
Start a SQL*Plus session on the new database and query the database filenames recorded in the control file.
Because the control file is from thetrgta
database, the recorded filenames use the originalhosta
filenames. You can queryV$
views to obtain this information. Run the following query in SQL*Plus:
COLUMN NAME FORMAT a60 SPOOL LOG '/tmp/db_filenames.out' SELECT FILE# AS "File/Grp#", NAME FROM V$DATAFILE UNION SELECT GROUP#,MEMBER FROM V$LOGFILE; SPOOL OFF EXIT
-
Write the RMAN restore and recovery script. The script must include the following steps:
-
For each datafile on the destination host that is restored to a different path than it had on the source host, use a
SET
NEWNAME
command to specify the new path on the destination host. If the file systems on the destination system are set up to have the same paths as the source host, then do not useSET NEWNAME
for those files restored to the same path as on the source host.
-
For each online redo log that is to be created at a different location than it had on the source host, use SQL
ALTER
DATABASE
RENAME
FILE
commands to specify the pathname on the destination host. If the file systems on the destination system are set up to have the same paths as the source host, then do not useALTER DATABASE RENAME FILE
for those files restored to the same path as on the source host.
-
Perform a
SET UNTIL
to limit recovery to the end of the archived redo logs. Note that recovery stops with an error if noSET UNTIL
is specified.
-
Restore and recover the database.
-
Run
SWITCH DATAFILE ALL
so that the control file recognizes the new path names as the official new names of the datafiles.
reco_test.rman
that can perform the restore and recovery.
RUN { # allocate a channel to the tape device ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS '...'; # rename the datafiles and online redo logs SET NEWNAME FOR DATAFILE 1 TO '?/oradata/test/system01.dbf'; SET NEWNAME FOR DATAFILE 2 TO '?/oradata/test/undotbs01.dbf'; SET NEWNAME FOR DATAFILE 3 TO '?/oradata/test/cwmlite01.dbf'; SET NEWNAME FOR DATAFILE 4 TO '?/oradata/test/drsys01.dbf'; SET NEWNAME FOR DATAFILE 5 TO '?/oradata/test/example01.dbf'; SET NEWNAME FOR DATAFILE 6 TO '?/oradata/test/indx01.dbf'; SET NEWNAME FOR DATAFILE 7 TO '?/oradata/test/tools01.dbf'; SET NEWNAME FOR DATAFILE 8 TO '?/oradata/test/users01.dbf'; SQL "ALTER DATABASE RENAME FILE ''/dev3/oracle/dbs/redo01.log'' TO ''?/oradata/test/redo01.log'' "; SQL "ALTER DATABASE RENAME FILE ''/dev3/oracle/dbs/redo02.log'' TO ''?/oradata/test/redo02.log'' "; # Do a SET UNTIL to prevent recovery of the online logs SET UNTIL SCN 123456; # restore the database and switch the datafile names RESTORE DATABASE; SWITCH DATAFILE ALL; # recover the database RECOVER DATABASE; } EXIT
-
For each datafile on the destination host that is restored to a different path than it had on the source host, use a
-
Execute the script created in the previous step.
For example, start RMAN to the target database and run the@
command:
% rman TARGET / NOCATALOG RMAN> @reco_test.rman
-
Open the restored database with the
RESETLOGS
option.
From the RMAN prompt, open the database with theRESETLOGS
option:
ALTER DATABASE OPEN RESETLOGS;
Caution:When you re-open your database in the next step, do not connect to the recovery catalog. Otherwise, the new database incarnation created is registered automatically in the recovery catalog, and the filenames of the production database are replaced by the new filenames specified in the script. -
Optionally, delete the test database with all of its files.
Note:If you used an ASM disk group, thenDROP DATABASE
is the only way to safely remove the files of the test database. If you restored to non-ASM storage then you can also use operating system commands to remove the database.DROP DATABASE
command to delete all files associated with the database automatically. The following example deletes the database files:
STARTUP FORCE NOMOUNT PFILE='?/oradata/test/inittrgta.ora'; DROP DATABASE;
Because you did not perform the restore and recovery when connected to the recovery catalog, the recovery catalog contains no records for any of the restored files or the procedures performed during the test. Likewise, the control file of thetrgta
database is completely unaffected by the test.
No comments:
Post a Comment