$ $ORACLE_HOME/bin/rman
RMAN-related records in the target database’s control file are overwritten after seven days, but
you can control the length of retention by setting a higher value for the initialization parameter
control_file_record_keep_time.
SQL> show parameter control_file_record_keep_time;
NAME TYPE
------------------------------------ --------------------------------
VALUE
------------------------------
control_file_record_keep_time integer
7
Problem
You’d like to start working with RMAN and issue the various RMAN commands to back up
your database and to manage those backups.
Solution
RMAN uses a free-form command language. Each RMAN command statement starts with a
keyword, is followed by specific arguments, and ends with a semicolon. A command can be
one line or multiple lines. For example, the following single-line command initiates a backup
of the target database:
RMAN> backup database;
RMAN> backup database
2> include current
3> controlfile
4> ;
You can add comments to your RMAN commands, which makes it easy to follow the logic
of your RMAN commands when you use several of them inside a command file (we discuss
RMAN command files later in this chapter). Each comment must be preceded by the # sign
# this command will be run daily
backup incremental level 1
for recover of copy # uses incrementally updated backups
database;
Problem
You want to save the output of an RMAN session to a text file.
Solution
how to use the spool command:
spool log to '/tmp/rman/backuplog.f';
backup datafile 1;
spool log off;
spool log to '/tmp/rman/backuplog.f' append.
Problem
You want to log the output of RMAN commands you issue in command-line mode.
Solution
If you want RMAN to log all its output when you use RMAN from the operating system command
line, just add the keyword log to the command line, and supply the name of the log file
to use. For example:
$ rman target / cmdfile commandfile1.rcv log /u01/app/oracle/outfile.txt
$ rman target / cmdfile commandfile2.rcv log /u01/app/oracle/outfile.txt append
connect to your target database from the RMAN prompt.
RMAN> connect target /
Connected to target database: POWER (DBID=922224687)
And here’s an example showing how to log in using a database username and password
that are authenticated against the password file:
$ rman
Recovery Manager: Release 11.1.0.1.0 - Beta on Mon Apr 2 08:31:11 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
RMAN> connect target sys/password@power
$ orapwd
Usage: orapwd file=
ignorecase=
where
file - name of password file (required),
password - password for SYS (required),
entries - maximum number of distinct DBA (required),
force - whether to overwrite existing file (optional),
ignorecase - passwords are case-insensitive (optional),
nosysdba - whether to shut out the SYSDBA logon (optional Database Vault only).
Example
$ orapwd file=mydb_pwd password=sammyy1 entries=20
remote_login_passwordfile = 'EXCLUSIVE'
Executing Operating System Commands from Within RMAN
In the following example, we use the host command to list all files ending with dbf, after
backing up a datafile from the RMAN prompt:
RMAN> shutdown immediate;
RMAN> startup mount;
RMAN> backup datafile '/u01/app/oracle/oradata/targ/system01.dbf'
format '/tmp/system01.dbf';
RMAN> host 'ls -l /tmp/*dbf';
RMAN> alter database open;
The following example uses the host command with no parameters to temporarily escape
to the operating system level during an interactive RMAN session:
RMAN> backup datafile 3 format '/u01/app/oracle/oradata/targ_db/dbs01.cpy';
RMAN> host;
$ ls $ORACLE_HOME/oradata/dbs01.cpy
/net/oracle/oradata/dbs01.cpy
$ exit
RMAN>
CRON DE RMAN
#!/bin/ksh
1 export ORACLE_SID=$1
2 rman target / catalog rman/rman@rcat > ${LOGFILE} <<- EOF
3 sql 'alter system archive log current';
4 change archivelog all crosscheck;
5 allocate channel for maintenance type disk;
6 delete noprompt expired archivelog all;
7 run {
8 allocate channel ch1 type disk format
9 '${BACKUP_DIR}/%d_level${LEVEL}_${TIMESTAMP}_%s_U%U.bak';
10 set limit channel ch1 kbytes=2000000;
11 backup incremental level ${LEVEL} (database);
12 release channel ch1;
13 resync catalog;
14 }
15 EOF
you can invoke RMAN from the command line to execute those files. For example, suppose
you have a file called full_backup.rman consisting of the following run block:
run {
allocate channel d1 type disk;
backup full database format '/export/rman/rman_%n_%T_%s_%p.bus';
}
You can then invoke RMAN from the operating system command line to execute this file
as follows:
$ rman target / @full_backup.rman
$ rman target / cmdfile commandfile.rcv
$ rman target / cmdfile /oracle/dbs/cmd/commandfile.rcv
$ rman target / @commandfile.rcv
Creating Dynamic Command Files
1. Create the RMAN command file that uses two substitution variables:
#backup.cmd
connect target sys/
run {
backup database
tag &1
format &2
}
exit;
The command file shown here will back up the database using two substitution variables
(&1 and &2), one for the backup tag and the other for the string value in the
format specification.
2. Create the shell script to run the backup command file you created in step 1:
#!/bin/tcsh
# script name: nightly_backup.sh
set tag=$argv(1)
set format=$argv[2]
rman @backup.cmd using $tag $format
3. Now that you have created a dynamic shell script, you can specify the arguments for
the tag and format variables on the command line, thus being able to modify them for
different jobs. Here’s an example:
$ nightly_backup.sh longterm_backup back0420
Connecting to an Auxiliary Database
$ rman auxiliary sys/
You can also start the RMAN client first and then connect to the auxiliary instance from
the RMAN prompt, as shown in this example:
$ rman
RMAN> connect auxiliary sys/
RMAN> connect target sys/
RMAN> connect catalog rman/
RMAN> connect auxiliary sys/
The following example shows how you can connect to all three types of database in one
go from the operating system command line:
% rman target sys/oracle@trgt catalog rman/cat@catalog auxiliary sys/aux@aux
Executing Multiple RMAN Commands As a Single Unit
run
{
allocate channel t1 device type disk format '/disk1/%U';
allocate channel t2 device type disk format '/disk2/%U';
backup database;
}
Here’s one more example, this time showing how you use the set command to temporarily
change the value of a parameter within a run block. Let’s say you configured datafile copies
to three using the following command:
RMAN> configure datafile backup copies for device type sbt to 3;
You can override the default of three copies by using the following run block, where the
set command sets the number of backup copies to only two. You’ll thus get two copies of each
datafile and archived log that’s part of the backup.
run
{
allocate channel dev1 device type sbt;
set backup copies = 2;
backup datafile 1,2,3,4,5;
backup archivelog all;
}
RMAN commands dealing with configuration and environmental settings within a run
block.
For example, you can’t use the following commands from within a run block:
connect, configure, create catalog, drop catalog, upgrade catalog
create script, delete script, replace script, list, report
RMAN> SQL 'alter system archive log all';
run
{
SQL "alter tablespace tools offline immediate";
restore tablespace tools;
recover tablespace tools;
SQL "alter tablespace tools online";
}
RMAN> connect target /
RMAN> connect catalog rman/rman@catdb
RMAN> startup nomount;
RMAN> restore controlfile;
RMAN> alter database mount;
RMAN> recover database;
RMAN> alter database open resetlogs;
set DBID 1296234570;
RMAN> startup dba pfile=/tmp/initprod1.ora;
Checking the Syntax of RMAN Commands
$. /rman checksyntax
Recovery Manager: Release 11.1.0.1.0 - Beta on Mon Apr 2 08:31:11 2007
RMAN> shutdown immediate;
RMAN> startup mount;
RMAN> backup database;
RMAN> alter database open;
-bash-3.00$ rman checksyntax
Recovery Manager: Release 10.2.0.4.0 - Production on Tue Sep 22 10:59:59 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
RMAN> backup database;
The command has no syntax errors
RMAN>
Identifying RMAN Server Sessions
$ ps –ef | grep rman
RMAN> drop database;
Database name is "NINA" and DBID is 922224687.
RMAN will require a confirmation from you that you really do want to drop the database.
Respond with yes, if that’s what you intend to do:
Do you really want to drop the database (enter YES or NO)? yes
Database dropped.
RMAN> drop database including backups;
Note how RMAN
RMAN> LIST ARCHIVELOG ALL;
RMAN> LIST BACKUP OF ARCHIVELOG ALL;
RMAN> LIST BACKUP;
RMAN> LIST BACKUP OF DATABASE;
RMAN> LIST BACKUP OF DATAFILE 1;
RMAN> LIST BACKUP SUMMARY;
RMAN> LIST INCARNATION;
RMAN> LIST BACKUP BY FILE;
RMAN> LIST COPY OF DATABASE ARCHIVELOG ALL;
RMAN> LIST COPY OF DATAFILE 1, 2, 3;
RMAN> LIST BACKUP OF DATAFILE 11 SUMMARY;
RMAN> LIST BACKUP OF ARCHIVELOG FROM SEQUENCE 1437;
RMAN> LIST CONTROLFILECOPY "/tmp/cntrlfile.copy";
RMAN> LIST BACKUPSET OF DATAFILE 1;
RMAN> LIST FAILURE;
RMAN> LIST FAILURE 641231 detail;
No hay comentarios:
Publicar un comentario