RecoveryManager Slides
RecoveryManager Slides
Recovery Manager
Backup and Recovery
Sreekanth Chintala
Texas Dept. of Human Services
Tel: 512-490-0547
Email: [email protected]
Copyright 2003 Sreekanth Chintala
2
Self
Scope
What is RMAN?
Oracle utility. Installed along with Oracle.
Can back up database files (datafiles, controlfile, archivelogs) to
disk or tape
Can restore database files from disk or tape.
Can parallalize the backup operation
Create duplicate databases
Create Standby database
Can run scripts from a command line. So jobs can be
scheduled from crontab, OEM or windows scheduler
Can generate reports on backups taken using RMAN
Can perform shutdown, startup and some administrative tasks
Copyright 2003 Sreekanth Chintala
5
How it Works
It is a client application that attaches to the target
database via an Oralce (SQL) Net connection.
Creates database server sessions on the target database
to access internal backup and recovery packages.
The database has internal packages, DBMS_RCVMAN,
DBMS_BACKUP_RESTORE that actually take the
pl/sql blocks passed from RMAN and turn them into
system calls.
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.
Copyright 2003 Sreekanth Chintala
6
Why RMAN?
Manages the complexity of backup and recovery operations.
RMAN can backup your database online without having to put
the tablespaces in hot backup mode. This reduces the
additional redo generated during a hot backup.
Minimizes the possibility of human errors. RMAN will
automatically track new datafiles and tablespaces for you.
Maintains history of backups and incarnations
RMAN can work fairly seamlessly with third-party media
management products.
Copyright 2003 Sreekanth Chintala
7
Why RMAN?
Make backups proportional to the size of transactional
changes, not to the size of the database. RMAN will only
back up used data blocks (up to HWM). Null blocks
(Blocks that have never been used) are never backed up.
Backups taken outside of RMAN can also be cataloged in
the control using RMAN
Can create Hot Backups (Image Copies) just like you do it
from SQLPLUS prompt. These Image copies can be used
for recovering database outside of RMAN
Copyright 2003 Sreekanth Chintala
8
Why RMAN?
Since RMAN is integrated into the RDBMS, it has block-level
access enabling it to check for data block corruptions.
In 9i, RMAN provides block media recovery. For “ORA-
1578:block corruption detected” error, instead of recovering the
entire file and performing recovery, RMAN can simply recover
the bad block and perform recovery. This means, rest of the
data in the datafile is available during recovery.
RMAN supports incremental backup strategies.
RMAN can test/validate the backups without actually restoring
them.
Free
Copyright 2003 Sreekanth Chintala
9
Restrictions
RMAN Environment
RMAN executable
Target Database
Recovery Catalog (Optional)
A recovery catalog is a schema created in a separate
database that contains metadata obtained from the target
control file. In general, Oracle Corporation advises using a
catalog when you manage multiple databases
Copyright 2003 Sreekanth Chintala
11
Backup Types
Logical
Export
Physical
Cold (Offline)
Hot (Online)
Full
Incremental
• Differential
• Cumulative
Copyright 2003 Sreekanth Chintala
13
ArcvhiveLog vs No ArchiveLog
No ArchiveLog
No point-in-time recovery
Need to shutdown to take a backup
ArchiveLog
Hot (Online) backups are possible
Point-in-time recovery till the last available log
Incomplete recovery up to a certain Time, SCN #
or Log Sequence #.
Copyright 2003 Sreekanth Chintala
14
Definitions
Full
A full backup includes all used data blocks in the datafiles. Full
backups of control files and archived logs always include all
blocks in the files.
Incremental
A backup of datafiles that includes only the blocks that have
changed since a previous incremental backup. Incremental backups
require an incremental level 0 backup to serve as a basis.
Hot / Online
A backup of online, read/write datafiles when the database is open.
Copyright 2003 Sreekanth Chintala
15
Definitions…
Cold / Closed
A backup of any part of the target database when it is mounted but
not open.
Image Copy:
An exact, consistent copy of a datafile, controlfile or archived log
Can be used as part of point-in-time recovery
Only to disk not to tape.
Not part of incremental backup
These are OS level hot backups that can be used in recovery
without using RMAN
Copyright 2003 Sreekanth Chintala
16
Definitions...
Backup piece
A backup piece is a physical file in RMAN format that one ore
more database files reside in.
Backup set
A backup set is a logical entity consists of one more backup pieces
Channel
A server process at the target database that coordinates the reads
from the datafiles and the writes to the specified location during
backup. This is a way to parallalize backup operation.
Can be a disk channel (default) or a tape channel
Copyright 2003 Sreekanth Chintala
17
Requirements
RMAN always connects to the target database (internally) as
SYSDBA user. If you are not part of ‘dba’ group, RMAN cannot
access target database.
RMAN is a client application that attaches to the target database via
ORACLE (SQL) Net. If you are planning to run RMAN remotely,
you need to create a TNS Names entry on the machine you are
running RMAN and a password file on the server for the target
database.
RMAN needs to connect to the target database with a dedicated server
process. Shared Server (MTS) which is the default setup on 9i, will
give errors. Create a separate TNS entry that uses a dedicated server
process.
It is recommended to setup RMAN for remote connectivity for
duplication and also to connect to recovery catalog
Copyright 2003 Sreekanth Chintala
18
Backup Files
RMAN can backup
The BACKUP and COPY commands support tablespace,
datafile, archived log, controlfile, spfile and another backup
set.
RMAN performs backup operations only when an instance
has the database mounted or open, because there must be a
control file available to record the backup information
RMAN does not back up:
Online redo logs
Copyright 2003 Sreekanth Chintala
19
Connecting to RMAN
On the DB Server
Set ORACLE_SID environment variable
Configure Settings
Configure channel d1 device type disk format /backup/%d/%d_%M%D_%s_%p’ ;
Allows you to define the format for automatic channel
Scripting Options
Option 1: Running at RMAN prompt
RMAN >backup database;
Option 2: Running inside “RUN” script
RMAN > run {
2 >allocate channel c1 type disk format ‘/backup2/%d/%d_%M%D_%s_%p’ ;
3 >allocate channel c2 type disk format ‘/backup2/%d/%d_%M%D_%s_%p’ ;
4 >backup database;
5>}
Option 3: Running OS Script or Catalog script
RMAN > @cold_backup.scr
Option 4: Trough Oracle Enterprise Manager
Copyright 2003 Sreekanth Chintala
23
Cold Backup
Target database need to be in mount state in order to take cold
backup using RMAN.
RMAN > run {
2 >allocate channel c1 type disk format ‘/backup1/%d/%d_%M%D_%s_%p’ ;
3 >allocate channel c2 type disk format ‘/backup2 /%d/%d_%M%D_%s_%p’ ;
4 >shutdown immediate;
5 >startup mount;
6 >backup database;
7 >backup current controlfile;
8 >alter database open;
9>}
Copyright 2003 Sreekanth Chintala
24
Hot Backup
To perform hot backups with RMAN, the database MUST
be in ArchiveLog mode.
RMAN > run {
2 >allocate channel c1 type disk format ‘/backup1/%d/%d_%M%D_%s_%p’ ;
3 >allocate channel c2 type disk format ‘/backup2/%d/%d_%M%D_%s_%p’ ;
4 >backup database plus archivelog including current controlfile;
7 >release channel c1;
8 >release channel c2;
9>}
Copyright 2003 Sreekanth Chintala
25
Image Copies
RMAN can create an exact duplicate of the datafiles,
archive logs or controlfile.
Copy process can check for corrupted blocks.
Only one file at a time.
RMAN > copy datafile 3 to ‘/oraspace0/copy/ste3/users_001.cpy’
RMAN > copy datafile ‘/u02/oradata/ste3/users_001.cpy’ to
‘/oraspace0/copy/ste3/users_002.cpy’
RMAN > copy current controlfile to
‘/oraspace0/copy/ste3/control_001.cpy’
RMAN > copy archivelog ‘/oralog/arch/ste3/ste3_23443.arc’ to
‘/oraspace0/copy/ste3/ste3_23443_arc.cpy’
Copyright 2003 Sreekanth Chintala
26
Validate Backup
Oracle checks the most current backup set that will be
needed to recover your database, ensuring that it is
complete. This option also checks any datafile copies
and archive redo log backup sets that will be required for
recovery and ensures that they are all complete
RMAN> restore database validate;
Un-register Database
Start RMAN and get the DBID of the target database. DB ID is displayed
when you start an RMAN session.
$> RMAN target /
RMAN-06005: connect to target database RMAN (DBID=1234567890)
Use SQL Plus to connect to the RECOVERY CATALOG database as
recovery catalog owner
>sqlplus rman/rman@catlog_db
Get db_key and db_id from db
SQL>select db_key, db_id from db where db_id = 1234567890 ;
Backup Examples
Tablespace backup
Backup tablespace users;
Backup tablespace users plus archivelog include current controlfile
Datafile backup
Backup datafile 2;
Backup datafile ‘/u01/oradata/ste3/users_001.dbf’
Archivelog backup
Backup archivelog all ;
Backup archivelog from time ‘sysdate – 1 ‘;
Backup archivelog from sequence 353;
Backup archivelog all delete input;
Backup archivelog all delete input until time ‘sysdate – 2’;
Backup archivelog not backed up 3 times;
Copyright 2003 Sreekanth Chintala
29
Backup Examples…
Controlfile backup
Backup current controlfile;
Each backup can be assigned a tag
Backup database tag=‘test full backup’
Limiting the size of a backupset
Backup database maxsetsize=50m ;
Using Keep parameter to override the default retention policy
Backup database keep forever‘;
Backup database keep until time=‘sysdate + 180’ ;
Skipping Offline, Inaccessible or Read-only files
Backup database skip readonly ;
Backup database skip offline ;
Backup database skip inaccessible;
Backup database skip readonly skip offline skip inaccessible;
Copyright 2003 Sreekanth Chintala
30
Backup Examples…
Validating the backups without actually taking one
Backup validate database;
Backing up only newly added files
Backup database not backedup ;
Backup databse not backedup since time=‘sysdate-2’
Copyright 2003 Sreekanth Chintala
31
Recovery
(No ArchiveLog mode)
Recovery from the most recent backup
Backup is still available on the location where the backup
was taken
RMAN> run {
2>startup mount;
3>restore database;
4>recover database noredo;
5>alter database open resetlogs;
6>}
Since the db is in NOARCHIVELOG mode, and there are no
redo logs to apply. If the online redo logs are missing, the
NOREDO parameter is required. If the online redologs are
intact, the noredo parameter would not be needed.
Copyright 2003 Sreekanth Chintala
32
Recovery
(ArchiveLog mode)
Recovery from the most recent backup
Backup is still available on the location where
the backup was taken
RMAN> run {
2>restore database ;
3>recover database ;
4>alter database open resetlogs;
5>}
Copyright 2003 Sreekanth Chintala
33
Point-in-Time Recovery
(ArchiveLog mode)
Recovering from an older backup
Backup is still available on the location where the backup
was taken
RMAN> run {
2>set until time “TO_DATE( ’06/30/02 13:00:00’,’MM/DD/YY
HH24:MI:SS’)” ;
3>restore database;
4>recover database ;
5>alter database open resetlogs;
6>}
Assuming that controlfile is available. If not, controlfile
need to be restored before doing any recovery.
Copyright 2003 Sreekanth Chintala
34
Point-in-Time Recovery…
If ‘SET UNTIL’ is not used during recovery, RMAN tries to
recover until the last available archived log.
Point-in-Time Recovery Options
TIME: Specifies a time as an upper limit. RMAN selects only files
that can be used to recover up to but not including the specified
time. For example, SET UNTIL TIME ‘SYSDATE-7’ restores up to
a point one week ago.
RUN{
SET UNTIL TIME ‘SYSDATE-1’;
……
DUPLICATE ..; }
RUN{
SET UNTIL TIME “TO_DATE(‘01/30/2003’,
‘MM/DD/YYYY’)” ;
……
DUPLICATE ..; }
Copyright 2003 Sreekanth Chintala
35
Point-in-Time Recovery...
SCN: Specifies an SCN as an upper limit. RMAN selects only
files that can be used to recover up to but not including the
specified SCN. For example, SET UNTIL SCN 1000 chooses
only backups that could be used to recover to SCN 1000.
RUN{
SET UNTIL SCN 10003;
……
DUPLICATE ..; }
SEQUENCE: Specifies a redo log sequence number and thread
as an upper limit. RMAN selects only files that can be used to
recover up to but not including the specified sequence number.
For example, SET UNTIL SEQUENCE 8000 reports only
backups that could be used to recover through log sequence
RUN{
SET UNTIL SEQUENCE 1345 THREAD 1;
……
DUPLICATE ..; }