Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Oracle provide a tool for Database backup and restore operation is called RMAN.
Recovery Manager is a client/server application that uses database server sessions to
perform backup and recovery. It stores metadata about its operations in the control file
of the target database and, optionally, in a recovery catalog schema in an Oracle
database.
Difference between RMAN and Traditional backup methods
RMAN is Oracle's backup and recovery utility. With RMAN, backups become as easy as:
BACKUP DATABASE;
RMAN reduces the complexity of backup and recovery. RMAN can determine what
needs to be backed up or restored.
Why Should we use RMAN
Ability to perform incremental backups.
Ability to recover one block of a datafile.
Ability to perform the backup and restore with parallelization.
Ability to automatically delete archived redo logs after they are backed up.
Ability to automatically backup the control file and the SPFILE.
Ability to restart a failed backup without having to start from the beginning.
Ability to verify the integrity of the backup.
Ability to test the restore process without having to actually perform the restore.
Comparison of RMAN Automated and User-Managed Procedures
By using operating system commands for User-Managed Backup and Recovery , a DBA
manually keeps track of all database files and backups. But RMAN performs these same
tasks automatically.
Understanding the RMAN Architecture
An oracle RMAN comprises of RMAN EXECUTABLE This could be present and fired even
through client side, TARGET DATABASE (This is the database which needs to be backed
up) and RECOVERY CATALOG (Recovery catalog is optional otherwise backup details are
stored in target database controlfile .)
About the RMAN Repository
The RMAN repository is a set of metadata that RMAN uses to store information about
the target database and its backup and recovery operations. RMAN stores information
about:
Backup sets and pieces
Image copies (including archived redo logs)
Proxy copies
The target database schema
Persistent configuration settings
If you start RMAN without specifying either CATALOG or NOCATALOG on the command
line, then RMAN makes no connection to a repository. If you run a command that
requires the repository, and if no CONNECT CATALOG command has been issued yet,
then RMAN automatically connects in the default NOCATALOG mode. After that point,
the CONNECT CATALOG command is not valid in the session.
Types of Database Connections
You can connect to the following types of databases.
Target database
RMAN connects you to the target database with the SYSDBA privilege. If you do not
have this privilege, then the connection fails.
Recovery catalog database
This database is optional: you can also use RMAN with the default NOCATALOG option.
Auxiliary database
You can connect to a standby database, duplicate database, or auxiliary instance
(standby instance or tablespace point-in-time recovery instance
Note: That a SYSDBA privilege is not required when connecting to the recovery
catalog. The only requirement is that the RECOVERY_CATALOG_OWNER role be granted
to the schema owner.
Using Basic RMAN Commands
After you have learned how to connect to a target database, you can immediately
begin performing backup and recovery operations. Use the examples in this section to
go through a basic backup and restore scenario using a test database. These examples
assume the following:
The test database is in ARCHIVELOG mode.
You are running in the default NOCATALOG mode.
The RMAN executable is running on the same host as the test database.
Connecting to the Target Database
rman TARGET /
If the database is already mounted or open, then RMAN displays output similar to the
following:
Recovery Manager: Release 9.2.0.0.0
connected to target database: RMAN (DBID=1237603294)
Reporting the Current Schema of the Target Database
In this example, you generate a report describing the target datafiles. Run the report
schema command as follows:
RMAN> REPORT SCHEMA; (RMAN displays the datafiles currently in the target
database.)
Backing Up the Database
In this task, you back up the database to the default disk location. Because you do not
specify the format parameter in this example, RMAN assigns the backup a unique
filename.
You can make two basic types of backups: full and incremental.
database tag="SUNDAY";
database tag="MONDAY";
database tag="TUESDAY";
database tag="WEDNESDAY";
database tag="THURSDAY";
database tag="FRIDAY";
database tag="SATURDAY";
your incremental Backup Details by using
INC_CHANGE#
0
271365
271369
271371
271365
271378
271380
CHECKPOINT_CHANGE#
271365
271369
271371
271374
271378
271380
271383
BLOCKS
59595
2
1
2
2
1
2
}
In this case, RMAN creates a datafile copy of 'C:_DATA.DBF named 'C:_DATA.DBF
and records it in the repository. To change the name for datafile 'C:_DATA.DBF to
'C:_DATA.DBF in the control file, run a SWITCH command so that RMAN considers the
restored file as the current database file.
RMAN Recovery: Basic Steps
If possible, make the recovery catalog available to perform the media recovery. If it is
not available, then RMAN uses metadata from the target database control file.
Assuming that you have backups of the datafiles and at least one autobackup of the
control file.
The generic steps for media recovery using RMAN are as follows:
Place the database in the appropriate state: mounted or open.
For example, mount the database when performing whole
database recovery, or open the database when performing
online tablespace recovery.
Restore the necessary files using the RESTORE command.
Recover the datafiles using the RECOVER command.
Place the database in its normal state.
Mechanism of Restore and Recovery operation:
The DBA runs the following commands:
RESTORE DATABASE;
RECOVER DATABASE;
The RMAN recovery catalog obtains its metadata from the target database control file.
RMAN decides which backup sets to restore, and which incremental backups and
archived logs to use for recovery. A server session on the target database instance
performs the actual work of restore and recovery.
Mechanics of Recovery: Incremental Backups and Redo Logs
RMAN does not need to apply incremental backups to a restored level 0 incremental
backup: it can also apply archived logs. RMAN simply restores the datafiles that it
needs from available backups and copies, and then applies incremental backups to the
datafiles if it can and if not applies logs.
How RMAN Searches for Archived Redo Logs During Recovery
If RMAN cannot find an incremental backup, then it looks in the repository for the
names of archived redo logs to use for recovery. Oracle records an archived log in the
control file whenever one of the following occurs:
The archiver process archives a redo log
RMAN restores an archived log
The RMAN COPY command copies a log
The RMAN CATALOG command catalogs a user-managed backup of an
archived log
RMAN propagates archived log data into the recovery catalog during resynchronization,
classifying archived logs as image copies. You can view the log information through:
The LIST command
The V$ARCHIVED_LOG control file view
The RC_ARCHIVED_LOG recovery catalog view
During recovery, RMAN looks for the needed logs using the filenames specified in the
V$ARCHIVED_LOG view. If the logs were created in multiple destinations or were generated
by the COPY, CATALOG, or RESTORE commands, then multiple, identical copies of each log
sequence number exist on disk.
If the RMAN repository indicates that a log has been deleted or uncataloged, then RMAN
ceases to consider it as available for recovery. For example, assume that the database
archives log 100 to directories /dest1 and /dest2. The RMAN repository indicates that
/dest1/log100.arc and /dest2/log100.arc exist. If you delete /dest1/log100.arc with the
DELETE command, then the repository indicates that only /dest2/log100.arc is available for
recovery.
If the RMAN repository indicates that no copies of a needed log sequence number exist on
disk, then RMAN looks in backups and restores archived redo logs as needed to perform the
media recovery. By default, RMAN restores the archived redo logs to the first local archiving
destination specified in the initialization parameter file. You can run the SET ARCHIVELOG
DESTINATION command to specify a different restore location. If you specify the DELETE
ARCHIVELOG option on RECOVER, then RMAN deletes the archived logs after restoring and
applying them. If you also specify MAXSIZE integer on the RECOVER command, then RMAN
staggers the restores so that they consume no more than integer amount of disk space at a
time.
Incomplete Recovery
RMAN can perform either complete or incomplete recovery. You can specify a time,
SCN, or log sequence number as a limit for incomplete recovery with the SET UNTIL
command or with an UNTIL clause specified directory on the RESTORE and RECOVER
commands. After performing incomplete recovery, you must open the database with
the RESETLOGS option.
Disaster Recovery with a Control File Autobackup
Assume that you lose both the target database and the recovery catalog. All that you
have remaining is a tape with RMAN backups of the target database and archived redo
logs. Can you still recover the database? Yes, assuming that you enabled the control file
autobackup feature. In a disaster recovery situation, RMAN can determine the name of
a control file autobackup even without a repository available. You can then restore this
control file, mount the database, and perform media recovery.
About Block Media Recovery
You can also use the RMAN BLOCKRECOVER command to perform block media
recovery. Block media recovery recovers an individual corrupt datablock or set of
datablocks within a datafile. In cases when a small number of blocks require media
recovery, you can selectively restore and recover damaged blocks rather than whole
datafiles.
Note: Restrictions of block media recovery:
You can only perform block media recovery with Recovery Manager. No SQL*Plus recovery
interface is available.
You can only perform complete recovery of individual blocks. In other words, you cannot stop
recovery before all redo has been applied to the block.
You can only recover blocks marked media corrupt. The V$DATABASE_BLOCK_CORRUPTION view
indicates which blocks in a file were marked corrupt since the most recent BACKUP, BACKUP ...
VALIDATE, or COPY command was run against the file.
You must have a full RMAN backup. Incremental backups are not allowed.
Blocks that are marked media corrupt are not accessible to users until recovery is complete. Any
attempt to use a block undergoing media recovery results in an error message indicating that the
block is media corrupt.
You can store metadata about multiple target databases in a single catalog.
You can store metadata about multiple incarnations of a single target database in
the catalog. Hence, you can restore backups from any incarnation.
Resynchronizing the recovery catalog at intervals less than the
CONTROL_FILE_RECORD_KEEP_TIME setting, you can keep historical metadata.
You can report the target database schema at a noncurrent time.
You can store RMAN scripts in the recovery catalog.
When restoring and recovering to a time when the database files that exist in the database are
different from the files recorded in the mounted control file, the recovery catalog specifies which
files that are needed. Without a catalog, you must first restore a control file backup that lists the
correct set of database files.
If the control file is lost and must be restored from backup, and if persistent configurations have
been made to automate the tape channel allocation, these configurations are still available when
the database is not mounted.
Types of Files That RMAN Can Back Up The BACKUP command can back up the
following types of files:
Database, which includes all datafiles as well as the current control file and current
server parameter
file:
Register Database
Each database to be backed up by RMAN must be registered:
C:>rman catalog=rman/rman@w2k1 target=sys/password@w2k2\
<mailto:target=sys/password@w2k2\>
SQL>
The FIRST_CHANGE# is the first SCN stamped in the missing log. This implies that the
last SCN stamped in the previous log is 370254 (FIRST_CHANGE#-1). This is the highest
SCN that we can recover to. In order to do the recovery we must first restore ALL
datafiles to this SCN, followed by recovery (also up to this SCN). This is an incomplete
recovery, so we must open the database resetlogs after we're done. Here's a transcript
of the recovery session (typed commands in bold, comments in italics, all other lines
are RMAN feedback):
C:\>rman target /
Recovery Manager: Release 9.2.0.4.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to target database: ORCL (DBID=1507972899)
--Restore ENTIRE database to determined SCN
RMAN> restore database until scn 370254;
Starting restore at 26/JAN/05
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to D:\ORACLE_DATA\DATAFILES\ORCL\SYSTEM01.DBF
restoring datafile 00004 to D:\ORACLE_DATA\DATAFILES\ORCL\USERS01.DBF
channel ORA_DISK_2: starting datafile backupset restore
channel ORA_DISK_2: specifying datafile(s) to restore from backup set
restoring datafile 00002 to D:\ORACLE_DATA\DATAFILES\ORCL\UNDOTBS01.DBF
restoring datafile 00003 to D:\ORACLE_DATA\DATAFILES\ORCL\TOOLS01.DBF
channel ORA_DISK_2: restored backup piece 1
piece handle=E:\BACKUP\13GB14IB_1_1.BAK tag=TAG20050124T171139 params=NUL
channel ORA_DISK_2: restore complete
channel ORA_DISK_1: restored backup piece 1
piece handle=E:\BACKUP\14GB14IB_1_1.BAK tag=TAG20050124T171139 params=NUL
channel ORA_DISK_1: restore complete
Finished restore at 26/JAN/05
--Recover database
RMAN> recover database until scn 370254;
Starting recover at 26/JAN/05
using channel ORA_DISK_1
following example. Here's the situation: a user connected to SQLPlus gets a data block
corruption error when she queries a table. Here's a part of the session transcript:
SQL> connect testuser/testpassword
Connected.
SQL> select count(*) from test_table;
select count(*) from test_table
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 4, block # 2015)
ORA-01110: data file 4: 'D:\ORACLE_DATA\DATAFILES\ORCL\USERS01.DBF'
Since we know the file and block number, we can perform block level recovery using
RMAN. This is best illustrated by example:
C:\>rman target /
Recovery Manager: Release 9.2.0.4.0 - Production
connected to target database: ORCL (DBID=1507972899)
--restore AND recover specific block
RMAN> blockrecover datafile 4 block 2015;
Starting blockrecover at 26/JAN/05
using target database controlfile instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=19 devtype=DISK
allocated channel: ORA_DISK_2
media recovery complete
Finished blockrecover at 26/JAN/05
RMAN>
Now our user should be able to query the table from her SQLPlus session. Here's her
session transcript after block recovery.
SQL> select count(*) from test_table;
COUNT(*)
---------217001
SQL>
A couple of important points regarding block recovery:
1. Block recovery can only be done using RMAN.
2. The entire database can be open while performing block recovery.
3. Check all database files for corruption. This is important - there could be other
corrupted blocks. Verification of database files can be done using RMAN or the dbverify
utility. To verify using RMAN simply do a complete database backup with default
settings. If RMAN detects block corruption, it will exit with an error message pointing
out the guilty file/block.
DISASTER RECOVERY
Introduction:
- i.e. a situation in which your database server has been destroyed and has taken all
your database files (control files, logs and data files) with it. Obviously, recovery from a
disaster of this nature is dependent on what you have in terms of backups and
hardware resources. We assume you have the following available after the disaster:
With the above items at hand, it is possible to recover all data up to the last full
backup. One can do better if subsequent archive logs (after the last backup) are
available. In our case these aren't available, since our only archive destination was on
the destroyed server ). Oracle provides methods to achieve better data protection. We
will discuss some of these towards the end of the article.
Now on with the task at hand. The high-level steps involved in disaster recovery are:
Ideally the server should have the same number of disks as the original. The new disks should
also have enough space to hold all software and data that was on the original server.
The operating system environment should be the same as the original, right up to service pack
and patch level.
The new server must have enough memory to cater to Oracle and operating system / other
software requirements. Oracle memory structures (Shared pool, db buffer caches etc) will be
sized identically to the original database instance. Use of the backup server parameter file will
ensure this.
Install the same version of Oracle as was on the destroyed server. The version number should
match right down to the patch level, so this may be a multi-step process involving installation
followed by the application of one or more patch sets and patches.
Do not create a new database at this stage.
Create a listener using the Network Configuration Assistant. Ensure that it has the same name
and listening ports as the original listener. Relevant listener configuration information can be
found in the backed up listener.ora file.
Don't worry if you do not know where the database files should be located. You can
obtain the required information from the backup spfile and control file at a later stage.
Continue reading - we'll come back to this later.
Step: 5 Create Oracle service
An Oracle service must be exist before a database is created. The service is created
using the oradim utility, which must be run from the command line. The following
commands show how to create and modify a service (comments in italics, typed
commands in bold):
--create a new service with auto startup
C:\>oradim -new -sid ORCL -intpwd ORCL -startmode a
Unfortunately oradim does not give any feedback, but you can check that the service
exists via the Services administrative panel. The service has been configured to start
automatically when the computer is powered up.
Step: 6 Restore and recover database
Now it is time to get down to the nuts and bolts of database recovery. There are several
steps, so we'll list them in order:
Copy PASSWORD and TNSNAMES file from backup: The backed up password file and
tnsnames.ora files should be copied from the backup directory to the proper locations. Default
location for password and tnsnames files are ORACLE_HOME\database
ORACLE_HOME\network\admin respectively.
Set ORACLE_SID environment variable: ORACLE_SID should be set to the proper SID name
(ORCL in our case). This can be set either in the registry (registry key:
HKLM\Software\Oracle\HOME<X>\ORACLE_SID) or from the system applet in the control panel.
Invoke RMAN and set the DBID: We invoke rman and connect to the target database as usual. No
login credentials are required since we connect from an OS account belonging to ORA_DBA. Note
that RMAN accepts a connection to the database although the database is yet to be recovered.
RMAN doesn't as yet "know" which database we intend to connect to. We therefore need to
identify the (to be restored) database to RMAN. This is done through the database identifier
(DBID). The DBID can be figured out from the name of the controlfile backup. Example: if you
use the controlfile backup format , your controlfile backup name will be something like
"CTL_SP_BAK_C-1507972899-20050228-00". In this case the DBID is 1507972899. Here's a
transcript illustrating the process of setting the DBID:
C:\>rman
Recovery Manager: Release 9.2.0.4.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
RMAN> set dbid 1507972899
executing command: SET DBID
RMAN>connect target /
connected to target database (not started)
RMAN>
Restore spfile from backup:
To restore the spfile, you first need to startup the database in the nomount state. This
starts up the database using a dummy parameter file. After that you can restore the
spfile from the backup (which has been restored from tape ). Finally you restart the
database in nomount state. Here is an example RMAN transcript for the foregoing
procedure. Note the difference in SGA size and components between the two startups:
RMAN> startup nomount
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file 'C:\ORACLE\ORA92\DATABASE\INITORCL.ORA'
trying to start the Oracle instance without parameter files ...
Oracle instance started
Total System Global Area 97590928 bytes
Fixed Size 454288 bytes
Variable Size 46137344 bytes
Database Buffers 50331648 bytes
Redo Buffers 667648 bytes
RMAN> restore spfile from 'e:\backup\CTL_SP_BAK_C-1507972899-2005022800';
Starting restore at 01/MAR/05
using target database controlfile instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=9 devtype=DISK
channel ORA_DISK_1: autobackup found: e:\backup\CTL_SP_BAK_C-150797289920050228-00
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 01/MAR/05
RMAN> startup force nomount
Oracle instance started
Total System Global Area 1520937712 bytes
Fixed Size 457456 bytes
Variable Size 763363328 bytes
Database Buffers 754974720 bytes
Redo Buffers 2142208 bytes
RMAN>
The instance is now started up with the correct initialization parameters.
We are now in a position to determine the locations of control file and archive
destination, as this information sits in the spfile. This is done via SQL Plus as follows:
C:\>sqlplus /nolog
SQL>connect / as sysdba
SQL> show parameter control_file
SQL> show parameter log_archive_dest
Tape Backups
The media management software must be configured such that host B is a media
manager client, and can read the backup sets. The media management vendor should
be consulted for support on this issue.
Step: 4 init.ora on host B
The "init.ora" needs to be made available on host B. Any location specific parameters
must be amended. For example, ifile, *_dump_dest, log_archive_dest*, control_files
Identifies currently active sessions. Use this view to determine which Oracle database
server sessions correspond to which RMAN allocated channels.
V$SESSION_LONGOPS
view. Join V$SESSION with V$PROCESS to correlate the server session with the channel.
To correlate a process with a channel during a backup:
Step:1 Start RMAN and connect to the target database .
Step:2 Set the command id parameter after allocating the channels and then back up
the
desired object.
run {
allocate channel t1 type disk;
allocate channel t2 type disk;
set command id to 'rman';
backup
incremental level 0
filesperset 5
tablespace 'SYSTEM';
# optionally, issue a host command to access the operating system prompt
host;
sql 'ALTER SYSTEM ARCHIVE LOG ALL';
}
Step:3 Start a SQL*Plus session and then query the joined V$SESSION and V$PROCESS
views while the RMAN job is executing.
SELECT sid, spid, client_info FROM v$process p, v$session s WHERE p.addr = s.paddr
AND client_info LIKE '%id=rman%';
SID
8
16
17
18
SPID
21973
22057
22068
22070
CLIENT_INFO
id=rman
id=rman
id=rman,ch=t1
id=rman,ch=t2
SERIAL#
19
SERIAL#
19
CONTEXT
1
SOFAR
10377
CONTEXT
1
SOFAR
21513
TOTALWORK
36617
% Complete
28.34
TOTALWORK % Complete
36617
58.75
no rows selected
NOTE: If you run the script at intervals of two minutes or more and the % Complete
column does not increase, then RMAN is encountering a problem.
SELECT sid, seconds_in_wait AS sec_wait, event FROM v$session_wait WHERE
wait_time = 0
ORDER BY sid;
SID
1
2
3
4
5
6
7
8
9
12
SEC_WAIT
368383335
1097
387928
0
1408
386114
387626
1060
1060
1060
EVENT
pmon timer
rdbms ipc message
rdbms ipc message
rdbms ipc message
smon timer
rdbms ipc message
rdbms ipc message
SQL*Net message from client
SQL*Net message from client
SQL*Net message from client
13
2366
14
2757
12 rows selected.
Note: The V$SESSION_WAIT view shows only Oracle events, not media
manager events.
Another Query:
COLUMN
COLUMN
COLUMN
COLUMN