Académique Documents
Professionnel Documents
Culture Documents
Module Objectives
Purpose
In this module, you will learn how to use Oracle9i Recovery Manager to
backup and restore a database.
Objectives
Prerequisites
Before starting this module, you should have complete the following:
Preinstallation Tasks
Install the Oracle9i Database
Postinstallation Tasks
Review the Sample Schema
Enabling Archiving
Downloaded the rman.zip module files and unzipped them into your working directory.
Reference Material
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 2 of 45
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 3 of 45
Module Layout
1. Open three windows, one for SQL*Plus, two command line windows of which one is for RMAN and
the other is for scripts.
2. Verify the ORCL instance is started. Click on the SQL*Plus icon and connect as SYS. If the instance
is idle start it.
startup
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 4 of 45
Starting RMAN
RMAN is a client executable that is installed with the Oracle database server.
You can connect it to a target database, and then use server sessions on the
target database to back up, restore, and recover files.
Omit the database connection at the command line, and use the CONNECT
command in your
RMAN scripts:
rman
In both cases, RMAN displays an RMAN> prompt at which you can enter
commands or run a command file.
Target database
The database that you will use RMAN to back up and restore: RMAN
connects to the target database as SYSDBA. If you do not have this
privilege, then the connection fails. You can connect with the SYSDBA
privilege by using a password file or using operating system authentication.
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 5 of 45
This database is optional: you can use RMAN with the default NOCATALOG
option, in which case RMAN uses the control file as the exclusive repository
of metadata. A recovery catalog is a set of tables containing RMAN
metadata. RMAN obtains the metadata from the target database control file.
If you choose to use a recovery catalog, refer to Oracle9i Recovery Manager
User's Guide for complete instructions.
Auxiliary database
The auxiliary instance is only used for duplicate and standby database
created with the DUPLICATE command and for tablespace point-in-time-
recovery
3. Connect to RMAN. From RMAN, type the following command to start the
RMAN client and create a server session on the target database ORCL.
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 6 of 45
You can return any CONFIGURE command to its default setting by running
the command with the CLEAR option, as in:
4. If D:\ORACL\ORCLBACKUP does not exist please create is now. From the command prompt, in a
windows where you are not connected to RMAN:
D:
cd\ORALCE
mkdir ORCLBACKUP
cd\wkdir
5. Configure the RMAN environment by typing the following commands from RMAN.
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 7 of 45
SHOW ALL;
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 8 of 45
RMAN stores its backups in backup sets. A backup set is a logical structure
that contains one or more backup pieces, which are the physical files
containing the data. A backup set usually contains only one backup piece.
Only RMAN can create and restore backup sets. You can also back up
individual tablespaces, database files, and backup sets.
Incremental Backups
Restarting Backups
If a backup fails for any reason, backing up some but not all specified files,
then you can use the NOT BACKED UP SINCE option on the BACKUP
command to continue from the point of failure. This example backs up all
files not backed up within the last day:
Testing Backups
You can run a test RMAN backup that does not generate any output. The
test checks datafiles for physical and logical corruption and that all database
files exist and are in the correct locations. For example:
7. Generate archive logs to backup. From the command prompt execute the batch file switch5.bat,
location in D:\wkdir, by typing the following:
switch5 orcl.world
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 9 of 45
8. Backup database files and archive logs. While the backup is going on, we can also monitor the
progress.
In RMAN type:
In SQL*Plus where you have already connected to the ORCL database, type the following command
to view the progress of the RMAN job. At first you may receive 'no row returned.'
@monitorjob
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 10 of 45
The columns from the resulting SQL statement which is run in MONITORJOB, refer to RMAN jobs in
this manner:
the buffer
9. Backup individual datafiles. First, let’s take a look at the schema via RMAN. From RMAN, type the
following commands. What does the database schema look like?
REPORT SCHEMA;
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 11 of 45
10. RMAN can backup at the database, tablespace, and datafile level. First you will backup a datafile.
Backup the database file which corresponds to the Example tablespace. In the example below the
Example tablespace is datafile 5.
BACKUP DATAFILE 5;
11. Backup at the Tablespace Level. From RMAN, type the following
commands.
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 12 of 45
12. Incremental backups can be made by RMAN. From RMAN, type the following command to make an
incremental level 0 backup of the database.
In SQL*Plus, you can run the following SQL statement to monitor the work being processed by
RMAN.
@monitorjob
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 13 of 45
13. Not only can you perform an incremental backup at the database level, but you can perform
incremental backups on datafiles and tablespaces as well. Let’s perform an incremental backup on a
datafile.
Use the same datafile as used previously, the datafile for the Example tablespace.
14. RMAN can backup the archive logs and database at the same time or separately. Let’s backup just
the archive logs. First, generate some logs. From the command prompt type the following:
switch5 orcl.world
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 14 of 45
15. At one time or another, a backup may terminate due to an error or be killed due to system resources.
RMAN offers the capability to restart a backup. With the RMAN command NOT BACKED UP SINCE,
files that have not been backed up since a specified time will then be backed up. In the following
command, we tell RMAN to backup the database files that have not been backed up since yesterday.
From RMAN, type the following command:
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 15 of 45
Administrative Commands
The following commands can be used in RMAN to find out if files require a
backup, delete backups that are no longer needed, and view backups of
files. We refer to this set of commands as RMAN maintenance. From RMAN,
type the following commands.
The following 2 commands allow you to view what backups are obsolete and
delete them.
REPORT OBSOLETE;
DELETE OBSOLETE;
The validate command can be used to check for corruption or verify that
database files are in the correct location.
If you run any batch jobs with the nologging option, the following command
will report any files that have not been backed up since the last nolog
operation.
REPORT UNRECOVERABLE;
To fee up disk space of archive logs that you know have already been
backed up, run this command to delete the archive logs that are older then
yesterday.
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 16 of 45
The crosscheck command is used to verify that backups of the database are
in the location known by the repository and to verify that archive logs are still
on disk and have not been deleted outside of RMAN.
The LIST commands allow you to view the backup information of the
database, datafile, tablespaces, and controlfiles. Lets view the backups for
datafile 4 and the control file.
REPORT OBSOLETE;
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 17 of 45
DELETE OBSOLETE;
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 18 of 45
REPORT UNRECOVERABLE;
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 19 of 45
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 20 of 45
Exit
Exit
2 Database Recovery
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 21 of 45
Complete Recovery
When you perform complete recovery, you recover the backups to the
current SCN. You can either recover the whole database at once or recover
individual tablespaces or datafiles. Because you do not have to open the
database with the RESETLOGS option after complete recovery as you do
after incomplete recovery, you have the option of recovering some datafiles
at one time and the remaining datafiles later.
Recovering Datafiles
Take the datafile that needs recovery offline, restore the datafile, recover the
datafile, and bring the datafile online.
1. In SQL*Plus connect as HR and select from the EMPLOYEES table to verify that a table exist.
connect hr/hr@orcl.world
SELECT first_name
FROM employees;
2. Simulate the loss of employee01.dbf. Run the following script from the command line window.
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 22 of 45
connect hr/hr@orcl.world;
SELECT *
FROM employees;
RESTORE DATAFILE 5;
RECOVER DATAFILE 5;
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 23 of 45
SELECT first_name
FROM employees;
The database must be in MOUNT mode to restore and recover with RMAN.
6. As HR, select from the EMPLOYEES table to verify that the database is up and running. In SQL*Plus,
type the following:
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 24 of 45
SELECT first_name
FROM employees;
7. Simulate the loss of all datafiles. (This does not include the control files or online logs) From the
command prompt, type the following
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 25 of 45
RECOVER DATABASE;
ALTER DATABASE OPEN;
9. In SQL*Plus as HR, type the following command to show that the datafile has been successfully
restored and recovered.
CONNECT hr/hr@orcl.world
SELECT first_name
FROM employees;
Recovering Tablespaces
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 26 of 45
Take the tablespace that needs recovery offline, restore the tablespace,
recover the tablespace, and bring the recovered tablespace online.
10. Select from the EMPLOYEES table to verify that a table exist. In SQL*Plus as HR, type the following
command .
CONNECT hr/hr@orcl.world
SELECT first_name
FROM employees;
11. Simulate the loss of the EXAMPLE tablespace. Run the following command from the command
prompt.
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 27 of 45
Connect hr/hr@orcl.world
SELECT first_name
FROM EMPLOYEES;
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 28 of 45
SELECT first_name
FROM employees;
The database must be in MOUNT mode to restore and recover with RMAN.
15. In SQL*Plus as HR, select from the EMPLOYEES table to verify that the database is up and running.
SELECT first_name
FROM employees;
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 29 of 45
16. Simulate the loss of all datafiles (this does not include the control files or online logs). From the
command prompt, type the following command.
Connect hr/hr@orcl.world
SELECT *
FROM employees;
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 30 of 45
18. Recover DATABASE. In RMAN, type the following commands. Connect to RMAN.
19. From SQL*Plus are HR, type the following commands to verify that the database has been
recovered.
Connect hr/hr@orcl.world
SELECT first_name
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 31 of 45
FROM employees;
Incomplete Recovery
To perform incomplete media recovery, you must restore all datafiles from
backups created prior to the time to which you want to recover and then
open the database with the RESETLOGS option when recovery completes.
The RESETLOGS operation creates a new incarnation of the database?in
other words, a database with a new stream of log sequence numbers
starting with log sequence 1.
20. In SQL*Plus as HR, select from the EMPLOYEES table to verify that the database is up and running.
Connect hr/hr@orcl
SELECT *
FROM employees;
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 32 of 45
21. Connect as SYS and select the database id from V$DATABASE. Write down the value returned.
22. Simulate the loss of all datafiles, control files, online logs and archive logs. Run the following script
from the command line.
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 33 of 45
Connect hr/hr@orcl.world
SELECT first_name
FROM employees;
24. Recover DATABASE. In RMAN, type the following commands. Connect to RMAN without any
connect strings
RMAN
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 34 of 45
25. The following commands are issued within RMAN, using the database id(DBID) returned from the
query. You will receive an error message at the end of recover due to the loss of the online redo logs.
26. Since the online logs were lost, complete recovery is not possible. Open the database with resetlogs
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 35 of 45
to continue.
27. To view the successful recovery of the database, in SQL*Plus type the following commands.
Connect hr/hr@orcl.world
SELECT first_name
FROM employees;
28. Make a backup of new database incarnation version!! Let's generate some archive logs. From the
command prompt, type the following command.
swtich5 orcl.world
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 36 of 45
29. In RMAN, type the following commands to make a backup and remove obsolete backups and archive
logs. What files require a backup now?
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 37 of 45
DELETE OBSOLETE;
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 38 of 45
DELETE OBSOLETE;
You can use the RMAN DUPLICATE command create a duplicate database
from target database backups while still retaining the original target
database. A duplicate database is a copy of the target database that you can
run independently for a variety of purposes. For example, you can use it to:
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 39 of 45
01. From the command prompt create a password file for the AUX database.
2. In SQL*Plus as SYS create a parameter file from the spfile for the AUX database.
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 40 of 45
db_file_name_convert=('D:\ORACLE\ORADATA\ORCL','D:\ORACLE\ORADATA\AUXORCL')
log_file_name_convert=('D:\ORACLE\ORADATA\ORCL','D:\ORACLE\ORADATA\AUXORCL')
4. Run script cre_dir from the command prompt to create the subdirectories for the duplicate database.
cre_dir
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 41 of 45
5. Add an entry in the tnsnames.ora and listener.ora for the AUX database. Use Net Manager.
Start > Programs > Oracle - OraHome92 > Configuration and Migration Tools > Net Manager
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 42 of 45
TNSNAMES.ORA
Select Oracle Net Configuration > Local > Service Name. Then from the menu select Edit >
Create. Use the following values to create the entry.
Port: 1521
Since the database has not been created you can not successfully test the configuration.
LISTENER.ORA
Select Oracle Net Configuration > Local > Listeners > LISTENER. From the drop down menu on
the right and side change Listener Location to Database Services. Click Add Database at the bottom.
Use the following values:
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 43 of 45
SID: aux
Select from the top menu: File > Save Network Configuration followed by File > Exit.
6. Shutdown and startup the listener.ora. From the command prompt type the follow:
lsnrctl stop
lsnrctl start
7. Create a service for the database. From the command prompt type:
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 44 of 45
RMAN
CONNECT AUXILIARY SYS/ORACLE@AUX.WORLD
CONNECT TARGET SYS/ORACLE@ORCL.WORLD
STARTUP CLONE NOMOUNT FORCE;
DUPLICATE TARGET DATABASE TO AUX;
connect hr/hr@aux.world
SELECT first_name
FROM employees;
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009
rman Page 45 of 45
Module Summary
Close Window
http://www.oracle.com/technology/obe/obe9ir2/obe-ha/rman/rman.htm?_template=/ocom... 22-06-2009