Objectives Learn basic concepts related the use of Recovery Manager (RMAN).
RMAN Features and Components
RMAN Components
Recovery Manager (RMAN) is an Oracle Database client - it performs backup and recovery tasks and helps automate backup strategy administration. Target database: o An Oracle database to which RMAN connects with TARGET as the keyword. o The target is the database on which RMAN is performing backup/recovery operations. RMAN Repository - the RMAN metadata. The RMAN client: o Named rman. o Located at $ORACLE_HOME/bin and is installed by default with both Oracle Standard and Enterprise editions. It is invoked from a command line argument as shown below. o The target parameter defaults to the value of the ORACLE_SID for the session. o The forward slash "/" indicates connection without connecting to a recovery catalog. o RMAN> is the prompt for recovery manager commands. o exit is the command to leave recovery manager.
Recovery Manager: Release 11.2.0.3.0 - Production on Wed Jul 10 12:06:48 2013 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: USER350 (DBID=164841282)
RMAN> exit
Recovery Catalog: One or more target databases can be cataloged in the recovery catalog. o Use of a recovery catalog (a tablespace stored in another database--not the target) is optional. o Stores RMAN metadata to enable recovery if control files are lost. The authoritative RMAN repository is always stored in the database control file. o The repository contents can also be stored in a recovery catalog database, as an adjunct to the information stored in the control file. o While RMAN is designed to work without a recovery catalog, if you choose not to use a recovery catalog, you must perform some additional administrative tasks.
Initialization Parameters
A number of PFILE initialization parameters are important for controlling backups. CONTROL_FILE_RECORD_KEEP_TIME – specifies number of days RMAN will attempt to keep a record of backups in the target control file. DB_RECOVERY_FILE_DEST – parameter specifies the location of the Fast Recovery Area. o Locate it on a file system different from any database datafiles, control files, or redo log files (online or archived). o This mitigates loss of any datafiles that might inadvertently be stored on the same disk as the Fast Recovery Area file. DB_RECOVERY_FILE_DEST_SIZE – parameter specifies the upper limit on the amount of space used by the Fast Recovery Area.
These are the PFILE settings for the USER350 database.
Fast Recovery Area – This is a location on disk to store all RMAN backups. For the USER350 database, this is located at:/u01/app/oracle/fast_recovery_area
RMAN Features
Major features of RMAN not available with traditional backup methods (operating system) or that improve significantly on traditional backup methods include: Skip unused blocks – Blocks that have never been written to in a table are not backed up by RMAN when the backup is to a RMAN backupset. Backup compression – RMAN provides a binary compression mode that optimizes compression for the typical kind of data found in Oracle data blocks. This slightly increases the CPU time required for backup and recovery. Open database backups – Tablespace backups with RMAN can be done without using BEGIN/END BACKUP clause – still must be in ARCHIVELOG mode. True incremental backups – RMAN does not write unchanged blocks since the last backup. Block-level recovery – RMAN supports block-level recovery to enable restoring or repairing a small number of blocks identified as being corrupt during the backup operation – keeps the rest of the tablespace online. Multiple I/O Channels – RMAN supports multi-threaded operations for backup and recovery. Platform independence – Backups written with RMAN commands are syntactically identical regardless of the operating system or hardware platform. Tape manager support – all major enterprise backup systems from 3rd parties support RMAN. Cataloging – a record of all RMAN backups are recorded in the target database control files – or optionally to a recovery catalog stored in a different database. Scripting capabilities – RMAN scripts can be saved in a recovery catalog for retrieval during backup sessions.
Backup Types Consistent and Inconsistent Backups – a physical backup is consistent when all datafiles have the same SCN – this only results when all changes in redo log files have committed to datafiles. An inconsistent backup results when the database is open and system users are using the database. Full backup – includes all blocks of every datafile – essentially a bit-for-bit copy. Incremental backup – RMAN supports incremental backups as level 0 or level 1. o Level 0 – a full backup of all blocks. o Level 1 – backup of only changed blocks. Image Copies – these are full backups done with operating system commands such as the LINUX/UNIX cp command, or the RMAN backup as copycommands. Backupsets and Backup Pieces – in contrast to Image Copies, backupsets can be created and restored only with RMAN. o A backupset is an RMAN backup of part or all of a database consisting of one or more backup pieces. o Each backup piece belongs to only one backupset and can contain backups of one or more datafiles in the database. Compressed Backups – Compressed backups are only usable by RMAN and require no special processing in a recovery operation – compression is automatic with RMAN.
Overview of RMAN Commands/Options
Frequently Used Commands
This table gives a list of common RMAN commands – see the Oracle Database Recovery Manager Reference for a complete listing.
Command Description @ Runs an RMAN script at the pathname specified after @. Default is current path. BACKUP Performs an RMAN backup with or without archived redo log files. Backs up datafiles, datafile copies, or performs incremental level 0 or level 1 backup. Also validates blocks to backed up with the VALIDATE clause. CHANGE Changes status of backup in RMAN repository – used to exclude a backup from a restore/recovery operation. Also used to notify RMAN that a backup file was removed by an operating system command outside of RMAN. CONFIGURE Configures RMAN persistent parameters. These parameters are available for subsequent sessions unless explicitly cleared/modified. CREATE Creates a repository catalog with RMAN metadata for one (or CATALOG more) target databases. CROSSCHEC Checks records of RMAN repository against actual disk or tape K files. DELETE Deletes backup files or copies – removes the record of the backup file from the repository. FLASHBACK Performs a Flashback Database operation such as restoration to a point in time by SCN or log sequence. LIST Displays information about backupsets and image copies. RECOVER Performs complete or incomplete recovery on a datafile, tablespace, or entire database. Can apply incremental backups to roll forward. REGISTER Registers a target database in the RMAN repository. DATABASE REPORT Provides a detailed analysis of the RMAN repository. RESTORE Restores files from image copies or backupsets to disk – usually after a media failure. Can also be used to validate a restore operation without actually performing the restore by specifying the PREVIEW option. RUN Runs sequence of RMAN statements as a group between { and } – allows overriding RMAN parameters for the group of statements executed. SET Sets RMAN configuration settings for the duration of a RMAN session – not the same as CONFIGURE. SHOW Shows all or individual RMAN configured settings. SHUTDOWN Shuts down the target database with RMAN – same as SHUTDOWN within SQLPlus. STARTUP Starts up the target database with RMAN – same as STARTUP within SQLPlus. SQL Runs SQL commands – example: sql 'ALTER TABLESPACE data01 OFFLINE IMMEDIATE'; -- before a restore/recover operation.
Starting RMAN and Connecting to a Database
Use the command rman to connect to the client.
dbockstd/@sobora2.isg.siue.edu=>rman
Recovery Manager: Release 11.2.0.3.0 - Production on Wed Jul 10 12:30:05 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
RMAN>
Use the CONNECT TARGET command to connect to a target database. RMAN connections to a database are specified and authenticated the same way SQL*Plus is. RMAN connections require SYSDBA privilege. This connects to the target (current ORACLE_SID value) by using operating system authentication - this doesn't require a separate password file that would otherwise be required.
RMAN> connect target /
connected to target database: USER350 (DBID=3391980809)
RMAN>
How to Persist an RMAN Setting
The SHOW ALL command displays default RMAN settings. Notice the target database control file is being used instead of a recovery catalog. Parameters set to default display a # default at the end of the configuration setting. Execute a CONFIGURE command to change any setting.
RMAN> show all;
using target database control file instead of recovery catalog RMAN configuration parameters for database with db_unique_name DBORCL are: CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default CONFIGURE BACKUP OPTIMIZATION OFF; # default CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default CONFIGURE MAXSETSIZE TO UNLIMITED; # default CONFIGURE ENCRYPTION FOR DATABASE OFF; # default CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_DBORCL.f'; # default
RMAN>
Retention Policy
Backups can be retained by either recovery window or by redundancy. Recovery window – RMAN will remain as many backups as necessary to bring a database to a point in time within a recovery window: o Example: a recovery window of 7 days will cause RMAN to maintain image copies, incremental backups, and archived redo log files to restore/recover a database to any point in the last 7 days. o Backups not needed for the recovery window are marked OBSOLETE and automatically removed by RMAN if a Fast Recovery Area is used and disk space is required for additional newer backups. Redundancy – RMAN retains a specified number of backups. o Extra copies beyond the redundancy number are marked OBSOLETE. o Obsolete backups are automatically removed if a Fast Recovery Area is used and disk space is required. o The DELETE OBSOLETE command can also be used to remove obsolete backups. None – this setting causes no backups or copies to ever be considered obsolete. The DBA must manually remove old backups.
Example: This sets the retention policy window to 28 days (4 weeks of retention).
RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 28 DAYS;
using target database control file instead of recovery catalog new RMAN configuration parameters: CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 28 DAYS; new RMAN configuration parameters are successfully stored
RMAN>
Device Type
If the default device is DISK and no pathname is specified, RMAN uses the Fast Recovery Area for all backups.
Keeping all backups on disk can become inefficient. This example shows configuring a tape device – the actual specification for the configuration is specific to each installation depending on the tape backup software and hardware.
RMAN> CONFIGURE CHANNEL DEVICE TYPE sbt PARMS='ENV=(<vendor specific arguments>)';
Sbt is the device type for any tape backup system for any vendor.
Backup Compression
This command demonstrates how to compress backups to save disk space.
RMAN> CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO compressed backupset;
new RMAN configuration parameters: CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 1; new RMAN configuration parameters are successfully stored
RMAN>
Backup Operations
Full Database Backup - ARCHIVELOG Mode
In ARCHIVELOG mode, you can backup a database while it is open. Termed an inconsistent backup - because redo is required during recovery. With archived redo logs, this approach is as effective as a consistent backup.
With the database open, use these steps: 1. Start RMAN 2. Connect to a target database (the one to be backed up). 3. Run the BACKUP DATABASE command.
RMAN> BACKUP DATABASE PLUS ARCHIVELOG;
Full Database Backup - NOARCHIVELOG Mode
In NOARCHIVELOG mode, only a consistent backup is valid. Database must be in MOUNT mode after a consistent shutdown. No recovery is required after restoring a backup.
Use these steps: 1. Start RMAN. 2. Connect to a target database (the one to be backed up). 3. Shutdown the database, and then mount it.
RMAN> SHUTDOWN IMMEDIATE; RMAN> STARTUP FORCE DBA; OR RMAN> STARTUP FORCE pfile=$HOME/init.ora; RMAN> SHUTDOWN IMMEDIATE; RMAN> STARTUP MOUNT pfile=$HOME/init.ora;
4. Run the BACKUP DATABASE command. This example backs up the database to the default backup device (hard disk for our databases).
RMAN> BACKUP DATABASE;
This variation on the BACKUP command will create image copy backups of all data files.
EXAMPLE: Here is the sequence of commands for a consistent backup (NOARCHIVELOG mode) of the USER350 database owned by dbockstd.
First, confirm the database is in NOARCHIVELOG mode by issuing this SQL*Plus command.
SQL> select archiver from v$instance;
ARCHIVE ------- STOPPED
Exit SQL*Plus and start RMAN.
dbockstd/@sobora2.isg.siue.edu=>rman
Recovery Manager: Release 11.2.0.3.0 - Production on Wed Jul 10 13:04:52 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connect to the target.
RMAN> connect target /
connected to target database: USER350 (DBID=164841282)
Shutdown the database immediate, restart it with FORCE option, and then shutdown immediate again to ensure it is shut down in a consistent state. Now mount the database.
First shutdown.
RMAN> shutdown immediate;
using target database control file instead of recovery catalog database closed database dismounted Oracle instance shut down
RMAN> connect target /
connected to target database (not started)
Startup FORCE option.
RMAN> startup force pfile=$HOME/initUSER350.ora
Oracle instance started database mounted database opened
Starting backup at 10-JUL-13 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=63 device type=DISK channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00001 name=/u01/student/dbockstd/oradata/USER350system01.dbf input datafile file number=00005 name=/u02/student/dbockstd/oradata/USER350data01.dbf input datafile file number=00004 name=/u02/student/dbockstd/oradata/USER350users01.dbf input datafile file number=00007 name=/u02/student/dbockstd/oradata/USER350comp_data.dbf input datafile file number=00006 name=/u03/student/dbockstd/oradata/USER350index01.dbf input datafile file number=00002 name=/u01/student/dbockstd/oradata/USER350sysaux01.dbf input datafile file number=00008 name=/u01/student/dbockstd/oradata/USER350undo02.dbf channel ORA_DISK_1: starting piece 1 at 10-JUL-13 channel ORA_DISK_1: finished piece 1 at 10-JUL-13 piece handle=/u01/app/oracle/fast_recovery_area/USER350/backupset/20 13_07_10/o1_mf_nnndf_TAG20130710T132207_8xv9lj60_.bkp tag=TAG20130710T132207 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set channel ORA_DISK_1: starting piece 1 at 10-JUL-13 channel ORA_DISK_1: finished piece 1 at 10-JUL-13 piece handle=/u01/app/oracle/fast_recovery_area/USER350/backupset/20 13_07_10/o1_mf_ncnnf_TAG20130710T132207_8xv9lr94_.bkp tag=TAG20130710T132207 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 10-JUL-13
Now open the database for normal operations.
RMAN> alter database open;
database opened
RMAN> exit
Recovery Manager complete.
The complete backup took less than one minute for this small student database.
Where is the backup? Changed directory to the fast recovery area directory. Inside was a directory for USER350 database. Changed to this directory. Listed the directories - see the backupset directory? The backup set contains a directory for the current backup (2013_07_10) and the backup set pieces are in that directory.
$ cd /u01/app/oracle/fast_recovery_area $ ls USER302 USER303 USER304 USER305 USER310 USER312 USER350 $ cd USER350 $ ls backupset $ ls -al total 12 drwxr-x--- 3 oracle dba 4096 Jul 10 13:22 . drwxrwxr-x 9 oracle dba 4096 Jul 10 13:22 .. drwxr-x--- 3 oracle dba 4096 Jul 10 13:22 backupset
This statement does a full database backup using backupsets to copy all database files to the Fast Recovery Area. If the database was started with an SPFILE, then the second command shown below would also backup the SPFILE; otherwise, it produces an error message.
RMAN> BACKUP AS BACKUPSET DATABASE;
RMAN> BACKUP AS BACKUPSET DATABASE SPFILE;
The next statement ensures that all transactions are represented in an archive log including any that occurred during the backup. This enables media recovery after restoring this backup.
RMAN> SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
sql statement: ALTER SYSTEM ARCHIVE LOG CURRENT
RMAN>
The LIST command for RMAN will show backups cataloged within the target database control file and the RMAN repository.
RMAN> list backup by backup;
List of Backup Sets ===================
BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 1 Full 346.97M DISK 00:00:05 10-JUL-13 BP Key: 1 Status: AVAILABLE Compressed: NO Tag: TAG20130710T132207 Piece Name: /u01/app/oracle/fast_recovery_area/USER350/backupset/2013_07_1 0/o1_mf_nnndf_TAG20130710T132207_8xv9lj60_.bkp List of Datafiles in backup set 1 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- --------- ---- 1 Full 620734 10-JUL-13 /u01/student/dbockstd/oradata/USER350system01.dbf 2 Full 620734 10-JUL-13 /u01/student/dbockstd/oradata/USER350sysaux01.dbf 4 Full 620734 10-JUL-13 /u02/student/dbockstd/oradata/USER350users01.dbf 5 Full 620734 10-JUL-13 /u02/student/dbockstd/oradata/USER350data01.dbf 6 Full 620734 10-JUL-13 /u03/student/dbockstd/oradata/USER350index01.dbf 7 Full 620734 10-JUL-13 /u02/student/dbockstd/oradata/USER350comp_data.dbf 8 Full 620734 10-JUL-13 /u01/student/dbockstd/oradata/USER350undo02.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 2 Full 7.30M DISK 00:00:01 10-JUL-13 BP Key: 2 Status: AVAILABLE Compressed: NO Tag: TAG20130710T132207 Piece Name: /u01/app/oracle/fast_recovery_area/USER350/backupset/2013_07_1 0/o1_mf_ncnnf_TAG20130710T132207_8xv9lr94_.bkp Control File Included: Ckp SCN: 620734 Ckp time: 10- JUL-13
Validating Backups
It is important to know if a backup is valid. VALIDATE command -- confirm that all database files exist, are in their correct location, and are free of physical corruption. CHECK LOGICAL option also checks for logical block corruption.
This command shows the use of the BACKUP VALIDATE DATABASE command to validate an entire database including the archived redo log files.
Starting backup at 10-JUL-13 using channel ORA_DISK_1 specification does not match any archived log in the repository channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00001 name=/u01/student/dbockstd/oradata/USER350system01.dbf input datafile file number=00005 name=/u02/student/dbockstd/oradata/USER350data01.dbf input datafile file number=00004 name=/u02/student/dbockstd/oradata/USER350users01.dbf input datafile file number=00007 name=/u02/student/dbockstd/oradata/USER350comp_data.dbf input datafile file number=00006 name=/u03/student/dbockstd/oradata/USER350index01.dbf input datafile file number=00002 name=/u01/student/dbockstd/oradata/USER350sysaux01.dbf input datafile file number=00008 name=/u01/student/dbockstd/oradata/USER350undo02.dbf channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03 List of Datafiles ================= File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 1 OK 0 19396 41600 620830 File Name: /u01/student/dbockstd/oradata/USER350system01.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 0 14806 Index 0 4807 Other 0 2591
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 2 OK 0 22661 41600 620959 File Name: /u01/student/dbockstd/oradata/USER350sysaux01.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 0 7680 Index 0 6456 Other 0 4803
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 4 OK 0 513 640 242283 File Name: /u02/student/dbockstd/oradata/USER350users01.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 0 0 Index 0 0 Other 0 127
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 5 OK 0 7436 7680 561103 File Name: /u02/student/dbockstd/oradata/USER350data01.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 0 63 Index 0 28 Other 0 153
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 6 OK 0 74 256 476861 File Name: /u03/student/dbockstd/oradata/USER350index01.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 0 0 Index 0 13 Other 0 169
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 7 OK 0 121 128 243029 File Name: /u02/student/dbockstd/oradata/USER350comp_data.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 0 0 Index 0 0 Other 0 7
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 8 OK 0 106 4432 620959 File Name: /u01/student/dbockstd/oradata/USER350undo02.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 0 0 Index 0 0 Other 0 4326
channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 List of Control File and SPFILE =============================== File Type Status Blocks Failing Blocks Examined ------------ ------ -------------- --------------- Control File OK 0 464 Finished backup at 10-JUL-13
This example validates individual data blocks.
RMAN> VALIDATE DATAFILE 4 BLOCK 10 TO 13;
This example validates backup sets.
RMAN> VALIDATE BACKUPSET 3;
Deleting Obsolete Backups
The DELETE command removes obsolete backups. Physically removes RMAN backup copies from disk (and tape). Updates file status to DELETED in the control file repository. Removes records from a recovery catalog (if a catalog is used). DELETE lists files and prompts for confirmation before deleting when running RMAN interactively.
The steps to follow are: 1. Connect to RMAN. 2. Run DELETE OBSOLETE command. Note here there were no obsolete backups.
RMAN> DELETE OBSOLETE;
RMAN retention policy will be applied to the command RMAN retention policy is set to recovery window of 28 days using channel ORA_DISK_1 no obsolete backups found
Other Backup Operations
Tablespace Backup
A tablespace backup should be made as soon as a tablespace is added to a database – this will reduce the time required for restoring the tablespace if media failure occurs. This uses the BACKUP command to create a backupset for the DATA01 tablespace.
RMAN> BACKUP AS BACKUPSET TABLESPACE data01;
Starting backup at 20-JUL-13 allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=252 devtype=DISK channel ORA_DISK_1: starting full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset input datafile fno=00005 name=/u01/student/dbockstd/oradata/application_data/dbockstdDA TA01.dbf channel ORA_DISK_1: starting piece 1 at 20-JUL-13 channel ORA_DISK_1: finished piece 1 at 20-JUL-13 piecehandle=/u01/app/oracle/fast_recovery_area/USER350/backups et/2013_07_20/o1_mf_nnndf_TAG20050720T170718_1fxlrp9f_.bkp comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 20-JUL-13
RMAN>
Datafile Backup
Individual datafiles may be backed up when it is impractical to backup an entire tablespace within a single RMAN session. This backs up a datafile for the INDEX01 tablespace.
RMAN> BACKUP AS BACKUPSET DATAFILE '/u01/student/dbockstd/oradata/dbockstdINDEX01.dbf';
Image Copy
Backup of copies of the database that are bit-for-bit are automatically recorded in the RMAN repository – this is an advantage over using the O/S commands. This creates an image copy of the INDEX01 tablespace.
RMAN> BACKUP AS COPY TABLESPACE index01;
Incremental Backup
The initial incremental backup is a level 0 incremental backup. Each backup after the initial incremental backup (known as a level 1 backup) contains only changed blocks and take less time. A cumulative level 1 incremental backup records all changed blocks since the last initial incremental backup. A differential level 1 incremental backup records all changes since the last incremental backup (level 0 or 1). RMAN will choose the best combination of backups when restoring a database.
RMAN> BACKUP INCREMENTAL LEVEL 0 database;
This example shows a level 1 cumulative incremental backup.
This example shows a level 1 differential incremental backup - no keyword for differential is needed as it is the default.
RMAN> BACKUP INCREMENTAL LEVEL 1 database;
Recovery Operations
RMAN can perform recovery at various levels including recovering individual blocks, tablespaces, datafiles, or an entire database. RESTORE - restores data files by retrieving them from backups. RECOVER - media recover applies changes from redo logs and incremental backups to restored data files to bring the database forward to a desired SCN or point in time.
Preparing to Restore/Recover Database Files
Recovery from media failure requires the backups to be available.
Use these steps to preview a database restore and recovery. 1. Start RMAN and connect to the target database. 2. Optionally, list the current tablespaces and data files, as shown in the following command:
RMAN> REPORT SCHEMA;
Report of database schema for database with db_unique_name USER350
List of Temporary Files ======================= File Size(MB) Tablespace Maxsize(MB) Tempfile Name ---- -------- -------------------- ----------- -------------------- 1 50 TEMP 50 /u01/student /dbockstd/oradata/USER350temp01.dbf
3. Run the RESTORE DATABASE command with the PREVIEW option. This will provide a summary .
RMAN> RESTORE DATABASE PREVIEW SUMMARY;
List of Backups =============== Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag ------- -- -- - ----------- --------------- ------- ------- ---------- --- 1 B F A DISK 10-JUL- 13 1 1 NO TAG20130710T132207 Media recovery start SCN is 620734 Recovery must be done beyond SCN 620734 to clear datafile fuzziness Finished restore at 10-JUL-13
Recovering a Whole Database
In this scenario, the datafiles have been lost, but the control file and online redo log files are on different disk sets and are available. This assumes you can restore the datafiles to their original locations.
Follow these steps. 1. Connect to RMAN. 2. Connect to the target database to be restored. 3. Startup in MOUNT state. If necessary terminate the database instance (use SHUTDOWN ABORT) if it is started and FORCE MOUNT.
RMAN> STARTUP FORCE MOUNT PFILE=$HOME/initUSER350.ora; <feedback messages about the startup in MOUNT stage are displayed)
4. Restore the database.
RMAN> RESTORE DATABASE; <feedback messages about the restore operation are displayed>
5. Recover the database.
RMAN> RECOVER DATABASE; <feedback messages about the recovery operation are displayed>
6. Open the database.
RMAN> ALTER DATABASE OPEN;
Block Media Recovery
The block media recovery is used to recover a small number of database blocks that may have become corrupted – this is preferable to recovering an entire database. Minimizes redo log application time. Reduces I/O to recover. Affected datafiles remain online and available to users (except for the corrupt database blocks).
Block corruption is often detected during a read or write (INSERT or SELECT) operation when Oracle writes to a trace file and aborts a transaction. Use the V$DATABASE_BLOCK_CORRUPTION view to identify records of corrupt blocks. RMAN must know the datafile number and block number within a datafile that is corrupt.
RMAN> BLOCKRECOVER DATAFILE 4 BLOCK 208;
Restoring a Control File
Control files can be restored from backups if you lose all copies of the control files – an unlikely event if you have multiple disk drives.
RMAN> RESTORE CONTROLFILE;
If you are not using a recovery catalog, use the FROM filename clause.
RMAN> RESTORE CONTROLFILE FROM '/u01/student/dbockstd/oradata/backup.ctl';
After recovering a control file, you must perform media recover of the database and open the database with RESETLOGS option – see the media recover documentation on the Oracle web site.
Restoring a Tablespace
To restore/recover a tablespace, the tablespace must be forced offline, restored and recovered, then brought back online. First a SQL command is executed from within RMAN to take the tablespace offline.
Restoring a datafile is similar to restoring a tablespace. Take the tablespace for the datafile offline, restore and recover the datafile, and bring the tablespace back online. The command to restore and recover the datafile requires knowing the file number assigned within the database to the datafile.
We will not do this in class. This option involves creating a tablespace in another database, such as DBORCL, and using the tablespace to store the recovery manager repository.
If a DBA elects to use a repository: The repository only needs to be created once – it can serve hundreds of databases. It should not be located in one of the target databases as this would make that database unrecoverable in the event of failure. Keep in mind that this is OPTIONAL – the target database control files can store RMAN metadata.
This sequence requires a tablespace and user to maintain metadata in a repository database. This uses the DBORCL database.
Logon to SQLPlus as a DBA to the database that will store the repository information. Create the tablespace RMAN that will store repository information.
CREATE TABLESPACE rman DATAFILE '/u02/oradata/DBORCL/rman01.dbf' SIZE 10M AUTOEXTEND ON NEXT 5M;
Tablespace created.
Create a user named RMAN that will handle backup and recovery operations and allocate privileges to this user.
CREATE USER rman IDENTIFIED BY rman001 DEFAULT TABLESPACE rman;
User created.
GRANT resource, connect, recovery_catalog_owner TO rman;
Grant succeeded.
Logoff from SQLPlus or start a second connect session. Start the RMAN software with a connection to the catalog. Note the error message that the recovery catalog is not yet installed.
Recovery Manager: Release 11.2.0.3.0 - Production on Wed Jul 10 12:30:05 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to recovery catalog database recovery catalog is not installed
The repository is created initially with the CREATE CATALOG command. This command takes a minute or two to create the objects in the repository catalog.
RMAN> CREATE CATALOG; recovery catalog created
At this point, the repository can be used by specifying the username/password on the RMAN command line with the CATALOG parameter or by using the CONNECT CATALOG command in a RMAN session.
Example: This example shows starting up the RMAN utility for the dbockstd database while specifying that the catalog repository is in the DBORCL database and the name of the repository owner is the rman user account (rman@DBORCL). The system prompts for the password of the rman user account. At this point the utility is ready for the DBA to enter a command.
Recovery Manager: Release 11.2.0.3.0 - Production on Wed Jul 10 12:30:05 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: USER350 (DBID=2717979554) recovery catalog database Password: connected to recovery catalog database
RMAN>
Registering a Database
Each database for RMAN backup/recovery must be registered in the RMAN repository if the repository is used. Records target database schema. Records database ID. Target database need only be registered once. In this example the database ORACLE_SID is USER350. This registers the database named dbockstd within the RMAN repository that is stored in the database named DBORCL.
RMAN> REGISTER DATABASE;
database registered in recovery catalog starting full resync of recovery catalog full resync complete
RMAN>
If you try to register the database twice, this results in an error message stack as shown.
RMAN> REGISTER DATABASE;
RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03009: failure of register command on default channel at 07/10/2013 11:01:06 RMAN-20002: target database already registered in recovery catalog