学习oracle技术,每天学一点,每天进步一点

没有控制文件怎么恢复数据库dbms_backup_restore包 英文文档

上一篇 / 下一篇  2008-06-10 09:56:36 / 个人分类:rman备份与恢复

How to extract controlfiles, datafiles, and archived logs fromITPUB个人空间c'd$R_`[$CCA
                    SMR backupsets without using RMAN  
$tDML/GtX0ITPUB个人空间O]"` @7v*{Q[

/_?iD$}KmH0Introduction:
rW!W;N#L ? `0ITPUB个人空间yni(@!FpF
  When using RMAN to restore objects (datafiles, controlfiles, or archivelogs)ITPUB个人空间t p sV |a@
  from backupsets, the object restore can be driven from the recovery catalogITPUB个人空间 y%O1m%k8^1Q5] x(E
  or the target database controlfile. This note explains how to extract  
,w1z!Zu x}.X0  objects from backupsets when the recovery catalog and controlfiles have beenITPUB个人空间BOL7^^;ch
  lost. In this scenario, you effectively perform. the RMAN functions throughITPUB个人空间;k `5l9pF
  PL/SQL procedure callsITPUB个人空间v VdY3A,@
ITPUB个人空间*~Cmk(a-v9v's*Ou:\
ITPUB个人空间m!m4|0E Zkq
Contents:ITPUB个人空间,E&H)N/Sic.e?

\o]$g]v7J2?0  1. PrerequisitesITPUB个人空间TXR2N1QOO K
  2. Extracting the controlfile from a backupsetITPUB个人空间4f,B!yo'e+w;Y {O+l
  3. Extracting datafiles from a backupsetITPUB个人空间-T&?(T+x)R efI
  4. Applying incrementals
:i;nh1M2d!`0  5. Extracting archivelogs from a backupsetITPUB个人空间 ^+}}%?2fWx
  6. A typical scenario  ITPUB个人空间 nCX)I BZ${Ft
  7. Errors
Du'{#{ Hl'IC0  8. Things to be done
6X1qATB+LBZ%KFw[0
&w h0p/? e{Q-CN;xU0
:zi'o'F:b(e01. PrerequisitesITPUB个人空间4i%t#s{u!A

;Z"^!vweJ%aZ0  The customer must have a knowledge of the contents of backupsets i.e. whatITPUB个人空间6h*](_.q-u!}U
  they contain, when the backups were created, and the type of backups. IdeallyITPUB个人空间$vR'h)J_hE"UH
  they should have logs of the RMAN backup sessions that produced the  
'YbE-{P0  backupsets.ITPUB个人空间zN~'t0SLL Z f
ITPUB个人空间7a?T(m0mHgm2Ox r
  Note that the following anonymous PL/SQL blocks are run on the instance of
q g.s{A0  the database being recovered (the 'target'). The instance must be at least
,b0CKe9c HT~-X'}0  started (once the controlfile has been restored the database can also be
"B(hw3qQ0  mounted). Anonymous blocks can be executed in this manner as long as theyITPUB个人空间q A/r8B%i4BW D
  call only 'fixed' packages. The DBMS_BACKUP_RESTORE packages are fixed.ITPUB个人空间 A!pmLQ+u t0w v

y$a jX}u6d4U0  IMPORTANT: All the anonymous blocks must be executed by SYS or a user
z%y8Yg&`I@0             who has execute privilege on SYS.DBMS_BACKUP_RESTORE
"`pZPQ7i$zc9\0
(Y/tDln6TdH0
9`:IyR(P D#vt02. Extracting the controlfile from a backupset
3C!AIQ!x0ITPUB个人空间9U m4a OA6?.uP
  The first stage is to extract the controlfile from a backupset. This is  
%a CM,}vu3M Z0  achieved by making use of the following SYS.DBMS_BACKUP_RESTORE packagedITPUB个人空间Hsmy"[m`)c
  functions & procedures:
i ON AW0ITPUB个人空间p/}xp"j+o|f
    FUNCTION deviceAllocate                - allocates a device for sequential I/OITPUB个人空间zl3Aw-o+]
    PROCEDURE restoreSetDataFile        - begins a restore conversationITPUB个人空间)Fm3Qh+w f&` `8D
    PROCEDURE restoreControlfileTo        - specifies the controlfile destinationITPUB个人空间 @/y_;p'r B(`G7K c+]
    PROCEDURE restoreBackupPiece         - performs the restore
t1a^$c+zs8XMcV0    PROCEDURE deviceDeallocate                - deallocates the I/O deviceITPUB个人空间-U^/P0H.JX'lua(g

oy(Nwy;],b l0  The following anonymous block can be created and executed to restore a  ITPUB个人空间1Q.w OU'i[O'}z
  controlfile from a backupset. Before executing it, you MUST edit the blockITPUB个人空间 X zU!P.x#R2\
  as follows:
e4Dz7ch_0
v9g6R+}#BI@"H:P0    a. The filetable PL/SQL table entries must reflect the backuppiecesITPUB个人空间t n h.D`:A+g.E Ot
       comprising the backupsetITPUB个人空间'K,UUd'U!A%g3hQ[-wD
    b. The v_maxPieces variable must reflect the number of backuppiecesITPUB个人空间vQ@k@L
       comprising the backupsetITPUB个人空间,K"V:@b P:@;W
    c. The call to restoreControlfileTo must specify the correct controlfile
E `2NO)aL-m0       path & filename
B:x"Cxv"D qI0ITPUB个人空间b*\D)j@rH5Z
  IMPORTANT: The latest backup of the controlfile should be restored. BecauseITPUB个人空间}~2Cl1^ sd k V
             recovery (using backup controlfile) will be performed manually,  ITPUB个人空间,t%|,Fm-Obg
             the recovering session will need to start applying redo fromITPUB个人空间$a+x#`-Q;?2ra(I(P6f
             the current log sequence AT THE TIME OF THE CONTROLFILE BACKUP.
}:O5zt;x7EL1Ji0K0             Thus, to take advantage of incremental backups, restore a  ITPUB个人空间n7KQ#J&{:g
             controlfile taken along with the incremental backups, thus
r~ v~8_0             reducing the amount of redo required during recovery.
PHP code:

9^,Wn@x3W0
O7T+[z%o0
DECLARE 
W%K1V&mn0ITPUB个人空间.C\ X5K.r q(q
  
v_dev     varchar2(50);    -- device type allocated for restore ITPUB个人空间I$d%N$W]"_'p$_
ITPUB个人空间 w}SB5Z!G
  v_done     boolean
;    -- has the controlfile been fully extracted yet ITPUB个人空间7]_7L5hd
ITPUB个人空间7np9xOd8E*Np
  type t_fileTable is table of varchar2
(255ITPUB个人空间4v Zv f:C&A&j
ITPUB个人空间S!ZYSr,H
    
index by binary_integerITPUB个人空间Y{ Q(iI/zK \ O9t{
ITPUB个人空间(Pr.YG*x@"Bw0U
  
v_fileTable     t_fileTable;    -- Stores the backuppiece names ITPUB个人空间 og2@1I*vh\/r

(a&@@c4L}2r0  v_maxPieces     number
:=1;    -- Number of backuppieces in backupset 
#hoR(p]5R6t P0ITPUB个人空间c5c4P [0V-E rr
BEGIN 
!l l;gSx7gwj0ITPUB个人空间.A}Kz1I"n?8a
   ITPUB个人空间%L cbj{Q}k
ITPUB个人空间q*]`5H#n%G
-- Initialise the filetable number of backup pieces in the backupset ITPUB个人空间]'G.b,IR2L/n&V
ITPUB个人空间.`]M|Ll$Hh
-- This section of code MUST be edited to reflect the customers available 
,@I?4dGfhAt0ITPUB个人空间|:O!H G8d
-- backupset before the procedure is compiled and runIn this examplethe 
pN&{"S2^+W7h @0ITPUB个人空间-Vd0]5b8Rpi AL{
-- backupset consists of 4 piecesITPUB个人空间)Uw;sl!Q_o*x/Us
ITPUB个人空间"q7c~:{*d+aR0W_u
 ITPUB个人空间7m0s$uJ-IU

T'q g)mhg`9Ic0  
v_fileTable(1):='fulldb_s15_p1'
3YJ[Hf@0
Q)vi-X9O!?%N0  
v_fileTable(2):='fulldb_s15_p2'ITPUB个人空间 ~9v+f Cq

0@(R q8Kn9_.[(oL0  
v_fileTable(3):='fulldb_s15_p3'
A;SS,GP4i0ITPUB个人空间9w `6iD2`
  
v_fileTable(4):='fulldb_s15_p4'
2\s*H w kG5aun0
(` GfIPW0  
v_maxPieces:=4ITPUB个人空间R%tx ]7M6j{$n
ITPUB个人空间;S C-jUh_
  ITPUB个人空间1i.ts*d2Y F n
ITPUB个人空间%C ^.}4]J}
-- 
Allocate a deviceIn this exampleI have specified 'sbt_tape' as I am 
wu3O+U"J!e3~0
w:N4czh J!z3X0
-- reading backuppieces from the media manager. If the backuppiece is on disk
*E_p?'eB3O0
6Q3B)Hsy0-- 
specify type=>null ITPUB个人空间? o4S8E7Xnwt7eq

1gU*Y L4i-I;r0 ITPUB个人空间Z$W e(w"H BU%`

!mHT5e5tW%J0  v_dev
:=sys.dbms_backup_restore.deviceAllocate(type=>'sbt_tape'
cULP.V-~c,~0ITPUB个人空间\(F D+|0J&eHFH W
                               
ident=>'t1'); ITPUB个人空间Jd(l^7U
ITPUB个人空间$F`a`ca J
  
G{,~,N-}[a e0
o!Fi u] A~)wc0-- 
Begin the restore conversation ITPUB个人空间 O@bI8rAy#LH8Q1vr@
ITPUB个人空间q+A6w3T)nG8Q
 
2t av(d:OF0ITPUB个人空间B"p A.deUOZ` |
  sys
.dbms_backup_restore.restoreSetDatafileITPUB个人空间mS#~m;^zj

c4[m6`o]G*o-o0  ITPUB个人空间%E4h cj^7s/U,BL
ITPUB个人空间C1x:o%[ oS'j6_
-- 
Specify where the controlfile is to be recreated 
[b~#TPI0X0A0
1XXK.{J8@t0 ITPUB个人空间*a6o.g+n%^!Bu
ITPUB个人空间d v{zB kL
  sys
.dbms_backup_restore.restoreControlfileTo(cfname=>'/support2/OFA_V804/u1/oradata/dbs/ctrl1V804.ctl'); 
_k#Yl:Dh0
*ODY8G.Kr0 
&Z^z V[!As0ITPUB个人空间I3t'Y1]o0?B t w
-- 
Restore the controlfile 
n9Y~,h7]"G7v0
^m$w#i#k#_X0 ITPUB个人空间i tB:l].E.r

/L'S} ur0  
FOR i IN 1..v_maxPieces LOOP 
DG7|o4ilq0ITPUB个人空间Zf~7?{[i6B,}"|
    sys
.dbms_backup_restore.restoreBackupPiece(done=>v_done
6A\;L xG0v0
@ wF0nxEx0                           
handle=>v_fileTable(i), ITPUB个人空间'D;z.Y#vk0X:P3_L
ITPUB个人空间0DMa.U@h6r
                           
params=>null); ITPUB个人空间?o s0YhTW
ITPUB个人空间`\#@~2jM
    IF 
v_done THEN 
,y&S8\1i k)L0j t0
$GG(XA!AJ7SL0      GOTO all_done

5K:t:E6i!Q*|-Z n|0
4C*qi'z7T%y.T*u0    
END IF; ITPUB个人空间7r"Yo'[K:@/mC
ITPUB个人空间 D)x1JC&F}_{o w
  
END LOOPITPUB个人空间!T5_/_+L^5K

"gDe @r+I)[_v3R0 ITPUB个人空间 X2I4Rt#b'gY
ITPUB个人空间9K&o8f higy"Lp
<<
all_done>> 
]*bfb)c1w `x#k0
O |:x tgg0-- 
Deallocate the device 
E1^$@"w~(v{[0ITPUB个人空间MnX_XO(TW9ZA
 ITPUB个人空间z*kT8_ {_2P;E

d|)m%vmf0  sys
.dbms_backup_restore.deviceDeallocateITPUB个人空间Q b~Y Y
ITPUB个人空间"t!^?6Pljr-{7u?
 
@B~/jc0ITPUB个人空间@ a T&Ckp'X'ic
END
bJ*k\B;yq0ITPUB个人空间5h-I3C a5FR4|y

lBg+@m+U K4C0ITPUB个人空间*sapQj~![
.ITPUB个人空间yT3U&|!`2^/q

3. Extracting datafiles from a backupsetITPUB个人空间/[-V!q9u%LQ4?H&b

a^tC3J0  The second stage is to extract the datafiles from a backupset. This is
3m*RE$]d;['k$^1I/LY0  achieved by making use of the following SYS.DBMS_BACKUP_RESTORE packaged
!Y2i3V zaC0  functions & procedures:ITPUB个人空间 }+v/w'aU(v-?
ITPUB个人空间 l/{]6jr'K
    FUNCTION deviceAllocate             - allocates a device for sequential I/OITPUB个人空间4} z [^/E Ve
    PROCEDURE restoreSetDataFile        - begins a restore conversation
-A+U"?q"x`0    PROCEDURE restoreDataFileTo              - datafile number & destination
0cO!` iB0    PROCEDURE restoreBackupPiece        - performs the restore
}.y| L8V'y*J0    PROCEDURE deviceDeallocate          - deallocates the I/O device
}d!M-N)hG0ITPUB个人空间}~8h!g:|p
  The following anonymous block can be created and executed to restore aITPUB个人空间xPy+B^P:x
  datafile from a backupset. Before executing it, you MUST edit the block
1?2W'j%P _,kMA0  as follows:  ITPUB个人空间M-v0bz.?1c7Q({J]
ITPUB个人空间*h]Nw"\ J\
    a. The filetable PL/SQL table entries must reflect the backuppieces
(P$h D7W$y0       comprising the backupsetITPUB个人空间5Cd+A:IFe4}$di
    b. The v_maxPieces variable must reflect the number of backuppiecesITPUB个人空间C(LPs3YB
       comprising the backupsetITPUB个人空间!A ].F/R\ P#h
    c. The call to restoreDataFileTo must specify the correct datafile number,
5j uukrrQ+N0       and datafile path & filename
PHP code:
ITPUB个人空间4z4?1oJ!f'Ml

] h6P{_elXLm,K0
DECLARE 
]1``-tC^GX0
2?;a.r C,\'R)~:i0  
v_dev        varchar2(50);        -- device type allocated for restore ITPUB个人空间8B ?S.a*w*N+jV
ITPUB个人空间3\ST `^ ?:H9K&{
  v_done    boolean
:=false; -- has the datafile been fully extracted yet ITPUB个人空间U*]4aC%]MA8h;[
ITPUB个人空间2Vg;v3S"qAF w
  type t_fileTable is table of varchar2
(255
fiV,P'D#V'nK&h0
#v$}&G#o(u6r0    
index by binary_integer
1Y3t6DLr9S0
L [] O*xL N0  
v_fileTable     t_fileTable;        -- Stores the backuppiece names ITPUB个人空间|6Q5ZT1`X

0P)WVu@&i x+_0  v_maxPieces     number
:=1;        -- Number of backuppieces in backupset ITPUB个人空间 U4U ?0r5V}*X0a
ITPUB个人空间q%~0}J i?
BEGIN 
p |.Dc p W3FP0ITPUB个人空间lAds;V
 
psl"R/bgAWY0ITPUB个人空间 bN2f1?^m,K:g
-- Initialise the filetable number of backup pieces in the backupset ITPUB个人空间?v hfUC
ITPUB个人空间{ BnU"J-G[6Jf[
-- This section of code MUST be edited to reflect the customers available ITPUB个人空间]Egz A,P#dB/V
ITPUB个人空间 E9k*F,x.?t"N'X/v
-- backupset before the procedure is compiled and runIn this examplethe 
#S(h#v;}5x:~r0
3BgGpT*X3Af]0
-- backupset consists of 4 pieces
6G){_^'E)IXw3Z0ITPUB个人空间q8X)?}(rP
 
5a}#jb&d+]BJ~0
,_#gFDf2|^u0  
v_fileTable(1):='fulldb_s15_p1'
s!yk Bf2c [7H!K;q;L0
)F5t|F,LL-_0\6y0  
v_fileTable(2):='fulldb_s15_p2'ITPUB个人空间$T0Y&^6TV$Ns

3} @1TD T0  
v_fileTable(3):='fulldb_s15_p3'
)I H*N d2z9jT0u O:d0
1o'KtQz^'C u(Z1D0  
v_fileTable(4):='fulldb_s15_p4'ITPUB个人空间 TE[!ZR{%`
ITPUB个人空间]:r0r8NQ-F!q
  
v_maxPieces:=4
'`)C ]GKU?0ITPUB个人空间*b;G%p*U*Et#Ln
  
SgRqJvk0
3q7K_,Q.Uz-V3CKx0-- 
Allocate a deviceIn this exampleI have specified 'sbt_tape' as I am ITPUB个人空间"{\^"V2uFT,zq
ITPUB个人空间)E(k} dH
-- reading backuppieces from the media manager. If the backuppiece is on disk
[H8Y ^']Kp0B0ITPUB个人空间2d-I{a1V.[ moa8S
-- 
specify type=>null 
&orDhN,F[7Du_0ITPUB个人空间 Q*d%[#a&W_
 ITPUB个人空间P"KP!G l?%_-X:@

PM%zPORLuj_0  v_dev
:=sys.dbms_backup_restore.deviceAllocate(type=>'sbt_tape'
yI]Dn0
eH B,A"F4i8Q0                            
ident=>'t1'); ITPUB个人空间K+?C5u^V^
ITPUB个人空间0Ih)xV H/S
  
|:g z y xI"`N^*M0ITPUB个人空间K(|'Ux&l'`
-- 
Begin the restore conversation 
S2l^_ H7f/CR0
"CRfY] Ft-o0 ITPUB个人空间$e+e5o[.O

:C$y"@z OT0  sys
.dbms_backup_restore.restoreSetDatafile
4eJ,E!n%S m4KYb0p0
u%Dl:Tv0  ITPUB个人空间 I%j-|y`Y i
ITPUB个人空间MPy1e}q
-- 
Specify where the datafile is to be recreated 
)]s7H uL0
&dD] r9h5R d7S!a0 ITPUB个人空间 _;Z5t5KFS
ITPUB个人空间 w;c dMI8V"j2mX'[
  sys
.dbms_backup_restore.restoreDataFileTo(dfnumber=>1
!Z.]$M!n#E$j0
!A3bdQ/t/DUK0        
toname=>'/support2/OFA_V804/u1/oradata/dbs/sysV804.dbf'); ITPUB个人空间9QdtI9?{U@c

sN _ x0{ J ^0  ITPUB个人空间"hW[m4|g7Xk
ITPUB个人空间i/rE{U8p2\3q#p f8~
-- 
Restore the datafile 
~;ml8jV@H3Q+W c0ITPUB个人空间v2mtTqyJ-l8d
 ITPUB个人空间jm*wb mO

:u:l:S@ z3H1I0  
FOR i IN 1..v_maxPieces LOOP 
)@C,B$x:c2ku'Q0ITPUB个人空间fYH}3l#H8\J
    sys
.dbms_backup_restore.restoreBackupPiece(done=>v_doneITPUB个人空间 ?g3g z6u|:l
ITPUB个人空间8M2O%k*l?j H
                           
handle=>v_fileTable(i), 
/f0X^f f zLO0
#or'IG.fMw7fhG0                           
params=>null); 
tS`8@+z w0
D-E.Dl c3i'B7f5d_Xm0    IF 
v_done THEN 
fc;Lw{/n0ITPUB个人空间(~,Y|2n6|1sZ
      GOTO all_done

/yT7O i]/CjV0ITPUB个人空间R2W&X S9{
    
END IF; 
r0Oow5n3Z&C2M0ITPUB个人空间3u._)W x,\g6F
  
END LOOPITPUB个人空间6}-|7hG&g2xt0_?
ITPUB个人空间)Bj3P"p/P
 ITPUB个人空间|9Ug x No,V!g

w8G$S,tI)Yw e0]0<<
all_done>> 
QYAj _'{Isg0ITPUB个人空间.n*s3yb8pF
-- 
Deallocate the device 
L4n$lRE{&AJq8t0
#J&jFsP tw0  sys
.dbms_backup_restore.deviceDeallocate
4s{ |!XN0x6e0
Ju(i4Qa#U$C,E0 ITPUB个人空间"}^3?R:b*wHX

D i5Om"L2yO0
ENDITPUB个人空间]|+r2ex3? c!Wr

Z2?(e+K!b.K0
2ZI.ZC b;i0ITPUB个人空间*{hPx"gH
.
^h_f.l|%\+^0

4. Applying incrementalsITPUB个人空间 Rv+x&M%zv,F

k4xP Is P:u0  If incrementals are to be applied, you must execute this anonymous blockITPUB个人空间yOJ7a(@F3{v@
  for each incremental datafile backup. The following SYS.DBMS_BACKUP_RESTOREITPUB个人空间?w"@;F0i,EKW
  packaged functions & procedures are called:ITPUB个人空间5cn^2WWu)N*A,B9F
ITPUB个人空间r,a8aXpt
    FUNCTION deviceAllocate             - allocates a device for sequential I/OITPUB个人空间HOD+w%R b [g
    PROCEDURE applySetDataFile          - begins a restore conversationITPUB个人空间 d-Tca8T \X
    PROCEDURE applyDataFileTo           - datafile number & destination
(G:^c4s~| H0    PROCEDURE applyBackupPiece          - performs the restore
y5}`7o2Q{p:fSh0    PROCEDURE deviceDeallocate          - deallocates the I/O deviceITPUB个人空间YKQSowN@5S
ITPUB个人空间g6Lp _y \o
  The following anonymous block can be created and executed to restore aITPUB个人空间kI6@9Y6DW
  datafile from a backupset. Before executing it, you MUST edit the block
&Xo#K]\0j;h.kA0  as follows:ITPUB个人空间k Qjb~}'Yf

? g*n1E.y5i0    a. The filetable PL/SQL table entries must reflect the backuppieces
!mE+WSP$c0       comprising the backupsetITPUB个人空间,l5[!H{iD&J"K
    b. The v_maxPieces variable must reflect the number of backuppieces
%J5M g0{C _m+x0       comprising the backupset
/j#B3p,{(|5U_0    c. The call to applyDataFileTo must specify the correct datafile number,
;T;DWh0W d9k7o0       and datafile path & filename
PHP code:

0N/e%Fk0Xi9J&C ab(dD0ITPUB个人空间U!`.j_/`nW9F*o@
DECLARE ITPUB个人空间4n3j)F|~$Z`
ITPUB个人空间Y2^J.M/@ C
  
v_dev           varchar2(50);           -- device type allocated for restore ITPUB个人空间P@TP5G&rTy
ITPUB个人空间 [J'Xc8h
  v_done          boolean
:=false;  -- has the datafile been fully extracted yet ITPUB个人空间$kc:b8Ojf([`5U

"]R~N![3o8_1[0  type t_fileTable is table of varchar2
(255ITPUB个人空间g`j.lY
ITPUB个人空间-kG)T![%V
    
index by binary_integerITPUB个人空间LOT6w-ccS

SurFq8_7x X"F e7~0  
v_fileTable     t_fileTable;            -- Stores the backuppiece name ITPUB个人空间3Cd6{3k,^5T

j9{e#c;IV$}e9e0  v_maxPieces     number
:=1;              -- Number of backuppieces in backupset 
2G |aI0Bndh0ITPUB个人空间6g7Q1O,v ?oN z9|lM
BEGIN 
nQ0{j[ [|#J0ITPUB个人空间Q#[i1W U"E%}e
 ITPUB个人空间N,Y O(a$K MDm"x3\X

JF&p.cgJ`0
-- Initialise the filetable number of backup pieces in the backupset 
!b6ldu|Eaz0
}YSH1Y-J8aW:n0
-- This section of code MUST be edited to reflect the customers available ITPUB个人空间4t\hEbg[

(o:h@/a z%f3D+l0
-- backupset before the procedure is compiled and runIn this examplethe 
!h5BwQV`0ITPUB个人空间,\ x]x-j(n
-- backupset consists of 1 piecea level 2 backupsetITPUB个人空间`#V'y8H!z@8y

r(Z:W+vd$Q0 ITPUB个人空间5n8nIrI:hU6N

-sT8^[-O tp0  
v_fileTable(1):='fulldb_level2_s18_p1'
L ej In-af'`0ITPUB个人空间G3b"R&Ls q)B@H&t
  
v_maxPieces:=1
s1]/OBK)Q+u0
$s9n6?f-u-hL2n0 ITPUB个人空间;r!bZ[7h#[ V:sD6`1~
ITPUB个人空间M@L+b4Q]2_(_r
-- 
Allocate a deviceIn this exampleI have specified 'sbt_tape' as I am 
Q(k5jh)T.A0
6b3T-bWN h!ga3E s#g0
-- reading backuppieces from the media manager. If the backuppiece is on diskITPUB个人空间)_H9Vi| i OR

9L?%t{m:?RG"E0-- 
specify type=>null ITPUB个人空间m-P ] O ?;U$o'Gf
ITPUB个人空间DNp)Z3N%t{,d
 ITPUB个人空间*Y ~;EBO Y;`W

3bM.svln(R^-XQmx0  v_dev
:=sys.dbms_backup_restore.deviceAllocate(type=>'sbt_tape'
|a0G _@z\7_7rvt~ O0
g IV4m4y8?L~$w@0                                                
ident=>'t1'); ITPUB个人空间bG{3R|

x{]k6s ~'w3dQ0 
-w9hk't^*@r}Eo0ITPUB个人空间|U}.[JrXC
-- 
Begin the restore conversation 
t3x%a a }Vba0
#a/K;A;k&|N'ex}0 
X}:Er{fg!r+F0R0ITPUB个人空间7YV%@M%Y+es7z
  sys
.dbms_backup_restore.applySetDataFileITPUB个人空间;i e,F-FiP&G

s}6z6ifz%SP0 
1iQ7R/pPlw0ITPUB个人空间7vO.~9NEjT
-- 
Specify where the datafile is to be recreated ITPUB个人空间"pPM:d%~^

1?$cL$bbl(Q;A0 
){,g3b(G%OY9L@)D0ITPUB个人空间,lvi&Wy6L0W M*w
  sys
.dbms_backup_restore.applyDataFileTo(dfnumber=>1ITPUB个人空间M(F6t_kb/\ i*h

9b"o2AJ&`"Q;w0                
toname=>'/support2/OFA_V804/u1/oradata/dbs/sysV804.dbf'); ITPUB个人空间o a-Y)KI_8F;_
ITPUB个人空间@&@1\s;Vw7[
 ITPUB个人空间[.t$ta`

P_ m,l_;d qa"ty v0-- 
Restore the datafile ITPUB个人空间)z/iKK9mu4Ku
ITPUB个人空间 XCa%iOZ4HO c
  
FOR i IN 1..v_maxPieces LOOP ITPUB个人空间*k s9u0~diO;{;mU3\|mo
ITPUB个人空间D0T@k(e,N
    sys
.dbms_backup_restore.applyBackupPiece(done=>v_done
| w2F m2\_6E,S$VM0
'tZ:VNS{+Q0                                             
handle=>v_fileTable(i), ITPUB个人空间;fM-~$lioq+l^
ITPUB个人空间C;Um_j"o,}9P
                                             
params=>null); ITPUB个人空间 [@zx5qi T Ri
ITPUB个人空间.h qCM \rK)C
    IF 
v_done THEN 
pLl^'wY!F0
]qX!M[*g0      GOTO all_done

_)k.Ne(T \%h6Ou!@'T0ITPUB个人空间;j5C A5uN'H!N
    
END IF; 
BcuGl_0X.Z9br0ITPUB个人空间#`#WNv@
  
END LOOP
u J$t\F$q_0ITPUB个人空间2RTAJ;P:_F
<<
all_done>> 
+wP/?,i x!JA0
9oT$NU2xK5SB}0-- 
Deallocate the device 
[?%ub-P/fz6k5c"B0ITPUB个人空间gY6h]^z
  sys
.dbms_backup_restore.deviceDeallocate
+Y.Z&JW.V~"}!h3sq0
lv!D.mK4]8P0 
JG1k*^iW;]&r0
4Sji(l!\7?5h0
END
pZkB;SZIZ3V"s0
?#D;yWFx0ITPUB个人空间6?,j$P a M@x:vl:{

$uY(U(W$t}0.
^ X [#D%pW0_0

5. Extracting archivelogs from a backupset
zz-uFD V9E0ITPUB个人空间,` X%u)M^^N,`0`
  The last restore stage is to extract the archivelogs from a backupset. This isITPUB个人空间 J9W Y h-{-R$l(qP%?)t r
  achieved by making use of the following SYS.DBMS_BACKUP_RESTORE packagedITPUB个人空间z7w;kcG T `
  functions & procedures:ITPUB个人空间 |z&|*Pv/_*W-V2} D+N
ITPUB个人空间_z ]5@7Ll/`
    FUNCTION deviceAllocate             - allocates a device for sequential I/O
qSJ$o,w7\"{b0    PROCEDURE restoreSetArchivedLog     - begins a restore conversationITPUB个人空间7q uY xGQ2cg H
    PROCEDURE restoreArchivedLog        - archivelog sequence & thread numbersITPUB个人空间i-fo7W8E0z1D
    PROCEDURE restoreBackupPiece        - performs the restore
Mbs$PlT(?0    PROCEDURE deviceDeallocate          - deallocates the I/O device
;dF*Ket#|Z`YU0
1~ jr L#V-l F0  The following anonymous block can be created and executed to restore  
PKNS!uE0  an archivelog from a backupset. Before executing it, you MUST edit the block
(?s2j7`,~p p4j0H d~0  as follows:ITPUB个人空间)D&A)T3YF!R2eH N(M

(s,V tfd"lPCf0    a. The filetable PL/SQL table entries must reflect the backuppiecesITPUB个人空间Z2ov1X s
       comprising the backupset
i/hTT CB-qo#sN0    b. The v_maxPieces variable must reflect the number of backuppieces
@$j0` TvUDfKtLL0       comprising the backupsetITPUB个人空间 m oP @,Dj.Vr Pc
    c. The call to restoreSetArchivedLog must specify the destination
9JF;y|ck:X0       where the archivelog is to be restored. Ideally the destination stringITPUB个人空间 ty/h1h;j4K
       should be the same as init.ora:log_archive_dest
L;S7A"[)n}_0    d. The call to restoreArchivedLog must specify the log sequence numberITPUB个人空间N"@h-n2T
       and thread number of the archivelog
PHP code:

-f5hZ9S(h{&`f`"|0ITPUB个人空间n ~LA;Q \ Joj
DECLARE ITPUB个人空间oi3LB M6C%D*j&_X
ITPUB个人空间W"MNzPJ%o9]W
  
v_dev      varchar2(50);    -- device type allocated for restore 
q)su5L~LF,X}0
7E3Zy!S;s4tKx0  v_done     boolean
:=false; -- has the log been fully extracted yet 
-m-Or w U"A;o0
z1fzZ8N O0  type t_fileTable is table of varchar2
(255ITPUB个人空间,xUHoZ

^7ZJ!q)Z'})Vh'Y5S0    
index by binary_integer
.k3YM n C0
5g$lXS+MIt/i0  
v_fileTable     t_fileTable;    -- Stores the backuppiece names 
q.N'[q*VkR0
IxPA+y#R'a#S0  v_maxPieces     number
:=1;    -- Number of backuppieces in backupset ITPUB个人空间fD:o ?WFh"Q
ITPUB个人空间 EU.t9^:J{I4XC
BEGIN ITPUB个人空间LJ9[ ]0b.p1L
ITPUB个人空间 U mq9U},qi
 
|5~#xH |T/z0ITPUB个人空间$m%Ka.@ F Aq-t
-- Initialise the filetable number of backup pieces in the backupset ITPUB个人空间m D'SGfEG~

D dm2G:i0
-- This section of code MUST be edited to reflect the customers available ITPUB个人空间S9a^}w2sb
ITPUB个人空间msjl:n}c
-- backupset before the procedure is compiled and runIn this examplethe 
0C(k@m5Av0
n8f7~$Y5E){oyS0
-- archivelog backupset consists of 2 piecesITPUB个人空间G8B bC&UW-\
ITPUB个人空间 m9^8Cs+c4E"mS @$_A
 
P h}&j2X`0N u%Y0ITPUB个人空间P7g(r:W.D_pn
   
v_fileTable(1):='al_s20_p1'ITPUB个人空间 T2C^s6CU x
ITPUB个人空间Q*dE @7QtRc,V:^
   
v_fileTable(2):='al_s20_p2'
;Yna4Mu9y'Pa&K8^{_0
mY,W2f0RN0   
v_maxPieces:=2
^Zi3Xy:d%c1aS0ITPUB个人空间CR9Nr{
  
C7]W#lC0ITPUB个人空间%y,fTA)DsR-Qf
-- 
Allocate a deviceIn this exampleI have specified 'sbt_tape' as I am 
|7w [ \-B;E!b0
8Y4};v)j?6t.P(J0
-- reading backuppieces from the media manager. If the backuppiece is on diskITPUB个人空间sB?|atJo
ITPUB个人空间p&?*fL0UR A[
-- 
specify type=>null ITPUB个人空间X8dGJ4]fz#?

'n$XLR*w2t8toM0 ITPUB个人空间 oF3Q fk/l;|_
ITPUB个人空间-eew$o?7x0QPR
  v_dev
:=sys.dbms_backup_restore.deviceAllocate(type=>'sbt_tape'
8T!p @8{._y0
8PK3{xa-n0                            
ident=>'t1'); 
#O8K#@&i/aM0ITPUB个人空间0IL A)f+r0j%V
  
PU"v;Tn#H0ITPUB个人空间h r}QiV%B8Jv
-- 
Begin the restore conversation ITPUB个人空间$p V(b:P;L'`DD,jYjI
ITPUB个人空间*c4ck9H#s OZ&g
 
^&MG%| C Nk0
8EZz}G.o0  sys
.dbms_backup_restore.restoreSetArchivedLog(destination=>'/support2/OFA_V804/app/oracle/admin/arch/arch_'); 
@ E%q F3U ^'\`0ITPUB个人空间Jc)\Ol E
  ITPUB个人空间:f [wEBO(Z1[0n

Q/UJI.L(w+M0-- 
Specify where the archivelog is to be recreated 
y*^6Z(@ep4V0ITPUB个人空间E-y @ HB"E*nO6d
 
5h6Y&EF0suh1V)Y0
(lTA%E%M5L[4|0  sys
.dbms_backup_restore.restoreArchivedLog(thread=>1ITPUB个人空间"}WT*O7|'Jy/Hi%Y

T6wb U o e0                         
sequence=>100); 
G5Eq'Z oQ5K:A N%g~ b;z0ITPUB个人空间@3B p j*E$e-r
 
v`i O-f.y0
Q\;{"fMy0-- 
Restore the archivelog 
zPpX^h opl0ITPUB个人空间SS!kC gc'Y4e
 ITPUB个人空间,?q \'T G3f ub7u@$D0^

3jR:L4N5U0  
FOR i IN 1..v_maxPieces LOOP 
jp3@!A o0ITPUB个人空间0t Dx l2`Z!c}
    sys
.dbms_backup_restore.restoreBackupPiece(done=>v_done
.R M_(P h X6q'p0ITPUB个人空间Zo`:`7Q j
                           
handle=>v_fileTable(i), 
:q AFVS X0ITPUB个人空间] f6y#I/W4@[
                           
params=>null); ITPUB个人空间+T4] a)H;@%@)`
ITPUB个人空间S!]RE mfV%xE
    IF 
v_done THEN 
Bc;f{.F0ITPUB个人空间5P ea/~,u
      GOTO all_done
ITPUB个人空间8S#q'? qp ]!]T

o YB3m%Ow!KH0}UP0    
END IF; ITPUB个人空间{g]-D \:qG
ITPUB个人空间UA&TIQ]
  
END LOOP
/cYD7o$bHSc)`.R0
"\8c"We3V}0d0 ITPUB个人空间CI,yEW#V-b?X
ITPUB个人空间cGg#BW'M
<<
all_done>> 
cG A0W U2X-t RW0
Y.k2c,\1ll0-- 
Deallocate the device 
.zP(EWn4sS W0
W"bL_^n_!}5gVq0  sys
.dbms_backup_restore.deviceDeallocateITPUB个人空间o it)A,jHOT)t
ITPUB个人空间I8QGw3i1@lCE&p
 
:[9X4[SH6p z f/|O0
a ^-D&nt)fNv R0
ENDITPUB个人空间*D8n unsp

s Z'O;E~I f0ITPUB个人空间 H{*]9p g2H

.C2g y)u` eZ0.
g#^,[axj_0

For restoring multiple archives from a backupset, add a loopITPUB个人空间Mx8mKk
  around  sys.dbms_backup_restore.restoreArchivedLog()
(P2f/VMs'c*T0
:N+L_ \E$?z,lL0  for seq in <min seq#>..<max seq#> loopITPUB个人空间4eO FX'Cq
    sys.dbms_backup_restore.restoreArchivedLog(thread=>1,ITPUB个人空间'|A/?Y3CA#m"t
                                             sequence=>seq);ITPUB个人空间,m5Og7xvN K?5\ X
  end loop
&v]*lkec;Wdv4c`-D2_0ITPUB个人空间 q5x X Sx]
6. A typical scenarioITPUB个人空间L.PG]e*h)gH;OU

T EiGr5l-vw&?L0  A customer has backupsets consisting of:ITPUB个人空间P+f8xd$e2d.MU
    o. an incremental level 0 database backup
Dr|qU+Cy0    o. an incremental level 2 database backup
U3e"X UV5mAp e9i0    o. archivelogs from the time of the level 2 backup to the current timeITPUB个人空间[4vy y+_0g G/M
  The target database and recovery catalog have been irretrievably lost.ITPUB个人空间 w mZ-k1H[ yua
ITPUB个人空间U bT3C,g|:v,@5d
  In this situation, the following steps should be followed (using the  ITPUB个人空间5_+z'C+xO_
  above anonymous blocks):ITPUB个人空间 `x-D t#g S$MAS
    1. Start the target instance (nomount)ITPUB个人空间 {(C hwY5K9sG
    2. Restore the latest controlfile, ideally from the same backupset asITPUB个人空间*N.{0LR^\t'V
       the last incremental to be restored (make further copies if necessary
O7d;R$Xn n0       as per the init.ora)ITPUB个人空间0c$~S~ Y3Bq.R
    3. Mount the database
(s*E y$f)Hs?0    4. Restore the datafiles from the level 0 backupsetITPUB个人空间&kTNr7H CK
    5. Restore (apply) the datafiles from the level 2 backupsetITPUB个人空间 {'~P)L0X]a(c&y
    6. Restore the archivelogs from the archivelog backupset
*k%cm8H}0    7. Using tradtional v7 recovery techniques, recover the database  ITPUB个人空间 ^R^Bn$k)e~.?
       (until cancel using backup controlfile)
*s1J3t;t:F0lWK0    8. Open the database (resetlogs)ITPUB个人空间 j!wJF{8|-I.J
    9. Rebuild the recovery catalog & re-register the target databaseITPUB个人空间0~Nr#kV0Q D+V U!d"~f
   10. Make backups of the target database and recovery catalog databaseITPUB个人空间1^6n?$I9FiYN e
ITPUB个人空间 FbW3sJ:k8N

"j\:hc"Q7N*n08. Errors
"V$M*w*TK c0
:x%]2FP2n.x;`N0  8.1 ORA-19615 & ORA-19613 when attempting to extract filesITPUB个人空间}/^5S]u0bN

+J w ~#y Jq;pM ` |0     Errorstack:ITPUB个人空间 [,oV$I4HCC3I;_
       ORA-19583: conversation terminated due to errorITPUB个人空间3C9GV.lj'j
       ORA-19615: some files not found in backup set
?c6Vv#R4T7XD7j-Mo0       ORA-19613: datafile <file#> not found in backup setITPUB个人空间&F f*q-Lof$d
       ORA-06512: at "SYS.X$DBMS_BACKUP_RESTORE", line 1043ITPUB个人空间4~6M{&K2H
       ORA-06512: at line 40ITPUB个人空间@j/{5]"b

}X-L nv1I h0     The problem is that one or more backup pieces specified in theITPUB个人空间0e+}@o`P W
     v_fileTable table contain NO blocks for the datafile that you are  
S5k3x dA _!M0     trying to extract.  
$Jr e~`4C,V^){0
7vjnm^!p*?*tl0     For example, I may have run an RMAN backup and allocated 2 channels toITPUB个人空间wcmD%@F"Y
     backup the (4 datafile) database. This will create 2 backupsets.
PHP code:

,y-dB.x3WL.t;s0ITPUB个人空间T3Ip6wv7z [ H
.                       ITPUB个人空间/N R/B5S8V4r4rKX

-h)aXj/R%?,X`t[t8f0                                                 +- 
Backup piece 1a 
^ }"G7t*DB8Zp0ITPUB个人空间|'xG3_5f2y1s
                 
+- (Backupset 1Datafiles 1,-+ ITPUB个人空间/m.x9?2s)g^![9?]N*I(G
ITPUB个人空间9@&U#H0[!kpAR'p8d)Z
                 |                               +- 
Backup piece 2a ITPUB个人空间D0H#SY F)~$Xd

;{*hh4M-h4\ G ` x;b0       Database 
-+ 
YYIZ#o0ITPUB个人空间,L.}7X:[$[N
                 |                               +- 
Backup piece 1b ITPUB个人空间-m!F&J2^|@mL

Hw7Tm$^pA0                 
+- (Backupset 2Datafiles 3,-+ 
0YGlCU/Z7mi$k0ITPUB个人空间q/m R3\;}9`'p_
                                                 +- 
Backup piece 2b ITPUB个人空间#c{kN ALK

tL/O4p)X{*t#X0   
.ITPUB个人空间PmlLP*HC

Although the backup pieces may contain blocks from all datafilesITPUB个人空间:v7U2x2}1H|
     associated with their backupset, they will not contain blocks from a  ITPUB个人空间9]HLc3\(c e+l"nz
     different backupset i.e. pieces 1a and 1b will NOT contain blocks from  
#W4A$xF1r$M0     datafiles 3 or 4.ITPUB个人空间#Rp#aP.n U
ITPUB个人空间"D z(aE `r/e*P1_
     If I want to restore datafile 1, and include either backup pieces 1b or
"V(S-k qmS1Y!vzb0     2b in v_fileTable, I will get the errorstack above.
O0s*~z;R G$uD0ITPUB个人空间 i,Mxodj SJ*}
     This is why it is important to know what files are in what backupset.ITPUB个人空间4I)k%g8AD6\[ r
     The original RMAN backup log will help here.ITPUB个人空间yMb)TQ1Rn`C5B

pJ;H7h#M?p0
C!Gj.}2P,VZ08. Things to be doneITPUB个人空间w:Sv s]
ITPUB个人空间!Q6z8oYM6R5K
  8.1. Error handlingITPUB个人空间3D2v8iXZ&M7]
       If the procedures fail with an unhandled exception (quite likely, as
!Pk:Qp9S0       no exception handlers have been set up), the allocated device does not
e9p{[Z~-h!{$P0       get deallocated. This is unfriendly (the user must exit & restart theITPUB个人空间 m,pt3n#K8o&uO"N
       session) and will be addressedITPUB个人空间wg$i%Z-TE_"J5F#M
ITPUB个人空间:^f"Ue _E R^2u

TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-12-02  
 123456
78910111213
14151617181920
21222324252627
28293031   

数据统计

  • 访问量: 26110
  • 日志数: 312
  • 图片数: 2
  • 建立时间: 2007-12-11
  • 更新时间: 2008-11-28

RSS订阅

Open Toolbar