Oracle8i Backup and Recovery Guide Release 8.1.5 A67773-01 |
|
This chapter describes how to use Recovery Manager to create a duplicate database for testing purposes, and includes the following topics:
The RMAN duplicate command allows you to use your target database backups to create a test database while still retaining your original database. The command takes image copies or backup sets of your target database's files and generates a new database. A duplicate database is especially useful if your production database must be up and running 24 hours per day, 7 days a week.
As part of the duplicating operation, RMAN manages the following:
When duplicating a database you can:
See Also: For duplicate command syntax, see "duplicate".
RMAN duplication has the following restrictions. You cannot:
If no valid backups exist of any tablespace or datafile, the command fails.
RMAN-10035: exception raised in RPC: ORA-19504: failed to create file "/oracle/dbs/tbs_01.f" ORA-27086: skgfglk: unable to lock file - already in use SVR4 Error: 11: Resource temporarily unavailable Additional information: 8 RMAN-10031: ORA-19624 occurred during call to DBMS_BACKUP_RESTORE.RESTOREBACKUPPIECE
Note that if you want the filenames to be the same, and the databases are in different hosts, then you must use the nofilenamecheck option.
When duplicating a database, perform the following operations:
The duplicate command creates the control files by using the names listed in the init.ora
file of the duplicate database. When choosing names for the duplicate database control files, make sure that you do not overwrite the init.ora
settings for the production files at the target database.
You have these options for creating the names of the duplicate online redo logs, which are listed in the order of precedence:
The order of precedence determines how RMAN renames the online redo logs. For example, if you specify both the logfile clause and the LOG_FILE_NAME_CONVERT parameter, RMAN uses the logfile clause. If you specify all options, then RMAN uses the logfile clause and ignores the others.
If you want to have different filenames in your duplicate datafile, then you must use parameters or commands to specify them. You have these options for renaming datafiles, listed in the order of precedence:
The order of precedence determines how RMAN will name the datafiles. For example, if you specify all the commands and the initialization parameter, RMAN uses set newname. If you specify the set auxname command and DB_FILE_NAME_CONVERT, RMAN uses set auxname. If you do not specify any of the first three options, then RMAN uses the original target filenames for the duplicate file.
When you specify skip readonly, RMAN does not duplicate the datafiles of these tablespaces. You will see the following values in the specified views or tables:
Table/View | Column | Value |
---|---|---|
V$DATAFILE |
STATUS |
OFFLINE |
V$DATAFILE |
ENABLED |
READ ONLY |
V$DATAFILE |
NAME |
MISSINGxxx |
SYS.DBA_DATA_FILES |
STATUS |
AVAILABLE |
SYS.DBA_TABLESPACES |
STATUS |
READ ONLY |
When tablespaces are taken offline with the OFFLINE NORMAL option, RMAN does not duplicate the datafiles of these tablespaces. After duplication, you can manually add or drop these tablespaces.
You will see the following values in the specified views or tables:
Table/View | Column | Value |
---|---|---|
V$DATAFILE |
STATUS |
OFFLINE |
V$DATAFILE |
ENABLED |
DISABLED |
V$DATAFILE |
NAME |
MISSINGxxx |
SYS.DBA_DATA_FILES |
STATUS |
AVAILABLE |
SYS.DBA_TABLESPACES |
STATUS |
OFFLINE |
Note that when you take a tablespace offline with the IMMEDIATE option, RMAN duplicates rather than skips the tablespace. As with online tablespaces, RMAN requires a valid backup for duplication.
It is possible for a set newname, set newname, or DB_FILE_NAME_CONVERT to generate a name that is already in use in the target database. In this case, specify nofilenamecheck to avoid an error. For example, assume that the host A database has two files: datafile 1
is named /oracle/data/file1.f
and datafile 2
is named /oracle/data/file2.f
. When duplicating to host B, you issue:
run { set newname for datafile 1 to /oracle/data/file2.f; # rename datafile 1 as file2.f set newname for datafile 2 to /oracle/data/file1.f; # rename datafile 2 as file1.f allocate ... duplicate target database to newdb; }
Even though you issued set newname commands for all your datafiles, the duplicate command will fail because the duplicate filenames are still in use in the target database. Although datafile 1
in the target is not using /oracle/data/file2.f
, and datafile 2
in the target is not using /oracle/data/file1.f
, the target filename is used by one of the duplicate datafiles and so you must specify nofilenamecheck to avoid an error.
Satisfy the following requirements before performing RMAN duplication:
For information about creating and maintaining Oracle password files, see the Oracle8i Administrator's Guide.
Create an init.ora
file for the auxiliary instance and set the following required parameters:
Parameter | Specify: |
---|---|
DB_NAME |
The same name that you use in the duplicate command. |
CONTROL_FILES |
Optionally, set the following parameters:
Parameter | Specify: |
---|---|
DB_FILE_NAME_CONVERT |
|
LOG_FILE_NAME_CONVERT |
Set other parameters, including the parameters that allow you to connect as SYSDBA through Net8, as needed. When duplicating to the same host or to a new host with a different filesystem, pay special attention to all parameters specifying pathnames.
Following are examples of the init.ora
parameter settings for the duplicate database:
DB_NAME=newdb CONTROL_FILES=(/oracle/dup_prod/cf/cf1.f,/oracle/dup_prod/cf/cf2.log) DB_FILE_NAME_CONVERT=(/oracle/prod/db,/oracle/dup_prod/db) LOG_FILE_NAME_CONVERT=("/oracle/prod/log","/oracle/dup_prod/log")
See Also: For more information about Net8, see the Net8 Administrator's Guide.
Before beginning RMAN duplication, use SQL*Plus to connect to the auxiliary instance and start it in NOMOUNT mode (specifying a parameter file if necessary). In this example, aux_pwd is the password for the user with SYSDBA authority and aux_str is the net service name for the auxiliary instance:
SQL> connect sys/aux_pwd@aux_str SQL> startup nomount pfile='/oracle/aux/dbs/initAUX.ora';
Because the auxiliary instance does not yet have a control file, you can only start the instance in NOMOUNT mode. Do not create a control file or try to mount or open the auxiliary instance.
The auxiliary instance must be accessible via Net8. Before proceeding, use SQL*Plus to ensure that you can establish a connection to the auxiliary instance. Note that you must connect to the auxiliary instance with SYSDBA privileges, so a password file must exist.
Before beginning RMAN duplication, open the target database (specifying a parameter file if necessary) if it is not already open. For example, enter:
SQL> startup pfile='/oracle/dbs/initPROD1.ora';
Use one of the following methods to start the RMAN command line interface:
You must connect to the auxiliary instance with SYSDBA privileges, so you must use a password file. To connect to the auxiliary instance, target instance, and recovery catalog, supply the following information when starting up Recovery Manager:
% rman target sys/target_pwd@target_str catalog rman/cat_pwd@cat_str auxiliary \
> sys/aux_pwd@aux_str
Where:
You can start the RMAN command line interface without a connection to the auxiliary instance, and then use the connect auxiliary command at the RMAN prompt to make the auxiliary connection:
% rman RMAN> connect auxiliary sys/aux_pwd@aux_str RMAN> connect target sys/target_pwd@target_str
RMAN> connect catalog rman/cat_pwd@cat_str
Make sure you have backups all the datafiles in your target database. If you do not have backups of everything, the duplicate operation will fail. The database backup does not have to be a whole database backup: you can use a mix of full and incremental backups of individual datafiles.
Make sure that you have enough backups of all the archived redo logs necessary to recover to the desired time, SCN, or log sequence number.
Before issuing the duplicate command, allocate at least one auxiliary channel within the same run command. The channel type (disk or 'sbt_tape') must match the media where the backups of the target database are located. If the backups reside on disk, then the more channels you allocate, the faster the duplication will be. For tape backups, limit the number of channels to the number of devices available for the operation.
run { # to allocate a channel of type 'sbt_tape' issue: allocate auxiliary channel ch1 type 'sbt_tape'; # to allocate three auxiliary channels for disk issue (specifying whatever channel # id that you want): allocate auxiliary channel aux1 type disk; allocate auxiliary channel aux2 type disk; allocate auxiliary channel aux3 type disk; . . . }
When you create your duplicate database, you have the following options:
The simplest case is to duplicate your database to a different host and to use the exact same directory structure. In this case, you do not need to change the init.ora
file or set new filenames for the duplicate database datafiles.
To create a duplicate database on a different host with the same filesystem:
SQL> startup nomount pfile=initDUPDB.ora;
SQL> startup pfile=initPROD1.ora;
% rman target / auxiliary sys/sys_pwd@dupdb
In this example, user SCOTT has SYSDBA privileges and a net service name is used for the target:
% rman auxiliary scott/tiger@dupdb target sys/sys_pwd@prod
In this example, connection is established to three databases, all using net service names:
% rman catalog rman/rman@rcat target sys/sys_pwd@prod1 auxiliary scott/tiger@dupdb
For example, enter the following:
run { allocate auxiliary channel ch1 type 'sbt_tape'; duplicate target database to dupdb nofilenamecheck; }
If you create your duplicate database on a host with a different filesystem, you need to change several init.ora
file parameters and generate new filenames for the duplicate database datafiles.
Use LOG_FILE_NAME_CONVERT or the logfile clause to convert the online redo log filenames. Use DB_FILE_NAME_CONVERT, the set newname command, or the set auxname command for the datafile filenames.
See Also: For a table of the various datafile filename conversion options, see Table 10-2.
To duplicate a database with DB_FILE_NAME_CONVERT and LOG_FILE_NAME_CONVERT:
tbs_*
to duptbs_*
.
log_*
to duplog_*
.
SQL> startup nomount pfile=initDUPDB.ora;
SQL> startup pfile=initPROD1.ora;
% rman target / auxiliary sys/sys_pwd@dupdb
In this example, user SCOTT has SYSDBA privileges and a net service name is used for the target:
% rman auxiliary scott/tiger@dupdb target sys/sys_pwd@prod
In this example, connection is established to three databases, all using net service names:
% rman catalog rman/rman@rcat target sys/sys_pwd@prod1 auxiliary scott/tiger@dupdb
run { allocate auxiliary channel ch1 type 'sbt_tape'; duplicate target database to dupdb; }
To duplicate a database with DB_FILE_NAME_CONVERT and the logfile clause:
Follow the same procedure for creating a duplicate database using the parameter LOG_FILE_NAME_CONVERT, but make the following substitutions:
run { allocate auxiliary channel ch1 type 'sbt_tape'; duplicate target database to dupdb logfile '/oracle/dbs/log1.f' size 200K, '/oracle/dbs/log2.f' size 200K; }
To duplicate a database using the set newname command:
SQL> startup nomount pfile=initDUPDB.ora;
SQL> startup pfile=initPROD1.ora;
% rman target / auxiliary sys/sys_pwd@dupdb
In this example, user SCOTT has SYSDBA privileges and a net service name is used for the target:
% rman auxiliary scott/tiger@dupdb target sys/sys_pwd@prod
In this example, connection is established to three databases, all using net service names:
% rman catalog rman/rman@rcat target sys/sys_pwd@prod1 auxiliary scott/tiger@dupdb
For example, enter the following:
run { # allocate at least one auxiliary channel of type disk or tape allocate auxiliary channel dupdb1 type 'sbt_tape'; . . . # set new filenames for the datafiles set newname for datafile 1 TO '$ORACLE_HOME/dbs/dupdb_data_01.f'; set newname for datafile 2 TO '$ORACLE_HOME/dbs/dupdb_data_02.f'; . . . # issue the duplicate command duplicate target database to dupdb # create at least two online redo log groups logfile group 1 ('$ORACLE_HOME/dbs/dupdb_log_1_1.f', '$ORACLE_HOME/dbs/dupdb_log_1_2.f') size 200K, group 2 ('$ORACLE_HOME/dbs/dupdb_log_2_1.f', '$ORACLE_HOME/dbs/dupdb_log_2_2.f') size 200K; }
To duplicate a database using the set auxname command:
SQL> startup nomount pfile=initDUPDB.ora;
SQL> startup pfile=initPROD1.ora;
% rman target / auxiliary sys/sys_pwd@dupdb
In this example, user SCOTT has SYSDBA privileges and a net service name is used for the target:
% rman auxiliary scott/tiger@dupdb target sys/sys_pwd@prod
In this example, connection is established to three databases, all using net service names:
% rman catalog rman/rman@rcat target sys/sys_pwd@prod1 auxiliary scott/tiger@dupdb
# set auxiliary names for the datafiles set auxname for datafile 1 to '/oracle/auxfiles/aux_1.f'; set auxname for datafile 2 to '/oracle/auxfiles/aux_2.f'; ... set auxname for datafile n to '/oracle/auxfiles/aux_n.f';
run { # allocate at least one auxiliary channel of type disk or tape allocate auxiliary channel dupdb1 type 'sbt_tape'; . . . # issue the duplicate command duplicate target database to dupdb . . . # create at least two online redo log groups logfile group 1 ('$ORACLE_HOME/dbs/dupdb_log_1_1.f', '$ORACLE_HOME/dbs/dupdb_log_1_2.f') size 200K, group 2 ('$ORACLE_HOME/dbs/dupdb_log_2_1.f', '$ORACLE_HOME/dbs/dupdb_log_2_2.f') size 200K; }
# un-specify auxiliary names for the datafiles set auxname for datafile 1 to null; set auxname for datafile 2 to null; ... set auxname for datafile n to null;
When creating a duplicate database on the same host as your target database, follow the same procedure as for duplicating to a remote host with a different directory structure ("Duplicating a Database on a Remote Host with a Different Directory Structure").
Note that you can duplicate your database to the same $ORACLE_HOME as your target, but you must convert the filenames using the same methods used for conversion on a separate host.
Following are some useful scenarios for creating a duplicate database:
This example assumes the following:
/oracle/dbs
sub-directory and use the tbs_*
prefix for each datafile.
connect target; connect catalog rman/rman@rcat; connect auxiliary sys/change_on_install@dupdb; run { allocate auxiliary channel dupdb1 type disk; allocate auxiliary channel dupdb2 type disk; allocate auxiliary channel dupdb3 type disk; allocate auxiliary channel dupdb4 type disk; set newname for datafile 1 TO '$ORACLE_HOME/dbs/tbs_01.f'; set newname for datafile 2 TO '$ORACLE_HOME/dbs/tbs_02.f'; set newname for datafile 3 TO '$ORACLE_HOME/dbs/tbs_03.f'; set newname for datafile 4 TO '$ORACLE_HOME/dbs/tbs_04.f'; set newname for datafile 5 TO '$ORACLE_HOME/dbs/tbs_05.f'; set newname for datafile 6 TO '$ORACLE_HOME/dbs/tbs_06.f'; set newname for datafile 7 TO '$ORACLE_HOME/dbs/tbs_07.f'; set newname for datafile 8 TO '$ORACLE_HOME/dbs/tbs_08.f'; set newname for datafile 9 TO '$ORACLE_HOME/dbs/tbs_09.f'; duplicate target database to dupdb logfile group 1 ('$ORACLE_HOME/dbs/log_1_1.f', '$ORACLE_HOME/dbs/log_1_2.f') size 200K reuse, group 2 ('$ORACLE_HOME/dbs/log_2_1.f', '$ORACLE_HOME/dbs/log_2_2.f') size 200K reuse; }
This example makes the same assumptions as in "Setting New Filenames Manually". Additionally, it assumes that you want to update your duplicate database daily so that it stays current with the target database.
# start RMAN and then connect to the databases connect target / connect catalog rman/rman@rcat connect auxiliary sys/change_on_install@dupdb # set auxiliary names for the datafiles only once set auxname for datafile 1 TO '$ORACLE_HOME/dbs/tbs_01.f'; set auxname for datafile 2 TO '$ORACLE_HOME/dbs/tbs_02.f'; set auxname for datafile 3 TO '$ORACLE_HOME/dbs/tbs_03.f'; set auxname for datafile 4 TO '$ORACLE_HOME/dbs/tbs_04.f'; set auxname for datafile 5 TO '$ORACLE_HOME/dbs/tbs_05.f'; set auxname for datafile 6 TO '$ORACLE_HOME/dbs/tbs_06.f'; set auxname for datafile 7 TO '$ORACLE_HOME/dbs/tbs_07.f'; set auxname for datafile 8 TO '$ORACLE_HOME/dbs/tbs_08.f'; set auxname for datafile 9 TO '$ORACLE_HOME/dbs/tbs_09.f'; # Create the duplicate database. Issue the same command daily # to re-create the database, thereby keeping the duplicate # in sync with the target. run { # allocate auxiliary channels allocate auxiliary channel dupdb1 type disk; allocate auxiliary channel dupdb2 type disk; allocate auxiliary channel dupdb3 type disk; allocate auxiliary channel dupdb4 type disk; duplicate target database to dupdb logfile group 1 ('$ORACLE_HOME/dbs/log_1_1.f', '$ORACLE_HOME/dbs/log_1_2.f') size 200K reuse, group 2 ('$ORACLE_HOME/dbs/log_2_1.f', '$ORACLE_HOME/dbs/log_2_2.f') size 200K reuse; }
This example assumes the following:
connect target sys/change_on_install@prod1 connect auxiliary sys/sysdba@dupdb run { set until time 'sysdate-7'; allocate auxiliary channel dupdb1 type 'sbt_tape'; allocate auxiliary channel dupdb2 type 'sbt_tape'; duplicate target database to dupdb nofilenamecheck; }