Professional Documents
Culture Documents
1 Votes
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.
RMAN starts Oracle server processes on the database to be backed up or
restored. The backup, restore, and recovery is driven through these processes
hence the term server-managed recovery.
Note that SMR can also be controlled from OEMs Backup Manager GUI.
This
article will not discuss Backup Manager.
2. Terminology
2.1. Backup sets
A backup set is characterised by the following:
-
Note: Following steps only apply for an Oracle8 8.0.x catalog creation.
SVRMGR> connect rman/rman
SVRMGR> @?/rdbms/admin/catrman
Check create_rman.log for errors. The above commands assume that the
TEMP and RCVCAT tablespaces have been created.
In Oracle8i the catalog is created a little differently.
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 databases controlfile, RMAN can use this
information for recovery purposes.
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.
The command line interface has following syntax:
rman target <qstring> [rcvcat <qstring> | cmdfile <qstring> |
msglog <qstring> | append | trace <qstring>]
Argument
CMDFILE The name of a file that contains the input commands for
RMAN. If this argument is specified, RMAN operates in batch
mode; otherwise, RMAN operates in interactive line mode.
MSGLOG The name of a file where RMAN records commands and output
Results. If not specified, RMAN outputs to the screen.
APPEND This parameters causes the msglog file to be opened in append
mode. If this parameter is not specified and a file with the
same name as the msglog file already exists, it is overwritten.
TRACE A file name where RMAN will dump a trace information.
(useful feature for RMAN jobs debugging)
For the purposes of the following examples, assume that
-
the target database is called targdb and has the same TNS alias
targdba has been granted SYSDBA privileges
the recovery catalog database is called rcat and has the same TNS alias
the schema containing the recovery catalog is rman (same password)
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.
8: Indicates all files including controlfiles are to be backed up
To view this backup in the catalog, use the following command:
RMAN> list backupset of database;
7.2. Example of how to back up a tablespace
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:
RMAN> list backupset of tablespace users;
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 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:
RMAN> list backupset of archivelog all;
Note that RMAN will backup specified logs if it finds them. If it cant
find a log, it will report rman-6089 error:
archived log %s not found or out of sync with catalog,
and it will abort a backup session.
8.2. Backing up the online logs
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.
A cumulative incremental backup backs up all blocks that have changed since
the the most recent incremental backup at level N-1 or less (contrast with
non-cumulative incremental backups that backup blocks that have changed
since the the most recent incremental backup at level N or less). This
means that more work is done in performing the backup (duplication of
backup effort), but time may be saved when restoring (potentially fewer
backupsets to restore).
RMAN> run {
2> allocate channel dev01 type disk;
3> backup incremental level 1 cumulative database;
4> release channel dev01;
5> }
11. Checking backup progress
To check the backup progress run the following sql against the target
database:
select sid, serial#, context
round(sofar/totalwork*100,2) % Complete,
substr(to_char(sysdate,yymmdd hh24: mi:ss),1,15) Time Now
from v$session_longops
where compnam = dbms_backup_restore; for 8.0
where substr(opname,1,4) = RMAN;
for 8.1
This will produce an output such as:
SID
SERIAL# CONTEXT % Complete
- -
12
56
Time Now
980408 14:21:07
12. Recovery
As with backup, recovery is probably best explained with a few examples
12.1. Database open, datafile deleted
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:
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
12.3. Restore of a subset of datafiles, complete recovery
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> }
13. Scripts
It is very easy to create and replace stored scripts with RMAN. E.g.
RMAN> create script alloc_disk {
2> # Allocates one disk
3> allocate channel dev1 type disk;
4> setlimit channel dev1 kbytes 2097150 maxopenfiles 32 readrate 200;
5> }
RMAN> replace script rel_disk {
2> # releases disk
3> release channel dev1;
5> }
RMAN> replace script backup_db_full {
2> # Performs a complete backup
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:
% rman <other RMAN options> cmdfile weekly_cold_backup
14. Parallelization
RMAN can parallelize its 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.
A few simple stored scripts should be adequate for the vast majority
of backup & recovery requirements.
18.4. RMAN errors
When RMAN goes wrong its 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.
19. Limitations
19.1 Enterprise Edition
Only the following features are available with the Enterprise Edition software:
Multiple Channels
Incremental Backups
Duplexed Backups