Vous êtes sur la page 1sur 13

4/11/2016

OracleRmanTutorial161CSC57014229

ChaitanyaMekathoti

MyBlackboard

Courses

CourseMaterials ... LecturesWeek12 OracleRmanTutorial

OracleRmanTutorial
RmanBackupTutorial
EvenifyouarenotanOracleDBA,youllstillencounterasituationwhereyoumay
havetotakeabackupofanOracledatabase.
UsingOracleRMAN,youcantakeahotbackupforyourdatabase,whichwilltakea
consistentbackupevenwhenyourDBisupandrunning.
ThistutorialgivesyouanintroductiononhowtoperformOracleDBbackupusing
RMAN.
Fortheimpatient,hereisthequicksnippet,thattakesRMANbackupofboth
databaseandarchivelogs.

RMAN>BACKUPASBACKUPSETDATABASEPLUSARCHIVELOG;

1.ViewCurrentRMANConfiguration
Beforewetakethebackup,wehavetoconfigurecertainRMANparameters.For
example,howlongyouwanttoretaintheRMANbackup,etc.
Beforewemodifyanyconfiguration,executethefollowingcommandtoviewall
currentRMANconfigurationsettings.
ToconnecttoRMAN,dothefollowingfromcommandline.Thiswilltakeyouto
RMAN>commandprompt,fromhereyoucanexecuteallRMANcommands.
https://bb.uis.edu/webapps/blackboard/content/listContent.jsp?course_id=_18002_1&content_id=_743710_1

1/13

4/11/2016

OracleRmanTutorial161CSC57014229

c:\Users\Administrator>rmantarget/

RecoveryManager:Release10.2.0.3.0ProductiononSatAug1011:21:292013
Copyright(c)1982,2005,Oracle.Allrightsreserved.
connectedtotargetdatabase:ORCL(DBID=821773)

RMAN>

ToviewcurrentRMANconfigurations,executeshowall.

RMAN>SHOWALL;

usingtargetdatabasecontrolfileinsteadofrecoverycatalog
RMANconfigurationparametersare:
CONFIGURERETENTIONPOLICYTORECOVERYWINDOWOF2DAYS;
CONFIGUREBACKUPOPTIMIZATIONON;
CONFIGUREDEFAULTDEVICETYPETODISK;
CONFIGURECONTROLFILEAUTOBACKUPON;
CONFIGURECONTROLFILEAUTOBACKUPFORMATFORDEVICETYPEDISKTO"%F";
CONFIGUREDEVICETYPEDISKBACKUPTYPETOCOMPRESSEDBACKUPSETPARALLELISM2;
CONFIGUREDATAFILEBACKUPCOPIESFORDEVICETYPEDISKTO1;
CONFIGUREARCHIVELOGBACKUPCOPIESFORDEVICETYPEDISKTO1;
CONFIGUREMAXSETSIZETOUNLIMITED;
CONFIGUREENCRYPTIONFORDATABASEOFF;

CONFIGUREENCRYPTIONALGORITHM'AES128';
CONFIGUREARCHIVELOGDELETIONPOLICYTONONE;
CONFIGURESNAPSHOTCONTROLFILENAMETO
'C:\APP\ADMINISTRATOR\product\11.2.0\DBHOME_1\DATABASE\SNCFORCL.ORA';#
default

Asyouseeabove,itdisplaysvariousRMANparametersandtheircurrentvalues.

2.ChangeFewRMANConfigurationParameters
https://bb.uis.edu/webapps/blackboard/content/listContent.jsp?course_id=_18002_1&content_id=_743710_1

2/13

4/11/2016

OracleRmanTutorial161CSC57014229

Location:Oneoftheimportantconfigurationparameterstosetwillbe,whereyou
wanttosavetheRMANbackup.Inthefollowingexample,ImsettingtheRMAN
backuplocationasC:\dbbackup\rman\

RMAN>CONFIGURECHANNELDEVICETYPEDISKFORMAT
'C:\dbbackup\rman\full_%u_%s_%p';

RetentionPeriod:Next,youshouldspecifyhowlongyouwanttoretainthebackup
for.WhenRMANtakesabackup,itautomaticallydeletesalltheoldbackupsthatare
olderthantheretentionperiod.Inthefollowingexample,Imsettingtheretention
periodas7days,whichwillkeeptheDBbackupforaweek.

RMAN>CONFIGURERETENTIONPOLICYTORECOVERYWINDOWOF7DAYS;

Verifythattheabovetwochangesaredone.

RMAN>SHOWALL;

..
CONFIGURECHANNELDEVICETYPEDISKFORMAT'C:\dbbackup\rman\full_%u_%s_%p';
CONFIGURERETENTIONPOLICYTORECOVERYWINDOWOF7DAYS;
..

ClearaParameter:Ifyouwanttoclearaparameterandsetitsvaluetodefault,use
CLEARattheendoftheconfigurationasshownbelow.

RMAN>CONFIGURERETENTIONPOLICYCLEAR;

Inthisexample,sinceweclearedtheretentionpolicysvalue,itwassettothedefault
value,whichis1.So,theretentionpolicyissetto1dayasshownbelow.

RMAN>SHOWALL;

https://bb.uis.edu/webapps/blackboard/content/listContent.jsp?course_id=_18002_1&content_id=_743710_1

3/13

4/11/2016

OracleRmanTutorial161CSC57014229

CONFIGURERETENTIONPOLICYTOREDUNDANCY1;#default

3.BackupOracleDatabase
MakesurethedirectorymentionedintheCHANNEKDEVICETYPEDISKFORMATis
created.i.ec:\dbbackup\rman\.Youneedtorunthisfromaseparatecmdwindowor
exitRMAN

cd\
mkdirdbbackup\rman

Currentlythisdirectoryisempty.Wellseewhatthishasafterthebackupistaken.

CD\dbbackup\rman
dir

total0

Wecantakeabackupusingimagecopyorinbackupset.Itisstronglyrecommended
touseRMANbackupsetstobackupthedatabase.
RMANstoresthebackupinbackupsets,whicharenothingbutwholebunchoffiles
whichcontainsthebackedupdata.OnlyRMANunderstandstheformatofthesefiles.
So,ifyoubackupanOracleDBusingRMAN,onlyRMANknowshowtoreadthe
backupandrestoreit.
TypicallywelluseBACKUPASBACKUPSETtobackupadatabase.So,totakeafull
backupofthedatabasewithoutthearchivelogs,dothefollowing.

RMAN>BACKUPASBACKUPSETDATABASE;

OR

https://bb.uis.edu/webapps/blackboard/content/listContent.jsp?course_id=_18002_1&content_id=_743710_1

4/13

4/11/2016

OracleRmanTutorial161CSC57014229

RMAN>BACKUPASCOMPRESSEDBACKUPSETDATABASE;

Ifyouwanttobackupthearchivelog,youhavetoenableArchiveMode.

SQLPLUS"/assysdba"

SQL>archiveloglist;
shouldsaydisabled
SQL>shutdownimmediate;
Waituntildatabaseisshutdown
SQL>startupmount;
Waituntildatabaseismounted
SQL>alterdatabasearchivelog;
SQL>alterdatabaseopen;
SQL>archiveloglist;

Totakeafullbackupofthedatabasewiththearchivelogs,dothefollowing:(Restart
rmanandreconnectifyouareinitinanotherwindow)

RMAN>BACKUPASBACKUPSETDATABASEPLUSARCHIVELOG;

OR

RMAN>BACKUPASCOMPRESSEDBACKUPSETDATABASEPLUSARCHIVELOG;

Youcanalsotakeabackupofonlyaspecifictablespace.Thefollowingexample
takesbackupofonlyUSERStablespace.

RMAN>BACKUPASBACKUPSETTABLESPACEUSERS;

TheRMANbackupoutputwillbesomethingsimilartothefollowing:

https://bb.uis.edu/webapps/blackboard/content/listContent.jsp?course_id=_18002_1&content_id=_743710_1

5/13

4/11/2016

OracleRmanTutorial161CSC57014229

RMAN>BACKUPASBACKUPSETDATABASE

Startingbackupat10AUG13
usingtargetdatabasecontrolfileinsteadofrecoverycatalog
allocatedchannel:ORA_DISK_1
channelORA_DISK_1:sid=193devtype=DISK
allocatedchannel:ORA_DISK_2
channelORA_DISK_2:sid=192devtype=DISK
channelORA_DISK_1:startingfulldatafilebackupset
channelORA_DISK_1:specifyingdatafile(s)inbackupset
inputdatafilefno=00025name=/u03/oradata/devdb/devuser07.dbf
inputdatafilefno=00003name=/u02/oradata/devdb/temp01.dbf
channelORA_DISK_1:startingpiece1at10AUG13
channelORA_DISK_2:startingfulldatafilebackupset
channelORA_DISK_2:specifyingdatafile(s)inbackupset
inputdatafilefno=00008name=/u03/oradata/devdb/devusers05.dbf

channelORA_DISK_2:startingpiece1at10AUG13
...
..

piecehandle=/backup/rman/full_4dogpd0u_4237_1tag=TAG20130808T114846
comment=NONE

channelORA_DISK_1:backupsetcomplete,elapsedtime:00:00:03
Finishedbackupat10AUG13
...

StartingControlFileandSPFILEAutobackupat10AUG13
piecehandle=/backup/rman/ctl_c7588181312013080800comment=NONE
FinishedControlFileandSPFILEAutobackupat10AUG13

Oncethebackupiscompleted,doanlsonthe/backup/rmandirectory,youllnowsee
https://bb.uis.edu/webapps/blackboard/content/listContent.jsp?course_id=_18002_1&content_id=_743710_1

6/13

4/11/2016

OracleRmanTutorial161CSC57014229

RMANbackupfiles.

CD\dbbackp\rman
dir

total14588

rwr1oracledba14585856Aug811:48ctl_c7588181312013080800
rwr1oracledba327680Aug811:48full_4dogpd0u_4237_1

Note:Onceabackupistaken,toviewallavailabledatabasebackupsfromRMAN,
youneedtouselistcommandthatisshownfurtherdowninoneoftheexamples.
Whilethismaybeobvious,itisworthrepeatingagain:Sincewearetakinghot
backup,theOracledatabasecanbeupandrunning.MakesureyourOracle
databaseisrunningbeforeyouexecuteanyoftheaboveRMANbackupcommands.

4.AssignBackupTAGNameforQuickIdentification
Ifyouaretakinglotofbackups,itwillbeeasiertoassignatagtoaparticularbackup,
whichwelllateruseduringOraclerecovery(orwhileusinglistcommandtoviewit).
Thefollowingexampleassignabackuptagcalled
WEEEKLY_PRD01_TBLS_BK_ONLYtothisparticularbackup.

RMAN>BACKUPASBACKUPSETTAG'WEEEKLY_PRD01_TBLS_BK_ONLY'TABLESPACEusers;

Startingbackupat10AUG13
usingchannelORA_DISK_1
usingchannelORA_DISK_2
channelORA_DISK_1:startingfulldatafilebackupset
channelORA_DISK_1:specifyingdatafile(s)inbackupset
inputdatafilefno=00002name=/u03/oradata/devdb/users_1.dbf
channelORA_DISK_1:startingpiece1at10AUG13
channelORA_DISK_1:finishedpiece1at10AUG13
piecehandle=/backup/rman/full_4fogpdb3_4239_1tag=WEEEKLY_PRD01_TBLS_BK_ONLY
https://bb.uis.edu/webapps/blackboard/content/listContent.jsp?course_id=_18002_1&content_id=_743710_1

7/13

4/11/2016

OracleRmanTutorial161CSC57014229

comment=NONE
channelORA_DISK_1:backupsetcomplete,elapsedtime:00:00:01
Finishedbackupat10AUG13

StartingControlFileandSPFILEAutobackupat10AUG13
piecehandle=/backup/rman/ctl_c7588181312013080801comment=NONE

FinishedControlFileandSPFILEAutobackupat10AUG13

Oncethebackupisfinished,ifyouviewthefilesfromrmandirectory,youllnotsee
thetagnamehere.TagnameisusedonlyfromRMANrepositoriestoviewand
restorebackups.So,nowyouseetherearemorefilesinthisdirectory,aswe've
takencoupleofbackups.

CD\dbbackup\rman
dir

total29176

rwr1oracledba14585856Aug811:48ctl_c7588181312013080800
rwr1oracledba14585856Aug811:54ctl_c7588181312013080801
rwr1oracledba327680Aug811:48full_4dogpd0u_4237_1
rwr1oracledba327680Aug811:54full_4fogpdb3_4239_1

5.ChangeOracleRMANBackupFileNameFormat
Ifyouwantthebackupfilesitselfwillbeinaspecificformat,youneedtochangethe
formatintheRMANconfigurationasshownbelow.Inthisexample,we'veappended
thetagfull_devdb_bk_prefixtoallourbackupfiles.

RMAN>CONFIGURECHANNELDEVICETYPEDISKFORMAT
"c:\dbbackup\rman\full_devdb_bk_%u_%s_%p"MAXPIECESIZE2048M;

Now,letustakeanotherbackupwiththismodifiedconfiguration.
https://bb.uis.edu/webapps/blackboard/content/listContent.jsp?course_id=_18002_1&content_id=_743710_1

8/13

4/11/2016

OracleRmanTutorial161CSC57014229

RMAN>BACKUPASBACKUPSETTAG'WEEEKLY_PRD01_TBLS_BK_ONLY'TABLESPACEPRD01;

NowwhenyouviewtheRMANfiles,youllseethenewRMANbackupfilehasthis
newfilenameformatforthefiles.Thisiseasiertoidentifycertaininformationabout
thebackupjustbylookingatthefilenames.

CD\dbbackup\rman
dir

total43764

rwr1oracledba14585856Aug811:48ctl_c7588181312013080800
rwr1oracledba14585856Aug811:54ctl_c7588181312013080801
rwr1oracledba14585856Aug811:56ctl_c7588181312013080802
rwr1oracledba327680Aug811:48full_4dogpd0u_4237_1
rwr1oracledba327680Aug811:54full_4fogpdb3_4239_1
rwr1oracledba327680Aug811:55full_devdb_bk_4hogpdef_4241_1

6.CompressaRMANBackup
Ifyouaretakingabackupofabigdatabase,youllnoticethattheRMANbackupfiles
arebigger(almostsamesizeasthedatabaseitself).
So,formostsituation,youshouldalwaystakeacompressedbackupofthedatabase.
ThefollowingexampletakeacompressedbackupofthetablepsaceUSERS.

RMAN>BACKUPASCOMPRESSEDBACKUPSETTAG'WEEEKLY_PRD01_TBLS_BK_ONLY'
TABLESPACEUSERS;

Whenyouviewthebackupfilesfromthefilesystemlevel,youwillnotseeany.gz(or
.zip,or.bz2)toindicatethattheRMANhastakenacompressedbackup.Thefile
namingconventionwillstillfollowthesameasanoncompressedbackup.
https://bb.uis.edu/webapps/blackboard/content/listContent.jsp?course_id=_18002_1&content_id=_743710_1

9/13

4/11/2016

OracleRmanTutorial161CSC57014229

CD\dbbacup\rman
dir

total58352
rwr1oracledba14585856Aug811:48ctl_c7588181312013080800
rwr1oracledba14585856Aug811:54ctl_c7588181312013080801
rwr1oracledba14585856Aug811:56ctl_c7588181312013080802
rwr1oracledba14585856Aug811:59ctl_c7588181312013080803
rwr1oracledba327680Aug811:48full_4dogpd0u_4237_1
rwr1oracledba327680Aug811:54full_4fogpdb3_4239_1
rwr1oracledba327680Aug811:55full_devdb_bk_4hogpdef_4241_1
rwr1oracledba127680Aug811:59full_devdb_bk_4jogpdl0_4243_1

Note:ThewaytotellwhetherRMANhastakeacompressedbackupornot,itby
lookingatthesize,andbylookingattheoutputoftheRMANlistcommandwhichis
showninoneofthesectionbelow.

7.ViewallRMANBackups
ToviewalltheRMANbackups,executelistbackupsummaryasshownbelow.

RMAN>LISTBACKUPSUMMARY;

usingtargetdatabasecontrolfileinsteadofrecoverycatalog

ListofBackups

===============

KeyTYLVSDeviceTypeCompletionTime#Pieces#CopiesCompressedTag

..
4215BFADISK10AUG1311NO
TAG20130808T114846
https://bb.uis.edu/webapps/blackboard/content/listContent.jsp?course_id=_18002_1&content_id=_743710_1

10/13

4/11/2016

OracleRmanTutorial161CSC57014229

4216BFADISK10AUG1311NO
TAG20130808T114849
4217BFADISK10AUG1311NO
WEEEKLY_PRD01_TBLS_BK_ONLY
4218BFADISK10AUG1311NO
TAG20130808T115413
4219BFADISK10AUG1311NO
WEEEKLY_PRD01_TBLS_BK_ONLY
4220BFADISK10AUG1311NO
TAG20130808T115600
4221BFADISK10AUG1311YES
WEEEKLY_PRD01_TBLS_BK_ONLY

Asyouseeabove,itdisplaysvariousinformationaboutthebackups.Intheabove
output,itshow7RMANbackups.ThelastcolumnshowstheTagthatwespecified
whenwetookabackup.IfwedidntspecifyanyTAG,RMANcreatesadefaulttag
withtheprefixTAGfollowedbysomenumbers.Youcanalsoseethatunderthe
columnCompressed,thelastRMANbackupshowsYES,whichindicatesthatout
ofallthe7RMANbackups,onlythelastonewascompressed.
Also,whentheRMANbackupisrunning,ifyouwanttoseetheprogress,youcan
querytheV$RMAN_STATUStablefromsql*plusasshownbelow.

SQL>SELECTOPERATION,STATUS,MBYTES_PROCESSED,START_TIME,END_TIMEfrom
V$RMAN_STATUS;

OPERATIONSTATUSMBYTES_PROCESSEDSTART_TIM
END_TIME

CONTROLFILEANDSPFILEAUTOBACKCOMPLETED1407NOV12
07NOV12
RMANCOMPLETED007NOV12
07NOV12
RESTOREVALIDATECOMPLETED007NOV12
07NOV12
https://bb.uis.edu/webapps/blackboard/content/listContent.jsp?course_id=_18002_1&content_id=_743710_1

11/13

4/11/2016

OracleRmanTutorial161CSC57014229

RMANCOMPLETEDWITHERRORS007NOV12
07NOV12
DELETECOMPLETED008NOV12
08NOV12
BACKUPCOMPLETED010AUG13
10AUG13
CONTROLFILEANDSPFILEAUTOBACKCOMPLETED1410AUG13
10AUG13
RMANCOMPLETEDWITHERRORS183210AUG13
10AUG13
RMANCOMPLETED010AUG13
10AUG13
...

8.DeleteallRMANBackups
IfyouwanttodeleteallrmanbackupsfromtheRMANlistandthefilesystem.

RMAN>DELETEBACKUP;

9.RestoreBackups
Inordertorestorethesystem,followthestepsbelow.
Ifthedatabaseisdownandthecontrolfileismissingorinvalid,youneedtorestore
thecontrolfilefirst.Thefilenameshouldbereplacedwiththenameofthebackupfile
thatcontainsyourcontrolfile.AsanexampleminewasFULL_0CPL9JH8_12_1

c:\Users\Administrator>rmantarget/

RMAN>startupnomount;
RMAN>restorecontrolfilefrom'c:\dbbackup\rman\filename';
https://bb.uis.edu/webapps/blackboard/content/listContent.jsp?course_id=_18002_1&content_id=_743710_1

12/13

4/11/2016

OracleRmanTutorial161CSC57014229

Oncethecontrolfileisrestoredthenyouneedtomountthedatabasewith.

RMAN>alterdatabasemount
RMAN>showall

Younowneedtomakesurethelocationofthechanneldeviceisthecorrectlocation
ofthebackupfiles.Ifthechanneldeviceisincorrectchangeitwiththefollowing
command.

RMAN>CONFIGURECHANNELDEVICETYPEDISKFORMAT
'C:\dbbackup\rman\full_%u_%s_%p'

Oncethechanneldeviceispointingtothelocationofthebackupfilesthenrunthe
followingcommandstocompletetherestore.

RMAN>restoredatabase
RMAN>recoverdatabase
RMAN>alterdatabaseopenresetlogs

ThereThereyouhaveit!.ThatishowyoutakeanOracleRMANbackupandsleep
peacefully.
**Thiscontentwasmodifiedfromtheoriginallocated
herehttp://www.thegeekstuff.com/2013/08/oraclermanbackup/

https://bb.uis.edu/webapps/blackboard/content/listContent.jsp?course_id=_18002_1&content_id=_743710_1

13/13

Vous aimerez peut-être aussi