RMAN Client

Starting and Exiting RMAN

RMAN client on Linux is located in $ORACLE_HOME/bin.

rman

rman target /

rman target sys/*****@orcl nocatalog

rman target / catalog rcat/****@cdb

To quit RMAN and terminate the program, enter EXIT or QUIT at the RMAN prompt:

RMAN> EXIT
or
RMAN> QUIT

Specifying the Location of RMAN Output

By default, RMAN writes command output to standard output. To redirect output to a log file, enter the LOG parameter on the command line when starting RMAN, as in the following example:

% rman LOG /tmp/rman.log
-bash-3.2$ rman LOG /tmp/rman.log
RMAN> show all;
RMAN> quit
-bash-3.2$ cat /tmp/rman.log

Recovery Manager: Release 11.2.0.3.0 - Production on Sat Sep 7 14:33:28 2013

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

RMAN>
using target database control file instead of recovery catalog
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of show command at 09/07/2013 14:33:33
RMAN-06171: not connected to target database

RMAN>

Recovery Manager complete.

In this case, RMAN displays command input but does not display the RMAN output.

The easiest way to send RMAN output both to a log file and to standard output is to use the Linux tee command or its equivalent. For example, the following technique enables both input and output to be visible in the RMAN command-line interface:

% rman | tee rman.log
RMAN>

Setting Globalization Support Environment Variables for RMAN

Before invoking RMAN, it may be useful to set the NLS_DATE_FORMAT and NLS_LANG environment variables. These variables determine the format used for the time parameters in RMAN commands such as RESTORE, RECOVER, and REPORT.

The following example shows typical language and date format settings:

NLS_LANG=american
NLS_DATE_FORMAT='Mon DD YYYY HH24:MI:SS'

If you are going to use RMAN to connect to an unmounted database and mount the database later while RMAN is still connected, then set the NLS_LANG environment variable so that it also specifies the character set used by the database.

A database that is not mounted assumes the default character set, which is US7ASCII. If your character set is different from the default, then RMAN returns errors after the database is mounted. For example, if the character set is WE8DEC, then to avoid errors, you can set the NLS_LANG variable as follows:

NLS_LANG=american_america.we8dec

In order for the environment variable NLS_DATE_FORMAT to be applied and override the defaults set for the server in the server initialization file, the environment variable NLS_LANG must also be set.

Entering RMAN Commands

Entering RMAN Commands at the RMAN Prompt

RMAN> CONNECT TARGET
RMAN> BACKUP DATABASE;

Note:-
Most RMAN commands take a number of parameters and must end with a semicolon. Some commands, such as STARTUP, SHUTDOWN, and CONNECT, can be used with or without a semicolon.

When you enter a line of text that is not a complete command, RMAN prompts for continuation input with a line number. For example:

RMAN> BACKUP DATABASE
2> INCLUDE CURRENT
3> CONTROLFILE
4> ;

Using Command Files with RMAN
For repetitive tasks, you can create a text file containing RMAN commands, and start the RMAN client with the @ argument, followed by a filename

vi cmdfile1
BACKUP DATABASE PLUS ARCHIVELOG;
:wq!

% rman TARGET / @cmdfile1
Note:- After the command completes, RMAN exits.

You can also use the @ command at the RMAN command prompt to execute the contents of a command file during an RMAN session. RMAN reads the file and executes the commands in it. For example:

RMAN> @cmdfile1
After the command file contents have been executed, RMAN displays the following message:

RMAN>  **end-of-file**

Entering Comments in RMAN Command Files

The comment character in RMAN is a pound sign (#).
All text from the pound sign to the end of the line is ignored. For example, the following command file contents backs up the database and archived redo log files and includes comments:

# Command file name: mybackup.rman
# The following command backs up the database
BACKUP DATABASE;
# The following command backs up the archived redo logs
BACKUP ARCHIVELOG ALL;

The following example shows that you can break a single RMAN command across multiple lines:

RMAN> BACKUP # this is a comment
2> SPFILE;

Using Substitution Variables in Command Files

When running a command file, you can specify one or more values in a USING clause for use in substitution variables in a command file. In this way, you can make your command files dynamic.

To create and use a dynamic shell script:

1.Create an RMAN command file that uses substitution variables.

The following example shows the contents of a command file named quarterly_backup.cmd, which is run every quarter. The script uses substitution variables for the name of the tape set, for a string in the FORMAT specification, and for the name of the restore point to be created.

# quarterly_backup.cmd
CONNECT TARGET /
RUN
{
  ALLOCATE CHANNEL c1
    DEVICE TYPE sbt
    PARMS 'ENV=(OB_MEDIA_FAMILY=&1)';
  BACKUP DATABASE
    TAG &2
    FORMAT '/disk2/bck/&1%U.bck'
    KEEP FOREVER
    RESTORE POINT &3;
}
EXIT;

2.Create a shell script that you can use to run the RMAN command file created in the previous step.

The following example creates a shell script named runbackup.sh. The example creates shell variables for the format and restore point name and accepts the values for these variables as command-line arguments to the script.

#!/bin/tcsh
# name: runbackup.sh
# usage: use the tag name and number of copies as arguments
set media_family = $argv[1]
set format = $argv[2]set restore_point = $argv[3]
rman @'/disk1/scripts/whole_db.cmd' USING $media_family $format $restore_point


3.Execute the shell script created in the previous step, specifying the desired arguments on the command line.

The following example runs the runbackup.sh shell script and passes it archival_backup as the media family name, bck0906 as the format string, and FY06Q3 as the restore point name.

% runbackup.sh archival_backup bck0906 FY06Q3

Checking RMAN Syntax

You may want to test RMAN commands for syntactic correctness without executing them. Use the command-line argument CHECKSYNTAX to start the RMAN client in a mode in which it only parses the commands that you enter and returns an RMAN-00558 error for commands that are not legal RMAN syntax.

To check RMAN syntax at the command line:

1.Start RMAN with the CHECKSYNTAX parameter.
For example, enter the following commands:

% rman CHECKSYNTAX
2.Enter the RMAN commands to be tested.

The following shows a sample interactive session, with user-entered text in bold.

RMAN> run [ backup database; ]

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01006: error signaled during parse
RMAN-02001: unrecognized punctuation symbol "["

RMAN> run { backup database; }

The command has no syntax errors

RMAN>

To test commands in a command file:

1.Use a text editor to create a command file.
Assume that you create the /tmp/goodcmdfile with the following contents:
# command file with legal syntax
RESTORE DATABASE;
RECOVER DATABASE;
Assume that you create another command file, /tmp/badcmdfile, with the following contents:

# command file with bad syntax commands
RESTORE DATABASE
RECOVER DATABASE
2.Run the command file from the RMAN prompt in the following format, where filename is the name of the command file:

% rman CHECKSYNTAX @filename
The following example shows the output when you run /tmp/goodcmdfile with CHECKSYNTAX:

RMAN> # command file with legal syntax
2> restore database;
3> recover database;
4>
The cmdfile has no syntax errors

Recovery Manager complete.
In contrast, the following example shows the output when you run /tmp/badcmdfile with CHECKSYNTAX:

RMAN> #command file with syntax error
2> restore database
3> recover
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01005: syntax error: found "recover": expecting one of: "archivelog,
channel, check, controlfile, clone, database, datafile, device,
from, force, high, (, preview, ;, skip, spfile, standby, tablespace,
until, validate"
RMAN-01007: at line 3 column 1 file: /tmp/badcmdfile

Making Database Connections with RMAN

To perform useful work, the RMAN client must connect to a database. The following table describes the types of database connections that you can make with RMAN.

Type of Database Connection Keyword Description
target database TARGET A database to be backed up or restored by RMAN
recovery catalog database CATALOG A database that provides an optional backup store for the RMAN repository in addition to the control file.
auxiliary instance or auxiliary database AUXILIARY A physical standby database, or a database instance created for performing a specific task such as creating a duplicate database, transporting tablespaces, or performing tablespace point-in-time recovery (TSPITR).For many tasks that use an auxiliary database, RMAN creates an automatic auxiliary instance for use during the task, connects to it, performs the task, and then destroys it when the task is completed. You do not give any explicit command to connect to automatic auxiliary instances.

Authentication for RMAN Database Connections

RMAN connections to a database are specified and authenticated in the same way as SQL*Plus connections to a database. The only difference is that RMAN connections to a target or auxiliary database require the SYSDBA privilege. The AS SYSDBA keywords are implied for target and auxiliary connections and cannot be explicitly specified.

A SYSDBA privilege is not required when connecting to the recovery catalog. You must grant the RECOVERY_CATALOG_OWNER role to the catalog schema owner

Connecting to a Target Database from the System Prompt
#operating system authentication
% rman TARGET / NOCATALOG

connected to target database: PROD (DBID=39525561)
using target database control file instead of recovery catalog

RMAN>
#pwd file authentication and uses Oracle Net authentication
% rman TARGET SYS@prod NOCATALOG

target database Password: password
connected to target database: PROD (DBID=39525561)

RMAN>

#Connecting to Target and Catalog Databases

% rman TARGET SYS@prod CATALOG rco@catdb

target database Password: password
connected to target database: PROD (DBID=39525561)
recovery catalog database Password: password
connected to recovery catalog database

RMAN>

To make a database connection from the RMAN prompt:

% rman
RMAN> CONNECT TARGET /
RMAN> CONNECT CATALOG rco@catdb

recovery catalog database Password: password
connected to recovery catalog database

% rman
RMAN> CONNECT TARGET SYS@prod

target database Password: password
connected to target database: PROD (DBID=39525561)

Connecting RMAN to an Auxiliary Database

% rman
RMAN> CONNECT TARGET /
RMAN> CONNECT AUXILIARY SYS@aux

auxiliary database Password: password
connected to auxiliary database: PROD (DBID=30472568)

Making RMAN Database Connections Within Command Files

cat > listbkup.rman << EOF
CONNECT TARGET /
LIST BACKUP;
EOF

Diagnosing RMAN Connection Problems

TO reproduce RMAN behavior with sqlplus

For example, suppose that the following RMAN command encountered connection errors:

RMAN> CONNECT TARGET /
You reproduce the preceding connection attempt with the SQL*Plus command as follows:

SQL> CONNECT / AS SYSDBA

Using the RMAN Pipe Interface
rman_pipes_sql.pdf
rman_pipes_spool.pdf

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s