EXIT FROM RMAN, AND USE SQL*PLUS TO QUERY SOME VIEWS THAT WILL CONFIRM THAT THE TARGET HAS BEEN REGISTERED AND THAT BACKUPS HAVE BEEN MADE

9. Exit from RMAN, and use SQL*Plus to query some views that will confirm

that the target has been registered and that backups have been made:

sqlplus rman/rman@catdbSQL> select dbid,name from rc_database;SQL> select db_id,bs_key,backup_type from rc_backup_set;

Stored Scripts

RMAN scripts can be stored as operating system files, and invoked from the command line.

For example, if these two commands are saved into a file named rman_script.rmn,

run {backup database plus archivelog delete all input;delete obsolete;}

then the script can be invoked from an operating system prompt as follows:

rman target / catalog rman/rman@catdb @rman_script.rmn

However, if you have a catalog, you can use it to store scripts. There are six script-

related commands:

create [ global ] scriptreplace [ global ] scriptprint [ global ] scriptlist [ global ] script namesexecute [ global ] scriptdelete [ global ] script

TIP There is no command to edit a script. However, you can query the views

RC_STORED_SCRIPT and RC_STORED_SCRIPT_LINE to view scripts, and

edit them by using DML against these views. Of course, you bypass all the

syntax checking if you do this. The views will not show global scripts.

The commands are all self-explanatory. By default, scripts are database-specific. If

you want to run the same script against many targets, you must connect to each target

and create it many times. But if the GLOBAL keyword is used, then the script will be

visible to all targets. While global scripts are very useful, care must be taken to ensure

that they will run against any target you wish. For example, if a script includes a FORMAT

clause to name the backup pieces, the path element of the piece name would have to be

different for Unix targets and Windows targets because of the different form of the

directory delimiter on these operating systems. Extensive use of the CONFIGURE

command will allow more use of global scripts, because the scripts behavior will

then be modified transparently by each target.

TIP You can convert RMAN scripts stored as operating system files to scripts

stored within the catalog with this command:

create script script_name from file 'file_name';

Figure 17-3 demonstrates the creation and running of a stored script. Note the

automatic resync of the recovery catalog: this will update the catalog with any changes

Figure 17-3 Creating and executing an RMAN stored script

that have occurred since the last resync, such as datafile adjustments and archivelog

generation, so that the catalog will be aware of the current state of the database.

Using RMAN to Create Databases

To clarify some naming conventions, the target database is the existing database you

want to copy. The auxiliary database is the new database created from the target. The

target and the auxiliary may be on the same server or on different machines. The

examples that follow assume that you are duplicating a database and instance named

orcl to a database and instance named newdb.

Here are the general steps to follow to create a duplicate database:

P AR T III