Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Oracle Database 11g.pdf
Скачиваний:
77
Добавлен:
10.06.2015
Размер:
12.69 Mб
Скачать

214  Chapter 5  n  Using the RMAN Recovery Catalog

E x e r c i s e 5 .1   ( c o n t i n u e d )

6.Test to see whether you can connect to the recovery-catalog schema that you have just created:

SQL> connect rcat_user/rcat_user Connected.

7.Now you need to create the recovery-catalog schema. To do this, use the create catalog command as shown in this example:

C:\Documents and Settings\Robert>Rman catalog=rcat_user/rcat_user@rcat Recovery Manager: Release 11.1.0.6.0 - Production on

Mon Sep 15 23:10:13 2008

Copyright (c) 1982, 2007, Oracle. All rights reserved. connected to recovery catalog database

RMAN> create catalog recovery catalog created

Some texts may show you granting connect or resource roles to the recovery catalog–schema owner. This is not required in Oracle Database 11g and may represent a security risk.

Using a Recovery Catalog

Using a recovery catalog is pretty straightforward with RMAN. You simply indicate that you want to connect to the recovery catalog when you start RMAN. You will also have to register the database before your first RMAN operation when connected to the recovery catalog. Most RMAN operations when connected to the recovery catalog are pretty much the same; it’s just that RMAN metadata will now be stored in both the control file and the recovery catalog. In the following sections, we will discuss these topics:

NN

Connecting to the recovery catalog from RMAN

NN

Registering the database with the recovery catalog

 

NN

Unregistering a database from the recovery catalog

Connecting to the Recovery Catalog from RMAN

When you start RMAN, you will need to indicate that you want to connect to a recovery catalog if you want the session to use the recovery catalog. There are a couple of ways of

Using a Recovery Catalog 

215

connecting to the recovery catalog. The first is to use the catalog RMAN command-line parameter, as shown in this example:

C:\Documents and Settings\Robert>Set oracle_sid=orcl C:\Documents and Settings\Robert>Rman target=sys/Robert catalog=rcat_user/rcat_user@rcat

Recovery Manager: Release 11.1.0.6.0 - Production on Mon Sep 15 22:17:11 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved.

connected to target database (not started) connected to recovery catalog database RMAN>

Note the use of the terms target and catalog. As we first mentioned in Chapter 4, the database you are intending to back up is called the target database. In the previous example, you connected directly to the target database with RMAN. At the same time, you connected to the catalog database through Oracle Net. If you desired, you could connect directly to the catalog database and connect to the target database via Oracle Net, or you could connect to both databases via Oracle Net. Since the server itself does the backup work via locally allocated channels, connecting to the server or the recovery catalog through Oracle Net should not impose any undue performance constraints on the performance of your backups.

Another way of connecting to the recovery catalog is to do so from the RMAN commandline prompt using the connect command, as shown in this example:

C:\Documents and Settings\Robert>Rman target=sys/Robert

Recovery Manager: Release 11.1.0.6.0 - Production on Mon Sep 15 22:18:05 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved.

connected to target database (not started) RMAN> Connect catalog rcat_user/rcat_user@rcat connected to recovery catalog database

Registering the Target Database with the Recovery Catalog

Once you have connected to the recovery catalog, you will have to register the database with the register database command. To be registered, the database must be mounted or open. In this example, you connect to the target database and the recovery catalog and then register the database with the recovery catalog:

C:\Documents and Settings\Robert>Rman target=sys/Robert catalog=rcat_user/rcat_user@rcat

216  Chapter 5  n  Using the RMAN Recovery Catalog

Recovery Manager: Release 11.1.0.6.0 - Production on Mon Sep 15 23:12:51 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved.

connected to target database: ORCL (DBID=1190537904, not open) connected to recovery catalog database

RMAN> register database;

database registered in recovery catalog starting full resync of recovery catalog full resync complete

Unregistering a Database

If you are preparing to remove a database, you will want to remove its metadata from the recovery catalog. This is done with the unregister command, as shown in this example:

C:\Documents and Settings\Robert>Rman target=sys/Robert catalog=rcat_user/rcat_user@rcat

Recovery Manager: Release 11.1.0.6.0 - Production on Mon Sep 15 23:13:45 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved.

connected to target database: ORCL (DBID=1190537904, not open) connected to recovery catalog database

RMAN> unregister database;

database name is “ORCL” and DBID is 1190537904

Do you really want to unregister the database (enter YES or NO)? yes database unregistered from the recovery catalog

Unregistering a database from the recovery catalog will cause all recovery catalog–related records to be removed from the recovery catalog. Control-file records for that database will be retained, of course. You might have had older backup records stored in the recovery catalog, though. When you unregister a database, those old records will be lost if the age of the backups exceeds the setting of the CONTROL_FILE_RECORD_KEEP_TIME parameter. Also, any scripts related to the database in the recovery catalog will be lost (we will talk more about scripting later in this chapter).

Using Scripts in the RMAN

Recovery Catalog

One benefit of the recovery catalog is the ability to store RMAN scripts. In the following sections, these topics will be addressed:

NN

Executing external scripts

NN

Creating stored scripts

Using Scripts in the RMAN Recovery Catalog 

217

NN

Replacing stored scripts

 

NN

Removing stored scripts

 

NN

Executing stored scripts

 

NN

Printing stored scripts

 

NN

Using script-substitution variables

 

Executing External Scripts

RMAN provides the ability to execute external scripts. You can do so from the RMAN command line using the cmdfile option, as shown here:

Rman target=/ cmdfile=run_me.rman

You can also run an external script from within RMAN using the @ command, as shown here:

RMAN> @run_me.rman

Creating Stored Scripts

Recovery catalog stored scripts provide the ability to centrally manage your backup and recovery scripts. Using global stored scripts allows you to use common scripts across the entire enterprise.

Use the create script RMAN command to store scripts in the recovery catalog. You will assign a name to the stored script when you create it. Stored scripts can be created to do many RMAN operations, including backups, recoveries, and database-maintenance operations. As mentioned earlier, you must be connected to the recovery catalog to be able to create a script.

Here is an example of using the create script command to create a script. This script does a backup of the database and the archived redo logs:

create script db_backup_script

{ backup database plus archivelog delete input;}

Note that if you are using virtual private catalogs (see more on these later in this chapter), you will need to create the script as a global script as shown here:

create global script db_delete_obsolete { delete obsolete;}

218  Chapter 5  n  Using the RMAN Recovery Catalog

Replacing Stored Scripts

The replace script command is used to replace stored RMAN scripts. The following example demonstrates the use of the replace script command:

Replace script db_delete_obsolete { delete noprompt obsolete;}

Removing Stored Scripts

If you need to remove a stored script permanently, you can use the delete script command as shown here:

Delete script db_delete_obsolete;

Executing Stored Scripts

Once you have created the script, it might be nice to actually run it! To run the script, you will use the execute script command. This command must be run within the confines of an RMAN run block, as shown in this example:

Run {execute script db_delete_obsolete;}

Printing Stored Scripts

The print script command will print your script to the standard output device, allowing you to cut and paste its contents. Here is an example of the print script command:

RMAN> Print script db_delete_obsolete; printing stored script: db_delete_obsolete { delete obsolete;}

Using Script Substitution Variables

Oracle Database 11g provides for the use of substitution variables in RMAN scripts or command files. You define the substitution variables using the ampersand (&) character followed by a number, as shown in this example:

Restore database from tag &1;

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]