You are on page 1of 22

High Availability Boot Camp: RMAN - Eliminate the Mystery

RMAN - ELIMINATE THE MYSTERY


Nelson Calero, UYOUG

RMAN is a must-have tool familiar to most Oracle DBAs. There are many capabilities hidden in RMAN and going beyond the basics is important. After a uic! revie" of the core functionality# "e "ill discuss both old and ne" features and provide tips and tric!s along "ith sample code using the $ommand %ine &nterface '$%&(.

INTRODUCTION
One of the most important tas!s of the DBA is to ensure that production data are safe# although incidents can occur and compromise hard"are# soft"are or physical facilities. )ithin our Disaster Recovery and *igh Availability plans# one of the most important components are the bac!ups. RMAN functionality is implemented in the Oracle !ernel# "ith many features to use in bac!up and recovery tas!s# available through a +%,-.% A+&. The RMAN client is a command line utility included in the installation of the Oracle database# in the /ORA$%01*OM0,bin directory# "ritten in +ro2$ that e3ecutes the +%,-.% A+&. Also there are some functionalities accessible through 0nterprise Manager# and the possibility to create your o"n scripts calling the +%,-.% A+&. The most important tas!s "e can perform "ith RMAN are4 bac!up recovery failure diagnostic 'from 55.5# Data Recovery Advisor functionality( instance duplication bac!ups history

RMAN provides several additional features in addition to the obvious tas!s e3pected of bac!ups and recovery. 6rom validating the logical and physical integrity of the bac!ups to sophisticated tas!s in a single command as the duplication of an instance. &t also presents a lot of maturity# "here there have been resolved many errors 'bugs(4 over 578 in all versions 'ref4 support.oracle.com(# and "ith fe" !no"n issues remaining in the current version 'MO- Note 9:7;55.5(. Additionally# each ne" version of the database incorporate ne" functionaliies or improves e3isting ones. 6or e3ample# 55 improvements are included in version 55.9 and 95 in version 55.5 'documented in the <ne" features< section of each manual(. Although RMAN has been available since version = of the database '$%& mode(# its adoption by users has been lo" compared to the alternative of developing scripts that perform bac!ups manually. This article "ill sho" the advantages of using RMAN# "ith e3amples to motivate those "ho do not use it yet# and help leverage their capabilities to those "ho already use it.
1 Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

BACKUP

POLICIES?

RMAN is a tool that can be used for specific actions or to implement tas!s from a bac!up policy. These policies are the ones "ho ensure that sensitive information of our organi>ation is safe# and therefore include processes and procedures that e3ceed the use of a particular tool. As an e3ample# these include the transfer of bac!ups to e3ternal sites# the rotation fre uency of the media used to store the bac!ups# use of encryption techni ues to ensure that data is not readable by third parties in case of media devices get lost# use of additional features of the database to have redundant data to be used in case of failure# etc.. The Data+ump utility# functionality such as 6lashbac! and -ecure Bac!up of the Oracle Database are other ingredients to include in a bac!up policy# that "e "ill not see here.

ORACLE

BACKUPS

The database has several files4 data 'datafiles(# control 'controlfiles(# temporal 'Temp6iles(# undo and redologs. To maintain consistency# it uses internally a number "hich identify transactions# called -ystem $hange Number '-$N(. 'http4,,docs.oracle.com,cd,055==9185,server.559,e9?7=@,transact.htmA$*D&A66*( This number is stored in several of these files. During the opening of the database is analy>ed and action is ta!en to ensure consistent data e3ist only "ith the last commited transaction# "hich corresponds to an -$N. '6or more details on this operation# see note 5B7;@@?.5 &nformation on the -ystem $hange Number '-$N( and ho" it is Csed in the Oracle Database(. To ta!e a bac!up "hile the database is do"n# the procedure is simple4 Dust copy all the files that composes the database to the ne" destination. This bac!up can be used later "ith the same result "e have on the original installation "hen opening the database after the bac!up# &f it is consistent# it "ill be consistent. &f it needs to be recovered# "e need to ma!e sure "e have all the necesary logs included on this copy at the destination site. This procedure is !no"n as cold bac!up. &t is difficult to have the option of using it in production because it implies lac! of service 'do"n time( "hile it runs and that may be diffcult to arrange. )hen the database is running# any activity of internal processes 'bac!ground( and user 'server processes( can change data files. Then# copying those files from the operating system 'using cp , copy( can generate copies that are not identical to the originals one# since the database bloc!s can be "ritten 'by the DB)R process( "hen trying to be read by the cp command# generating the problem !no"n as 6ractured Bloc! 'http4,,docs.oracle.com,cd,055==9185,bac!up.559,e58;:9,glossary.htmA$*DB6$B6(. This occurs because the O- "rite operations are not necessarily of the same si>e that the bloc!s used by the database 'typical dis! bloc!s are ?59 bytes vs database bloc!s of = Ebytes(# therefore there may be several non-atomic input,output operations for each Oracle data bloc!s. 0ven if using A-M this copy is possible# and can run into the same problem# though "ith different methods depending on the version# because from 55.5 the command cp e3ists "ithin the A-M$MD utility. To avoid this problem "hile copying# "e must tell the database that "e are doing this operation through the command A%T0R TAB%0-+A$0 B0F&N BA$EC+ GnameH# and it "ill ta!e precautions4 to free>es the modification of the -$N in datafiles header# and to "rite full data bloc! the first
! Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

time a record is modified. Archivelog should be enabled on the database to use this functionality. &t is necessary 'and very important( to run another command to indicate the end of the copy 'A%T0R TAB%0-+A$0 GnameH 0ND BA$EC+(# and thus the database starts to operate normally. )ith these actions# "hen using the restored bac!up files and open the database# the recovery process identifies that the datafiles need recovery from the moment the bac!up started 'as the -$N in the headers is less than the last !no"n to the controlfile(# so the recovery applies the redo generated that include the complete bloc!s# correcting any possible inconsistencies in e3isting data files. 6or more details# see note 58?8@B9.; I)hy Are Datafiles Being )ritten To DCR&NF *ot Bac!upJI This form of bac!up is !no"n as hot bac!up# or inconsistent. This re uires an additional tas! of recovery "hen used# therefore archived redologs generated until the end of the bac!up is needed in addition. The follo"ing is a summary of the commands used in the t"o manual bac!up strategies 'also !no"n as user managed(4 consistent 'cold(
cp /u02/oradata/* dest-bkp

inconsistent 'hot(
alter tablespace nnn begin backup; cp /u02/oradata/datafile-nnn.dbf destbkp alter tablespace nnn end backup; cp /archivelogs-path/* dest-bkp

RMAN

BACKUPS

RMAN is invo!ed by the command line and it runs as a console "aiting to e3ecute commands. The database used to perform bac!up and recovery is called <target<. &t is necessary to connect before to start e3ecuting commands# indicating the command line parameter <target<# or using the <connect< command. &t can be used a database name configured using -.%2N0T# or using <,< to connect to the local database. The user must have sysdba privilege# so -K- is usually used. RMAN stores metadata about the operations performed in a repository itself# along "ith configuration variables in the controlfile of the target database or in a proprietary database called the catalog. To ta!e a bac!up "e use the BA$EC+ command. &t can ma!e identical physical copies 'image copies( or BA$EC+ -0T-# a proprietary format# some"hat li!e TAR that can span multiple files# that stores all data bac!ed up in one or more files# called BA$EC+ +&0$0-. The latter is preferred because it creates smaller files# as e3plained later. There are several files in the database that are not re uired for recovery and "hich can be recreated "ithout loss of information# therefore they are not copied. Also# other files that are not part of the data stored in the database are not copied either. &n short# these are not copied4 temporary files 'tempfiles( and online redo logs files from e3ternal tabes or bfiles database binary files database net"or! configuration files
" Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

The copied files are4 datafiles controlfiles archived logs spfile

Csing the prior e3amples for manual bac!ups# "ith RMAN they are as follo"s4 consistent 'cold(
rman target / startup mount; backup database plus archivelog;

inconsistent 'hot(4
rman target / backup database plus archivelog;

The difference bet"een the scripts used for cold , hot cases is that in the first one the database must be open in at least mount mode to run the bac!up command. And in the second it should be in archivelog mode. Archivelog needs to be included in a cold bac!upJ. &t depends. &f the database "as do"n normally 'immediate(# then it is not necessary to do recovery# and archivelogs are not necessary. &f the database "as closed "ith a <shutdo"n abort< command or the server "as turned off# then they are re uired to do recovery "hen "e attempt to open it. This is only possible if the database is in archivelog mode# because RMAN does not allo" to ta!e a bac!up of a closed database in an inconsistent state if it is in NOAR$*&L0%OF mode 'http4,,docs.oracle.com,cd,055==9185,bac!up.559,e58;:B,rcmsynta887.htmA$*DB&A*&(. RMAN do not have the problem of fractured bloc!s "hile copying# because it !no"s the format of the bloc!s and its contents is validated "hen copying# retrying the reading of those detected inconsistent. Then# the database does not need to store additional redo "hile ta!ing the bac!up.

CONCEPTS
No" that "e !no" ho" to ma!e a bac!up# "e must !no" the concepts used by RMAN4 device4 destination of the bac!ups. &t can be dis! or tape '-BT(. channels4 is a connection to the database used to read data and "rite it to the destination device. The default value is one. -everal can be used to achieve parallelism. &mage copy4 and identical copy of a single data file# archived redo log file# or control file. bac!up sets4 an Oracle proprietary "ay of ma!ing bac!ups# "hich includes all the bac!ed up data in a TAR li!e format# having an internal table of contents# can span several files and loads multiple e3ternal files into one archive. &t is identified by a uni ue number# a date and a label 'TAF(. &t is the only format allo"ed to tape '-BT(. bac!up pieces4 are the files that ma!e up a bac!upset.

Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

bac!up status4 &ndicates "hether the bac!up is available for use 'Available( or if the file no longer e3ists in the destination '03pired(. The latter is detected by manually running the command $rosschec!# "hich is not doing automatically. obsolete bac!ups4 those not needed to meet our retention policy. They are not deleted automatically. The commands R0+ORT OB-O%0T0 is used to see "hich are the files# and D0%0T0 OB-O%0T0 to delete them from destination. incarnation4 is a number associated "ith the instance# "hich changes every time it is open "ith resetlogs. &t is important for the restore procedures# because the bac!ups are useful only in the same line of incarnations that have the current database.

CONFIGURATION
The BA$EC+ command can change its behavior "ith configuration variables or parameters that implement e3tra functionality. These variables define the behavior of some commands# or defaults values "hen not e3plicitly stated. To vie" these settings# there is the command <sho" all<. These belong to the destination database to "hich "e are connected# and they are stored in the RMAN metadata.
oracle@oraculo:~> rman target / Recovery Manager: Release 11.2.0.2.0 - Production on Thu Feb 9 16:16:00 2012 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: XE (DBID=2642191927) RMAN> show all; using target database control file instead of recovery catalog RMAN configuration parameters for database with db_unique_name XE are: CONFIGURE RETENTION POLICY TO REDUNDANCY 2; CONFIGURE BACKUP OPTIMIZATION ON; CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default CONFIGURE CONTROLFILE AUTOBACKUP OFF; 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/xe/dbs/snapcf_XE.f'; # default

The variables that "e must set in order to get our bac!up policy are4 Device4 "e "ill use dis! or tape '-BT(J The default installation uses dis!. To use tape you need to install and configure the use of a library provided by tape vendor# called media library 'MM%(.
# Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

+arallelism4 using multiple channels simultaneously for bac!up or restore of the base. &s defined at the D0L&$0. Available in 0nterprise. Retention +olicy4 6or ho" long "e "ant our bac!s available on dis!J. This is controlled by setting the R0T0NT&ON +O%&$K# "hich can be defined by R0$OL0RK )&NDO) or R0DCNDAN$K. The first is days during "hich bac!ups must be !ept# regardless of amount. The second uantity is only bac!rests. Bac!up optimi>ation4 Do not copy e3isting files identical on destination. &t is useful to shorten time in operations that failed due to lac! of space and can reuse the good copies "hen retried 'eg duplication( 0ncryption4 to seamlessly protect generated bac!ups against third parties. Re uires Advanced -ecurity option for dis! devices# or Oracle -ecure Bac!up for tape devices.

Another important configuration setting is outside RMAN. One is related to the use of the 6ast Recovery Area '6RA(. &t is controlled by parameters in the target database4 DB1R0$OL0RK16&%01D0-T1-&M0 and DB1R0$OL0RK16&%01D0-T. )ith the first one "e can put a logical ma3imum to the dis! space used by files inside the 6RA. This is important because archivelogs are automatically deleted "hen obsoleted by RMAN# so "e only need to ta!e care on proper setting its initial value# "hich must be big enough to allo" all the files needed by our retention policy. The other important parameter to consider "hen not using a recovery catalog is $ONTRO%16&%01R0$ORD1E00+1T&M0. &t defines the amount of days control file records are reused. &ts default value is 7. This must be set consistent to our bac!up policy# to avoid lose bac!up records.

SEEING

ITS CONTENTS

To see the generated files and their contents# use the <%ist bac!up< command. &n this e3ample# as "e are not using a recovery $atalog# this information is stored in the controlfile. Adding the clause <summary< you can see a summary rather than detail.
oracle@oraculo:~> rman Recovery Manager: Release 11.2.0.2.0 - Production on Fri Feb 17 11:00:13 2012 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. RMAN> connect target connected to target database: ENT11G (DBID=410442782) RMAN> list backup summary; List of Backups =============== Key TY LV S Device Type ------- -- -- - ----------1 B F A DISK 2 B F A DISK 3 B F A DISK 4 B F A DISK

Completion Time --------------13-FEB-12 13-FEB-12 13-FEB-12 13-FEB-12

#Pieces ------1 1 1 1

#Copies ------1 1 1 1

Compressed ---------NO NO NO NO

Tag --TAG20120213T122058 TAG20120213T122238 TAG20120213T122421 TAG20120213T122440

To vie" the full content of a specific bac!up 'to avoid seeing all cataloged bac!ups(# "e can filter by bac!up attributes# li!e its label 'TAF(4
$ Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

RMAN> list backup tag TAG20120213T122058; using target database control file instead of recovery catalog List of Backup Sets =================== BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------1 Full 1.03M DISK 00:00:01 13-FEB-12 BP Key: 1 Status: AVAILABLE Compressed: NO Tag: TAG20120213T122058 Piece Name: /u01/app/oracle/fast_recovery_area/ENT11G/backupset/2012_02_13/o1_mf_nnndf_TAG20120213T122058_7ml72cnz_.bkp List of Datafiles in backup set 1 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- --------- ---5 Full 1044143 13-FEB-12 /u02/oradata/ent11g/prueba.dbf

&n this e3ample you can see that it is a bac!up of a single datafile 'prueba.dbf( and "as stored in the default destination 'the 6ast Recovery Area(. This can be changed by adding the clause Iformat ,path-to-b!pI to the bac!up command. NOTE4 Dates displayed by these commands# as "ell as used as parameters to some commands in RMAN can be changed "ith the N%-1DAT016ORMAT environment variable at the operating system. 6or e3ample to include the time4
[oracle@oraculo ~]$ export NLS_DATE_FORMAT='DD/MON/YYYY HH24:MI:SS' [oracle@oraculo ~]$ rman target / Recovery Manager: Release 10.2.0.3.0 - Production on Wed Dec 21 20:31:46 2011 Copyright (c) 1982, 2005, Oracle. All rights reserved. connected to target database: Ent11g (DBID=943234298) RMAN> list backup summary tag bkp_prod_121511060003; using target database control file instead of recovery catalog List of Backups =============== Key TY LV S ------- -- -- 1 B F A 2 B F A 3 B F A 4 B F A

Device Type ----------DISK DISK DISK DISK

Completion Time -------------------13/FEB/2012 03:21:03 13/FEB/2012 03:25:42 13/FEB/2012 03:29:28 13/FEB/2012 03:35:17

#Pieces ------1 1 1 1

#Copies ------1 1 1 1

Compressed ---------NO NO NO NO

Tag --TAG20120213T122058 TAG20120213T122238 TAG20120213T122421 TAG20120213T122440

BACKUPS

IT!

ORAC"E #E

&f you use Oracle N0# the installation includes scripts to bac!up and restore the database using RMAN4 bac!up.sh and restore.sh. They are in the /ORA$%01*OM0,config ,scripts, directory. They are a good starting point to ta!e as an e3ample and customi>e as you "ish.

INCRE$ENTA"

BACKUPS

&n a database "ith several terabytes of data# a full bac!up can ta!e longer that the time available for maintenance tas!s. )ith incremental bac!ups this time can be reduced by copying only the changed bloc!s since the last incremental bac!up. There are t"o types of incremental bac!up4 differential and cumulative.
% Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

Differential4 copy only the changes since the last incremental bac!up $umulative4 copy all changes from the last full bac!up 'level 8(.

The le%el concept is similar to CN&N O- bac!up levels# but limited in the practice to 8 and 5# instead of the 8-? for O-. This simply provides a mar!er for "hich to reach bac! for the increment or difference. Therefore# to restore a database all differential bac!ups are needed since the last full bac!up# or the last cumulative bac!up follo"ing the last full bac!up. &ncremental bac!ups are differential by default. 03ample4 the first incremental bac!up must be complete# and is identified "ith the level 8.
backup incremental level 0 tablespace users;

The ne3t is level 5. &f no level 8 bac!up e3ists "hen running a level 5# it creates a level 8 bac!up4
backup incremental level 1 tablespace users;

To ta!e a cumulative bac!up4


backup incremental level 1 cumulative tablespace users;

&f you have 0nterprise version# you can enable the feature <$hange Bloc! Trac!ing< for this type of bac!up. &t !eeps a bitmap of changed bloc!s of the database since it "as enabled# avoiding to analy>e all the data bloc!s of the database each time the incremental bac!up is ta!en. This is more efficient in scenarios "here the total amount of changes are small compared to the si>e of the database# so it needs to be evaluated to your specific environment. And is the "ay to handle &'g('le ta&les)aces. As an e3ample# using Oracle Managed 6iles 'DB1$R0AT016&%01D0-T parameter(# it can be enabled "ith this command# and then "e can ta!e the level 8 bac!up4
ALTER DATABASE ENABLE BLOCK CHANGE TRACKING;

Additionally# there are &ncremental updated Bac!ups# or merged incremental bac!ups. This allo"s you to ta!e an incremental bac!up and apply it to the last full bac!up for a ne" full bac!up# "ithout reading all the destination database to create the full bac!up. The command to ta!e it is4
run { backup incremental level 1 for recover of copy with tag 'BKP_L0' database; recover copy of database with tag 'BKP_L0'; }

This type of bac!up re uires more dis! space# because it creates a ne" bac!up file in the default destination. &n the above e3ample# only one copy is !ept current at level 8# so a policy "ith redundancy 5 is used. &f "e "ant to use a recovery "indo" "ith more available copies# it is
& Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

needed to add the clause ICNT&% T&M0 ..I to the reco%er command. 6or more details on this type of bac!up# see the Note <7:?7@=.5 Merged &ncremental Bac!up -trategies<.

CO$PRESSION
There are several features in RMAN "hich helps in having more compact files. The follo"ing prevents copying unnecessary bloc!s. They are built in and no configuration is re uired to activate them4 B%O$E $OM+R0--&ON NC%% '=i( - does not bac!up empty bloc!s never used 'ie4 unformatted above *igh )ater Mar! '*)M(( CNC-0D B%O$E $OM+R0--&ON '58.9( - does not bac!up unused bloc!s 'ie4 empty under *)M( CNDO O+T&M&MAT&ON '55.5( - does not bac!up undo segments from commited transactions 'considering CNDO1R0T0NT&ON(.

A simple e3ample to see the first optimi>ation in action 'NC%% $OM+R0--&ON( is to create a tablespace and then ma!e a bac!up4
oracle@oraculo:~> du -hs oradata/XE 1.5G .oradata/XE oracle@oraculo:~> ls -lrt /usr/lib/oracle/xe/app/oracle/flash_recovery_area/XE/backupset/2010_06_03/ total 1176688 -rw-r----- 1 oracle dba 1203748864 2010-06-03 00:57 o1_mf_nnndf_TAG20100603T005534_60g9xpkz_.bkp

The free space on the database is4


01:41:16 XE>select sum(bytes)/1024/1024 mb from dba_free_space; MB ---------135.8125

$onsidering that RMAN does not include tempfiles nor redologs# 5.5Fb data "ere copied "ith RMAN against 5.?Fb "hich they had copied manually. The last feature# binary compression# must be e3plicitly enabled4 Binary $OM+R0--&ON '58g( - $ompress data before sending it to the destination. &t supports incremental bac!ups. Algorithm can be changed using the Advanced compression option '55.9(

Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

There are t"o "ays to ta!e compressed bac!ups4 set it as the default method# or e3plicitly stated in the BA$EC+ command. a( Bac!up as compressed bac!upset O b( $ON6&FCR0 D0L&$0 TK+0 D&-E BA$EC+ TK+0 TO $OM+R0--0D BA$EC+-0TP The generated files are much smaller 'from 5.5F to 988M(# at the e3pense of using more $+C4
-rw-r----- 1 oracle dba 1203986432 2010-06-03 01:31 o1_mf_nnndf_TAG20100603T013020_60gcywnl_.bkp -rw-r----- 1 oracle dba 235642880 2010-06-03 01:38 o1_mf_nnndf_TAG20100603T013720_60gdd066_.bkp

CO$PRESSION

IT!

ORAC"E#E

The script &ac*u)+s, does not have a parameter to create compressed bac!ups. Also# if "e configured compression as our database default method 'con('gure de%'ce+++( &t "onIt be used because the script includes clauses "hich ta!e precedence. This choice can be Dustified because the ma3imum amount of data handled by N0 is 55FB# and "ith actual dis! this si>e is not a problem# nor time re uired to manipulate this volume. 6urthermore# the same script &ac*u)+s, sets redundancy to 9. This ensures that "e al"ays have a valid bac!up available# but not more than t"o. Then compression is even less necessary. Both can be adDusted according to our policy# simply by modifying this script. As an e3ample# "e ta!e a bac!up "ithout compression and "ith the compression setting4 a(
rman target / CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO BACKUPSET; exit; ./backup.sh

b(
rman target / CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET; exit ./backup.sh

Once they finish# both generated files are identical4


ls -lrt /usr/lib/oracle/xe/app/oracle/flash_recovery_area/XE/backupset/2010_06_03/
1' Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

-rw-r----- 1 oracle dba 1203748864 2010-06-03 00:57 o1_mf_nnndf_TAG20100603T005534_60g9xpkz_.bkp -rw-r----- 1 oracle dba 1203986432 2010-06-03 01:31 o1_mf_nnndf_TAG20100603T013020_60gcywnl_.bkp

Revie"ing the content of the bac!up.sh script# "e found4


echo "Backup in progress..." rman target / >> $rman_backup << EOF set echo on; shutdown immediate; startup mount; configure retention policy to redundancy 2; configure controlfile autobackup format for device type disk clear; configure controlfile autobackup on; sql "create pfile=''$rman_spfile2init'' from spfile"; backup as backupset device type disk database; configure controlfile autobackup off; alter database open; delete noprompt obsolete; EOF

The bac!up command e3plicitly includes parameters that indicate ho" to ta!e bac!up# so it does not consider the default values. &f "e are interested on ta!ing compressed bac!ups# "e must modify the code of the bac!up.sh script and include this e3plicitly4
... backup as compressed backupset device type disk database; ...

INTEGRITY

VALIDATION

By default# the BA$EC+ command validates bloc! chec!sum "hen "riting to destination 'physical integrity(. Additionally# there are commands to validate logical integrity "hen ta!ing the bac!up# or directly on the data "ithout the need for a bac!up# or over already ta!en bac!up files. To detect logical corruption in data bloc!s "hile ta!ing the bac!up# the <chec! logical< clause must be included 4
backup blocks all check logical database;

To validate already ta!en bac!ups# and their availability for the restore operation# the QvalidateR clause must be included4
11 Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

restore validate database; restore validate controlfile to 'c:\temp\control01.ctl'; restore validate archivelog from sequence N1 until sequence N2;

-ince version 55.5 "e have the command LA%&DAT0#so this can be done independently of the tas!s of bac!up , recovery# "ith a variety of options that allo"s for e3ample4 validaing the entire database# a specific bac!up# a datafile# and only a fe" bloc!s from a datafile4
validate VALIDATE validate validate database; BACKUPSET 5; datafile 3; datafile 3 BLOCK 5 TO 20;

Also "e can optimi>e validations e3ecuting it on parallel# distributing reading tas! over several channels# ta!ing advantage of the ne" parameter in 55.5 -0$T&ON -&M0# "hich enables to split the reading of a single datafile in smalls chun!s4
RUN { ALLOCATE CHANNEL n1 DEVICE TYPE DISK; ALLOCATE CHANNEL n2 DEVICE TYPE DISK; VALIDATE DATAFILE 3 SECTION SIZE 1024M; }

RECOVERY
There are several critical components in the database# and in case of isolated or combined failures# there are many different scenarios and steps needed to recover the database to a consistent state. &n the official documentation there are 9 basic and 59 advanced cases. To get Dust an overvie" on the subDect# included here are only basic cases4 recover the last full bac!up# using the e3isting controlfile4
RMAN> RMAN> RMAN> RMAN> STARTUP MOUNT; RESTORE DATABASE; RECOVER DATABASE; ALTER DATABASE OPEN;

recover only one tablespace in an open instance4


RMAN> RMAN> RMAN> RMAN> SQL 'ALTER TABLESPACE mytbs OFFLINE IMMEDIATE'; RESTORE TABLESPACE mytbs; RECOVER TABLESPACE mytbs; SQL 'ALTER TABLESPACE mytbs ONLINE';

&t is important to note that4 recovery uses bac!ups !no"n by the instance 'cataloged(# leaving in our hands ensuring consistency "ith "hat "e have available. This involves the tas!s of obtaining appropriate
1! Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

bac!ups from our archived media 'tapes# DLD# etc(# use the right controlfile for the set of bac!ups to be used# and catalog them in the destination database 'either controlfile or catalog(. bac!ups are useful only in the same line of incarnations !no"n by the current database# so the controlfile to use is critical. recovery is to a point in time# so "e must have the appropriate se uence of full bac!ups and archivelogs 'or incremental bac!ups( to reach to the re uired point. &n high-volume databases# to detect that this is not "or!ing may ta!e several hours# so it is imperative to have a periodic test of these procedures# to anticipate any failures at a time "here "e have time to analy>e and correct them "ithout pressure.

WHAT

TO DO IF

STILL DO NOT USE

RMAN?

After seeing the advantages of RMAN and the time "e can save by adding it to our bac!up policy# "e have to plan the steps to get started. The first is to define the policy# including the follo"ing4 acceptable level of service4 retention destination generated file names use of parallelism ma3imum si>es of files generated use of encryption time frame for implementation and e3ecution dis! consumption and $+C usage e3pected to define the use of compression

)ith these definitions# the RMAN environment must be configured at each database. A script can be created to perform this configuration# and although it "ill be used only the first time RMAN be used by our database# it "ill serve as a bac!up of the configuration and "ill be part of the process of recreating the database on a ne" server . Then it should implement the scripts that run the bac!up. They should incorporate controls to be complete# and in addition to the statements that actually ta!e the bac!up# should include4 Delete obsolete bac!ups %ist catalog 'documentation( Lalidate logical integrity Detect errors in the e3ecution of the script and notify operators

Once the bac!ups are "or!ing# "e must remember that you must practice the various recovery scenarios# and run bac!ups regularly ta!en to validate that there are no errors in the process# or on the destinations "here they reside 'tapes# $D# e3ternal drives# etc..(.
1" Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

NOTE4 remember that the RMAN-generated files are not portable bet"een platforms# so a bac!up ta!en on &ntel B9-bit '3=;( can not be restored on &ntel ;:-bit '3=;1;:(. There is an RMAN command # $ONL0RT DATABA-0# "hich "or!s only over platforms "hich share the endian format. Details of this on QTransporting Data Across +latfromsR# http4,,docs.oracle.com,cd,055==9185,bac!up.559,e58;:9,rcm3plat.htmA$*D6*B6&

ADITIONAL
$ONITORING

TASKS

To validate the progress of a bac!up operation# the vie" L/-0--&ON1%ONFO+- may be used "hile the operation is running# "ith a uery li!e this4
SELECT SID, SERIAL#, CONTEXT, SOFAR, TOTALWORK, ROUND(SOFAR/TOTALWORK*100,2) "%_COMPLETE" FROM V$SESSION_LONGOPS WHERE OPNAME LIKE 'RMAN%' AND OPNAME NOT LIKE '%aggregate%' AND TOTALWORK != 0 AND SOFAR <> TOTALWORK;

To see the result of e3ecuted commands in RMAN since the last start of the base# the vie" L/RMAN1OCT+CT may be used# "hich e3ists only in memory. To vie" the status of the tas!s performed or in progress# there is the vie" L/RMAN1-TATC-. To vie" the bac!ups that have been ta!en on the current database# "e may use the vie"s4 L/BA$EC+1-0T L/BA$EC+1-0T1D0TA&%v/BA$EC+1DATA6&%0 L/RMAN1BA$EC+1SOB1D0TA&%-

&f using a catalog# then there is more metadata available in R$12 vie"s. 6inally# after running the command LA%&DAT0# if bad bloc!s are detected they appear in the system vie" L/DATABA-01B%O$E1$ORRC+T&ON.

$ANTEINANCE
Our bac!up scripts should include crossc,ec* statements to detect bac!up files deleted outside RMAN# and statements to periodically delete obsolete bac!ups. Both statements may be included in our bac!up script daily or "ee!ly# or run separately. &n the case of having a standby database# from version 55.5 the deletion of obsolete can be done
14 Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

immediately to the bac!# having set the AR$*&L0%OF D0%0T&ON +O%&$K TO A++%&0D ON -TANDBK. &n previous versions# the deletion of archivelogs must be separated from the bac!up to ensure that archivelogs can be sent to the standby before being deleted. if using the 6ast Recovery Area# archivelogs are automatically deleted "hen obsoleted by the retention policy. Also there are dis! uota rules for deletion "hen free space is needed# "ho can decide to delete files "hich are not obsoleted but has been bac!ed up. 6or more details about this# http4,,docs.oracle.com,cd,055==9185,bac!up.559,e58;:9,rcmcncpt.htm

!EN ERRORS

The most common errors "ith RMAN are caused by recovery procedures using incorrect bac!up files or controlfiles# such as4
RMAN-03002: failure of restore command at 12/20/2011 08:08:22 RMAN-06026: some targets not found - aborting restore RMAN-06023: no backup or copy of datafile 17 found to restore

&n case of errors that put health of our procedures in doubt# the first thing to do is to validate that "e are doing the right thing by chec!ing the official documentation 'http4,,otn.oracle.com( and My Oracle -upport 'http4,,support.oracle. com(. &f you already did that and "ant to analy>e the steps RMAN too! to get the error# then you can enable D0BCF in bac!up , restore commands# and use TRA$0 to see the channelIs activity4
rman target / log rman.log run{ allocate channel t1 type allocate channel t2 type allocate channel t3 type debug on; restore database; debug off; } trace rman.trc sbttrace=2; sbttrace=2; sbttrace=2;

Thus "e see all the internal operations performed by RMAN that can serve as a guide to trac! the problem. To address problems "ith the use of tape devices# it must be remembered that Media manager libraries 'MM%( are from third parties# and therefore can not be controlled "ith RMAN commands# )e must revie" the documentation provided by the manufacturer. 0nabling trace on the channel generates a file called sbtio.log# "ith information generated by the MM%. This must be validated "ith the manufacturer. Another alternative is to use the simulation driver provided by Oracle# D&-E-BT4
run {
1# Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

allocate channel t1 type sbt parms 'SBT_LIBRARY=oracle.disksbt,ENV=(BACKUP_DIR=d:\temp)' trace=2; backup database; }

This "ay it "ill rule out that the problem is in the read operation or at our instalation# thus "e can advance in the diagnosis and if necessary pass the problem to the manufacturer of the tape drive.

OPTIMIZATION
-erver running RMAN tas!s increases mainly its &,O activity# so "e should loo! to optimi>e the access time to devices. The points to chec! are4 using async &,O 'O.-. configuration( ade uate parallelism 'channels( to amount of tapes slots of the hard"are performance of the MM% identify "hether the problem is in reading or "riting. for e3ample# comparing the time of <bac!up validate< 'read-only operation( "ith the time of bac!up. if using incremental bac!ups and 0nterprise 0dition# enable bloc! change trac!ing. to !no" the RMAN process architecture in detail helps in the optimi>ation process. The MOnote B;8::B.5 <RMAN Bac!up +erformance< goes deeper on it. to use the standby database if Active DataFuard is available.

-ince version 55.5 -0$T&ON -&M0 parameter e3ists# "hich allo"s to generate a bac!up piece of a single datafile using smaller chun!s 'sections( in parallel# thus produce it in less time. 6or e3ample# to bac! up a tablespace "ith a datafile of @88Mb using three parallel channels4
CONFIGURE DEVICE TYPE sbt PARALLELISM 3; CONFIGURE DEFAULT DEVICE TYPE TO sbt; RUN { BACKUP SECTION SIZE 300M TABLESPACE prueba; }

6or recovery operations# "e must remember that the content of the scripts are e3ecuted serially. 6or e3ample# if "e "ant to leverage that "e have three tape drives and "ant to access them in parallel# this se uence does not succeed4
run { allocate channel allocate channel allocate channel restore datafile restore datafile

t1 type sbt....; t2 type sbt....; t3 type sbt....; 2; 3;


1$ Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

restore datafile 5; restore datafile 7; restore datafile 11; }

-ince the smallest unit of reading up to 55.5 "as the datafile# the "ay of using channels in parallel is4
run { allocate channel allocate channel allocate channel restore datafile }

t1 type sbt....; t2 type sbt....; t3 type sbt....; 2,3,5,7,11;

BACKUP

REPOSITORY -CATA"OG. E#TERNA"

)e can configure a database "hich is used e3clusively as a repository of all information maintained by RMAN. &f you manage a single database# this can add a tas! management too. But if you "or! "ith many# it gives us the possibility to have this information centrally.

FEATURES

A/AI"AB"E ON

ENTERPRISE E0ITION

ON"Y

Remember that the follo"ing features are not available in -tandard 0dition4 allocate dis! parallel channels bloc! change trac!ing encryption -- Advanced -ecurity option or Oracle -ecure Bac!up license

EXAMPLES
*ere are some e3amples of using RMAN for specific tas!s4

CLONING
Rman has the DC+%&$AT0 command "ich automates the process of creating a clone of a database. -ince version 55.9 there are many "ays to clone a database4 from active database# and from pre-e3isting bac!ups. This last one also could be connected or not to a target database# and to a catalog. All the details about this can be found in the manual4 http4,,docs.oracle.com,cd,055==9185,bac!up.559,e58;:9,rcmdupdb.htm As an e3ample# "e "ill see ho" to duplicate a database to a remote host "ith the same directory structure# in 58g and in 55.9# assuming Oracle Net $onnectivity has been already configured on the ne" server to the source database.
1% Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

12G

C"ONING

These steps must be performed to implement a clone that can be automated "ithout manual intervention. Remember that the database created by cloning is done over the ACN&%&AR connection# and the source database is the RMAN TARF0T connection. 5. set destination database environment4 parameter file# pass"ord file and directories 9. reboot the destination database in nomount mode B. get the -$N to "hich you "ant to restore from the source database. There are several "ays to do it. One possible is to loo! past -$N bac!ed archivelogs "ith the follo"ing uery4
select next_change# from v$archived_log where recid = (select max(recid) from v$archived_log where backup_count>0);

:. e3ecute the duplication on destination server4


rman catalog rman/clave@rman target sys/clave@origen connect auxiliary / run { allocate auxiliary channel dupdb1 type disk; set until scn $MAX_SCN; duplicate target database to COPIA NOFILENAMECHECK; }

?. disable archivelog on the cloned database

ON"INE C"ONING -3 11+1.


-ame 5 and 9 steps# and the :th is4
rman nocatalog target sys/clave@origen connect AUXILIARY sys/clave@copia run { DUPLICATE TARGET DATABASE TO 'COPIA' FROM ACTIVE DATABASE PASSWORD FILE SPFILE NOFILENAMECHECK SET SGA_TARGET=1000M; } exit;

1&

Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

CLONING

RAC

DATABASE

$loning a database in a RA$ environment is similar to the single instance procedure# "ith the follo"ing changes4 pfile on destination database is configured as single instance 'removing RA$ configuration( clone the same "ay as single instance pfile parameters are adDusted# adding RA$ settings removed before# and putting the correct names for the control1files and the ne" database. restart the database to use the ne" parameters configure the ne" database in all the remaining RA$ nodes4 pfile# p"file# tnsnames.ora once cloned# you must register the ne" database in $R-

Details of this procedure can be found in My Oracle -upport notes :;5:7@.5 and :?9=;=.5

DATA RECOVERY ADVISOR


This functionality# available since version 55.5# analy>e failures on the database and recommends actions to correct them# having the possibility to e3ecute the recommended scripts. &n this e3ample "e simulate the loss of a datafile4
oracle@test:> rm /u01/app/oracle/oradata/test11/users01.dbf oracle@test:> rman target / Recovery Manager: Release 11.2.0.1.0 - Production on Thu Jun 3 14:07:35 2010 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: TEST11 (DBID=3428713062) RMAN> validate database; Starting validate at 03-JUN-10 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=68 device type=DISK RMAN-06169: could not read file header for datafile 4 error reason 5 RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of validate command at 06/03/2010 14:07:50 RMAN-06056: could not access datafile 4 RMAN> list failure; List of Database Failures ========================= Failure ID Priority Status Time Detected Summary ---------- -------- --------- ------------- ------1 Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

122 missing

HIGH

OPEN

03-JUN-10

One or more non-system datafiles are

RMAN> advise failure all; List of Database Failures ========================= Failure ID Priority Status Time Detected Summary ---------- -------- --------- ------------- ------122 HIGH OPEN 03-JUN-10 One or more non-system datafiles are missing analyzing automatic repair options; this may take some time using channel ORA_DISK_1 analyzing automatic repair options complete Mandatory Manual Actions ======================== no manual actions available Optional Manual Actions ======================= 1. If file /u01/app/oracle/oradata/test11/users01.dbf was unintentionally renamed or moved, restore it Automated Repair Options ======================== Option Repair Description ------ -----------------1 Restore and recover datafile 4 Strategy: The repair includes complete media recovery with no data loss Repair script: /u01/app/oracle/diag/rdbms/test11/test11/hm/reco_2784754173.hm

The re)a'r scr')t has the follo"ing code4


# restore and recover datafile sql 'alter database datafile 4 offline'; restore datafile 4; recover datafile 4; sql 'alter database datafile 4 online';

These steps are correct because "e have a cataloged bac!up on our database# and available. &f this "ere not the case# the recommendation "ould be different4
analyzing automatic repair options; this may take some time using channel ORA_DISK_1 analyzing automatic repair options complete Mandatory Manual Actions ========================
!' Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

1. If file /u01/app/oracle/oradata/test11/users01.dbf was unintentionally renamed or moved, restore it 2. If you have an export of tablespace USERS, then drop and re-create the tablespace and import the data. 3. Contact Oracle Support Services if the preceding recommendations cannot be used, or if they do not fix the failures selected for repair Optional Manual Actions ======================= no manual actions available Automated Repair Options ======================== no automatic repair options available

Bac! to the first case# having the bac!up !no"n to the catalog# "e accept to e3ecute the recommendation4
RMAN> repair failure; Strategy: The repair includes complete media recovery with no data loss Repair script: /u01/app/oracle/diag/rdbms/test11/test11/hm/reco_3604648805.hm contents of repair script: # restore and recover datafile sql 'alter database datafile 4 offline'; restore datafile 4; recover datafile 4; sql 'alter database datafile 4 online'; Do you really want to execute the above repair (enter YES or NO)? Yes executing repair script sql statement: alter database datafile 4 offline Starting restore at 03-JUN-10 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile backup set restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/test11/users01.dbf channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/TEST11/backupset/2010_06_03/o1_mf_nnndf_TAG2010 0603T140513_60hr69ob_.bkp channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/TEST11/backupset/2010_06_03/o1_mf_nnndf_ TAG20100603T140513_60hr69ob_.bkp tag=TAG20100603T140513 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 Finished restore at 03-JUN-10 Starting recover at 03-JUN-10 using channel ORA_DISK_1
!1 Session #4 !

High Availability Boot Camp: RMAN - Eliminate the Mystery

starting media recovery media recovery complete, elapsed time: 00:00:00 Finished recover at 03-JUN-10 sql statement: alter database datafile 4 online repair failure complete

NEXT

STEPS?

This paper provides a guide to start using RMAN. There are many areas to e3pand. The follo"ing are some suggestions to continue4 03ercise recovery scenarios separating roles of DBAIs "ith one group generating failures and the other trying to fi3 them. Csing 0nterprise Manager '0M(. Many common operations "ith RMAN have their o"n screens inside 0M 'ie4 cloning# bac!up(# so it is recommended to move as much as possible of our bac!up policy to 0M to ta!e advantage of its reporting mechanisms# alerting and centrali>ed management. %earn and incorporate additional high availability functionalities included on Oracle databases# such as Dataguard and 6lashbac!.

REFERENCES
OracleT Database Bac!up and Recovery Basics - 58.9 http4,,do"nload.oracle.com,docs,cd,B5@B8;185,bac!up.589,b5:5@9,toc.htm OracleT Database Bac!up and Recovery Advanced CserIs Fuide - 58.9 http4,,do"nload.oracle.com,docs,cd,B5@B8;185,bac!up.589,b5:5@5,toc.htm OracleT Database Bac!up and Recovery CserIs Fuide U 55.9 http4,,do"nload.oracle.com,docs,cd,055==9185,bac!up.559,e58;:9,toc.htm )hatIs Ne" in Bac!up and RecoveryJ 55.5 - http4,,docs.oracle.com,cd,B9=B?@185,bac!up.555,b9=978,"nbradv.htm 55.9 - http4,,docs.oracle.com,cd,09:;@B185,bac!up.5598B,e58;:9,"nbradv.htm MO- note B;8::B.5 - RMAN Bac!up +erformance MO- note 7:8@55.5 - RMAN Restore +erformance MO- note 555;:=:.5 - Oracle -upport Master Note 6or Oracle Recovery Manager 'RMAN(

!!

Session #4 !

You might also like