Documente Academic
Documente Profesional
Documente Cultură
This document explains the basic operation of SMR & RMAN. Because of the
enormous flexibility of RMAN only the most basic features will be covered
here. For more information, please read the Oracle8 Server Backup & Recovery
Guide. For comprehensive examples, please view the online case*.rcv scripts
in $ORACLE_HOME/rdbms/demo.
For the sake of clarity, I have excluded RMAN error messages and return
codes unless necessary. It is usually obvious when an error occurs!
NOTE: MUCH OF THE TEXT OF THIS DOCUMENT HAS BEEN EXTRACTED FROM THE ORACLE8
SERVER BACKUP AND RECOVERY GUIDE, AND THE ONLINE EXAMPLES.
Contents:
1. What is RMAN & SMR?
2. Terminology
3. The recovery catalog
4. Starting RMAN
5. Register the target database
6. Adding existing backups to the recovery catalog
7. Backing up in noarchivelog mode
8. Backing up in archivelog mode
9. Incremental backups
10. Cumulative incremental backups
11. Recovery
12. Scripts
13. Parallelization
14. Corruption detection
15. Channels
16. Balancing throughput on devices
17. Reports
18. Hints, tips, & best practices
1. What is RMAN?
RMAN can be used to backup and restore database files, archive logs, and
control files. It can also be used to perform complete or incomplete
database recovery. Note that RMAN cannot be used to backup initialization
files or password files.
Note that SMR can also be controlled from OEM's Backup Manager GUI. This
article will not discuss Backup Manager.
2. Terminology
2.1. Backup sets
A full backup is a backup of one or more datafiles that contains all used
blocks in the datafile. Blocks that have never been used are not backed up
i.e. oracle performs backup set compression.
The Oracle8 Server Backup & Recovery Guide p.6-3 lists typical space
requirements for the recovery catalog.
To set up the recovery catalog, firstly ensure that catalog and catproc
have been run, then execute the following:
Check create_rman.log for errors. The above commands assume that the
TEMP and RCVCAT tablespaces have been created.
Also ensure that catproc has been run on the target database; RMAN makes
extensive use of RPCs.
Note: Although you are not required to use a recovery catalog with RMAN,
it is recommended. Because most of the information in the recovery catalog
is available via the target database's controlfile, RMAN can use this
information for recovery purposes. For more information and limitations
on using RMAN without a recovery catalog, please see the Oracle8 Server
Backup & Recovery Guide pp.7-8, 7-8.
4. Starting RMAN
RMAN has a command line interface, or can be run from Enterprise Manager.
For the purposes of this document, only the CLI will be covered.
NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
NLS_DATE_FORMAT=DD-MON-YYYY HH24:MI:SS
For RMAN to connect to the recovery catalog and the target database, the
recovery catalog database must be OPEN, while the target instance must be
at least STARTED. If not, RMAN will give an error. To perform backups with
the target database open, the target MUST be in archivelog mode.
% rman nocatalog
RMAN> connect target
or if the target database uses a password file,
RMAN> connect target targdba/<password>@targdb
Once connected to the target database, you can specify RMAN commands
either interactively or by using stored scripts. An example of
using RMAN interactively would be:
The target database must be registered with the recovery catalog before
using RMAN against the database for the first time:
RMAN> register database;
RMAN> run {
2> # backup the complete database to disk
3> allocate channel dev1 type disk;
4> backup
5> full
6> tag full_db_sunday_night
7> format '/oracle/backups/db_t%t_s%s_p%p'
8> (database);
9> release channel dev1;
10> }
Line#
2: Comment line (anything after the '#' is a comment)
3&9: See section 15 - Channels
5: Full backup (default if full or incremental not specified)
6: Meaningful string (<=30 chars)
7: Filename to use for backup pieces, including substitution variables.
Oracle8 Backup & Recovery Guide p8-26 explains these variables
8: Indicates all files including controlfiles are to be backed up
RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4> tag tbs_users_read_only
5> format '/oracle/backups/tbs_users_t%t_s%s'
6> (tablespace users);
7> release channel dev1;
10> }
Line#
6: Specifying only the USERS tablespace for backup
To view this tablespace backup in the catalog, use the following command:
If for example the USERS tablespace is going to be put READ ONLY after
being backed up, subsequent full database backups would not need to
backup this tablespace. To cater for this, specify the 'skip readonly'
option in subsequent backups.
RMAN> run {
2> allocate channel dev1 type 'SBT_TAPE';
3> backup
4> format '%d_%u'
5> (datafile '/oracle/dbs/sysbigdb.dbf');
6> release channel dev1;
7> }
Line#
2: Allocates a tape drive using the media manager layer (MML)
Note that no tag was specified and is therefore null.
To view this tablespace backup in the catalog, use the following command:
RMAN> run {
2> allocate channel dev1 type 'SBT_TAPE';
3> copy datafile '/oracle/dbs/temp.dbf' to '/oracle/backups/temp.dbf';
4> release channel dev1;
5> }
To view this file copy in the catalog, use the following command:
RMAN> run {
2> allocate channel dev1 type 'SBT_TAPE';
3> backup
4> format 'cf_t%t_s%s_p%p'
5> tag cf_monday_night
6> (current controlfile);
7> release channel dev1;
8> }
The commands are identical to those in section 7 except that the target
database is in archivelog mode.
RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4> format '/oracle/backups/log_t%t_s%s_p%p'
5> (archivelog all);
6> release channel dev1;
7> }
RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4> format '/oracle/backups/log_t%t_s%s_p%p'
5> (archivelog from logseq=90 until logseq=100 thread 1);
6> release channel dev1;
7> }
The following script backs up all archive logs generated in the past
24 hours. Furthermore it actually deletes the logs after backing them
up. If the backup fails, logs will NOT be deleted:
RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4> format '/oracle/backups/log_t%t_s%s_p%p'
5> (archivelog from time 'sysdate-1' all delete input);
6> release channel dev1;
7> }
To view the archive logs in the catalog, use the following command:
Note that RMAN will backup specified logs if it finds them. If it can't
find a log, it does not issue a warning.
Online logs CANNOT be backed up using RMAN; they must be archived first.
To do this, you can issue SQL commands from RMAN e.g.
RMAN> run {
2> allocate channel dev1 type disk;
3> sql "alter system archive log current";
4> backup
5> format '/oracle/backups/log_t%t_s%s_p%p'
6> (archivelog from time 'sysdate-1' all delete input);
7> release channel dev1;
8> }
The above script might be run after performing a full 'database open'
backup. It would ensure that all redo to recover the database to a
consistent state would be backed up.
9. Incremental backups
A level N incremental backup backs up blocks that have changed since the
most recent incremental backup at level N or less.
RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4> incremental level 0
5> filesperset 4
6> format '/oracle/backups/sunday_level0_%t'
7> (database);
8> release channel dev1;
9> }
Line#
4: Level 0 backup - backups of level > 0 can be applied to this
5: Specifies maximum files in the backupset
A list of the database backupsets will show the above backup. The 'type'
column is marked 'Incremental'; the 'LV' column shows '0'.
11. Recovery
As with backup, recovery is probably best explained with a few examples
Datafile has been deleted from a running database. There are two methods
of open database recovery: restore the datafile and recover either the
datafile, or the tablespace. The next two examples show both methods:
RMAN> run {
2> allocate channel dev1 type disk;
3> sql "alter tablespace users offline immediate";
4> restore datafile 4;
5> recover datafile 4;
6> sql "alter tablespace users online";
7> release channel dev1;
8> }
RMAN> run {
2> allocate channel dev1 type disk;
3> sql "alter tablespace users offline immediate";
4> restore tablespace users;
5> recover tablespace users;
6> sql "alter tablespace users online";
7> release channel dev1;
8> }
11.2. Complete restore (lost online redo) and rollforward - database closed
RMAN> run {
2> allocate channel dev1 type disk;
3> set until logseq=105 thread=1;
4> restore controlfile to '/oracle/dbs/ctrltargdb.ctl';
5> replicate controlfile from '/oracle/dbs/ctrltargdb.ctl';
6> restore database;
7> sql "alter database mount";
8> recover database;
9> sql "alter database open resetlogs";
10> release channel dev1;
11> }
Notes:
- The 'set until' command dictates at which log sequence recovery will
stop. It is critical that this command is issued BEFORE datafiles
are restored, otherwise RMAN will attempt to restore the most recent
set of datafiles, which could be ahead of the specified log
- The 'replicate controlfile' copies the restored controlfile to
the controlfiles referenced in init.ora
- Because the database is opened with resetlogs, it is necessary to
register the new incarnation of the database with the RESET DATABASE
command. As with v7, it is important to take a full backup of the
database immediately after a resetlogs
RMAN> run {
2> allocate channel dev1 type disk;
3> sql "alter database mount";
4> restore datafile 2;
5> restore datafile 3;
6> restore archivelog all;
7> recover database;
8> sql "alter database open";
9> release channel dev1;
10> }
12. Scripts
It is very easy to create and replace stored scripts with RMAN. E.g.
The 3rd script calls the previously stored scripts either side of
performing a backup.
RMAN> run {
2> execute script backup_db_full;
3> }
Note that a stored scripts must be called from within a job command
list i.e. run { .... execute <script>; ....}.
It is possible to create a job command list in a flat file and call that
script from the O/S command line as an RMAN option. E.g. to call scripts
stored in a file called 'weekly_cold_backup':
13. Parallelization
RMAN can parallelize it's operations. When creating backup sets, the
granule of parallelization is the backup set. E.g. if your backup consists
of 10 backup sets, RMAN will potentially use 10 channels. To create an
environment for this to take place, you must allocate sufficient channels
and dictate the number of backup sets created (using the filesperset
parameter). E.g. if you are backing up a database consisting of 50
datafiles and you allocate 20 channels and specify 'filesperset 10',
only 5 channels will be used. This is because only 5 backup sets (50/10)
will be created.
Please see the Oracle8 Backup and Recovery Guide p.7-20 for examples
of parallelization.
E.g.
When the above script the backup will fail if ANY corrupt blocks are
found in datafile 1.
15. Channels
A channel is a connection from RMAN to a target database. The 'allocate
channel' command starts a server process on the target instance. It also
specifies the type of I/O device that the server process will use to
perform the backup or restore operation.
Output:
Output:
17.2. Report
The report command also queries the recovery catalog, However, the report
command syntax is constructed in such a way to produce a more useful
listing. E.g. the following command can be used to list all datafiles
in a database that have had UNRECOVERABLE operations performed on objects
in those datafiles since the last backup:
See Oracle8 Server Backup & Recovery Guide pp.8-12, 8-18 for more
information on lists and reports.
A full resync updates the catalog with ALL controlfile information that
has changed since the last resync. This includes changes to the physical
structure of the database. A manual (explicit) resync performs a full
resync, whilst full (implicit) resyncs are performed after an SMR backup.
A partial resync only updates the catalog with redo log, backupset, and
datafile copy information i.e. physical structure changes are NOT
refreshed. A partial (implicit) resync is performed before an SMR backup.
A few simple stored scripts should be adequate for the vast majority
of backup & recovery requirements.
When RMAN goes wrong it's spectacular! The error stacks are usually
very long. If an error is reported, it is worth getting the complete
stack sent to support as most of the errors will not help in diagnosing
the problem.
End of File……………