朋友用到的一次不完全恢复案例与大家分享

来源:互联网 发布:gulp 混淆js 编辑:程序博客网 时间:2024/05/21 15:50

前2天因为一次错误的truncate 操作,删除了hz用户下的几个表,费了1天多时间才恢复出来,在这里记录下恢复过程和这个深刻的教训。

  使用坏境: oracle11.2+rhce5.5 RAC,归档模式,数据库有1TB容量。
   在配置流环境时,因为一个误操作,删除了hz用户下的几个表。在这个数据库上还部署了其它几个用户,停机恢复数据显然是不可能的,分析情况后可以使用下面两种方式来恢复数据。
1、把当前库的备份文件和归档日志传到测试机上进行时间点不完全恢复,然后exp导出需要误删除的数据。
2、使用duplicate表空间的方式生成辅助数据库,在新库中导出需要的数据。
      参考:http://space.itpub.net/7199859/viewspace-79054
 
这次的数据恢复操作我我使用第一种方式,以下是操作步骤:
1、拷贝数据文件和2节点的归档日志文件。由于故障库的备份是nfs挂载到备份机上的,省去了拷贝数据文件的时间,只需要把2节点下的archive日志文件拷贝到测试库上就行。
2、创建新库的pfile参数文件,拷贝故障库的spfile文件,修改参数并删除有关rac的不需要参数信息。
3、创建新库的密码文件.
     orapwd file=/u02/app/oracle/product/11.2.0/db1/dbs/orapwklir passord=oracle entries=10 force=y
4、创建新库的dump目录。
5、启动新库到nomount下。
[oracle@kms2 dbs]$ export ORACLE_SID=klir
!M#U]Rt22815499[oracle@kms2 dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Thu Nov 18 09:56:35 2010
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to an idle instance.ITPUB个人空间8Tp'E3QT%Cp}
SQL> startup nomount pfile='/u02/pfile_klir.ora'
6、从备份集中恢复控制文件,并启动到mount状态下。
RMAN>   restore controlfile from /orabk/ctl_c-949039848-20101116-00.ctl;
RMAN>  alter database mount;
 
7、恢复表空间。因为只是一个表空间下的一些表被删除了,朋友建议我只恢复有问题的表空间就可以了,当然system,sysaux,undo这些基本的表空间是要恢复的。

_g_Z;E22815499RMAN> restore tablespace system;
Starting restore at 16-NOV-10ITPUB个人空间,W'IE0S1[
Starting implicit crosscheck backup at 16-NOV-10
(g:O0ie1g4O'k7[,{{22815499allocated channel: ORA_DISK_1ITPUB个人空间y0@ b)F`
Crosschecked 198 objectsITPUB个人空间N1^s7A3y
Finished implicit crosscheck backup at 16-NOV-10
Starting implicit crosscheck copy at 16-NOV-10
G9aj I(d22815499using channel ORA_DISK_1ITPUB个人空间8R$[ ]kx5^C
Finished implicit crosscheck copy at 16-NOV-10
searching for all files in the recovery area
5W.E UH/s6B3hy4P+ZC22815499cataloging files...ITPUB个人空间4m(vO$L(Y3XZU7A
no files cataloged
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restoreITPUB个人空间z9Es-A CM1/
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
*V h+s(dTP22815499channel ORA_DISK_1: restoring datafile 00001 to +DG1/system01.dbfITPUB个人空间4u r/?7?8^Y!?&ou
channel ORA_DISK_1: reading from backup piece /orabk/db_KLIR_13771_1_1_735012733.dbfITPUB个人空间 H!Q9X(/Uiy"?F
channel ORA_DISK_1: piece handle=/orabk/db_KLIR_13771_1_1_735012733.dbf tag=TAG20101114T021212
+Q7iB(A6F*?$wM22815499channel ORA_DISK_1: restored backup piece 1
$Kv~!BYg:~!Hf(W22815499channel ORA_DISK_1: restore complete, elapsed time: 00:09:15
{*vV _D22815499Finished restore at 16-NOV-10
RMAN> restore tablespace sysaux;
Starting restore at 16-NOV-10ITPUB个人空间Cdh/g,r-v5]
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restoreITPUB个人空间.?,m4Y x Fn F6ow
channel ORA_DISK_1: specifying datafile(s) to restore from backup setITPUB个人空间Be!zQAv,y
channel ORA_DISK_1: restoring datafile 00002 to +DG1/sysaux01.dbf
~i5r&Jwd$_&u22815499channel ORA_DISK_1: reading from backup piece /orabk/db_KLIR_13770_1_1_735012528.dbfITPUB个人空间 YXZc%h^^
channel ORA_DISK_1: piece handle=/orabk/db_KLIR_13770_1_1_735012528.dbf tag=TAG20101114T021212                              
/n4C&u L Kr x]{ Ig22815499channel ORA_DISK_1: restored backup piece 1ITPUB个人空间[H6z r ^$V~
channel ORA_DISK_1: restore complete, elapsed time: 00:08:50
zND:_S!z/E22815499Finished restore at 16-NOV-10
RMAN> restore tablespace HZDATATBS;
Starting restore at 16-NOV-10ITPUB个人空间c!k+s,j}6g5q
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restoreITPUB个人空间z6N eb3S4Pd
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
,OvaZC k22815499channel ORA_DISK_1: restoring datafile 00011 to +DG1/hzdata01.dbf
sY~u,F*Ux22815499channel ORA_DISK_1: reading from backup piece /orabk/db_KLIR_13770_1_1_735012528.dbfITPUB个人空间#`7j.DV-z1B6Z(G)f,@
channel ORA_DISK_1: piece handle=/orabk/db_KLIR_13770_1_1_735012528.dbf tag=TAG20101114T021212
/[ D{&QnW22815499channel ORA_DISK_1: restored backup piece 1ITPUB个人空间#OZe$_9M;|Oz
channel ORA_DISK_1: restore complete, elapsed time: 00:16:35ITPUB个人空间u1M(ucV.L)j/J
channel ORA_DISK_1: starting datafile backup set restoreITPUB个人空间3e"T@q f yy
channel ORA_DISK_1: specifying datafile(s) to restore from backup setITPUB个人空间7j$qP7y$q1I Fl
channel ORA_DISK_1: restoring datafile 00154 to +DG1/hzdata02.dbfITPUB个人空间 E|/]7l-JF l}
channel ORA_DISK_1: reading from backup piece /orabk/db_KLIR_13938_1_1_735186686.dbfITPUB个人空间0g hd/]6F*V;g W
channel ORA_DISK_1: piece handle=/orabk/db_KLIR_13938_1_1_735186686.dbf tag=TAG20101116T023123ITPUB个人空间#N#r E+`-HF {/B*Q Ua ^
channel ORA_DISK_1: restored backup piece 1ITPUB个人空间 UB j1{q
channel ORA_DISK_1: restore complete, elapsed time: 00:02:05ITPUB个人空间'm2pa-`BXB
Finished restore at 16-NOV-10
RMAN> restore tablespace hzindtbs;
Starting restore at 16-NOV-10ITPUB个人空间~l+wY[B
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
TR0BL*@mA4|C22815499channel ORA_DISK_1: specifying datafile(s) to restore from backup setITPUB个人空间A#{9{u__
channel ORA_DISK_1: restoring datafile 00017 to +DG1/hzind02.dbf
2h F+v5Hu+D$ysd22815499channel ORA_DISK_1: restoring datafile 00021 to +DG1/hzind03.dbfITPUB个人空间^!hQ:h*MLI
channel ORA_DISK_1: reading from backup piece /orabk/db_KLIR_13773_1_1_735012734.dbfITPUB个人空间 M4o%ZRzN c
channel ORA_DISK_1: piece handle=/orabk/db_KLIR_13773_1_1_735012734.dbf tag=TAG20101114T021212
d)T'SU'@0j I22815499channel ORA_DISK_1: restored backup piece 1ITPUB个人空间Wl!D#p6x4G[-F
channel ORA_DISK_1: restore complete, elapsed time: 00:13:45
C7Q7r1B&g8/x&u/{22815499channel ORA_DISK_1: starting datafile backup set restoreITPUB个人空间R;iWU0d x^lxH
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
$o@;TB [ym22815499channel ORA_DISK_1: restoring datafile 00012 to +DG1/hzind01.dbf
3n1I%mL6KYf22815499channel ORA_DISK_1: reading from backup piece /orabk/db_KLIR_13771_1_1_735012733.dbf
.qN&D/yA22815499channel ORA_DISK_1: piece handle=/orabk/db_KLIR_13771_1_1_735012733.dbf tag=TAG20101114T021212ITPUB个人空间 u!i%X7C9H}_0b
channel ORA_DISK_1: restored backup piece 1ITPUB个人空间"VT|&`t m:y
channel ORA_DISK_1: restore complete, elapsed time: 00:14:46
M"BSPgu#p`~22815499channel ORA_DISK_1: starting datafile backup set restore
[Zpx}k;Jb22815499channel ORA_DISK_1: specifying datafile(s) to restore from backup set
/i+g1^5g0AN3S22815499channel ORA_DISK_1: restoring datafile 00153 to +DG1/hzind04.dbf
5b0B}9M JS4U/] ZB UH22815499channel ORA_DISK_1: reading from backup piece /orabk/db_KLIR_13937_1_1_735186478.dbf
jhV*CUF22815499channel ORA_DISK_1: piece handle=/orabk/db_KLIR_13937_1_1_735186478.dbf tag=TAG20101116T023123ITPUB个人空间0r}!RbR0[6g%BX
channel ORA_DISK_1: restored backup piece 1ITPUB个人空间tTnkP
channel ORA_DISK_1: restore complete, elapsed time: 00:03:15
5z/}A vk@22815499Finished restore at 17-NOV-10

6[LP`uS+gL(Z22815499RMAN> restore tablespace undotbs2;
Starting restore at 17-NOV-10
g:C+u!i6p-T6V22815499using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restoreITPUB个人空间&o?-rf*}|.B _
channel ORA_DISK_1: specifying datafile(s) to restore from backup setITPUB个人空间G ~3h4h#dgI/VS
channel ORA_DISK_1: restoring datafile 00006 to +DG1/undotbs201.dbf
adDzCq0M2f22815499channel ORA_DISK_1: reading from backup piece /orabk/db_KLIR_13770_1_1_735012528.dbf
%j-XvJ,o22815499channel ORA_DISK_1: piece handle=/orabk/db_KLIR_13770_1_1_735012528.dbf tag=TAG20101114T021212ITPUB个人空间RV&L R#h
channel ORA_DISK_1: restored backup piece 1
{:ke9[x.x6Hx22815499channel ORA_DISK_1: restore complete, elapsed time: 00:04:46ITPUB个人空间(db-ff ?[
Finished restore at 17-NOV-10
RMAN> restore tablespace undotbs1;
Starting restore at 17-NOV-10
LP z0H)q$j i9f22815499using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restoreITPUB个人空间/L)L1aK9enr
channel ORA_DISK_1: specifying datafile(s) to restore from backup setITPUB个人空间 | z kA'w2^
channel ORA_DISK_1: restoring datafile 00003 to +DG1/undotbs101.dbfITPUB个人空间Q]n z M;Ws6atLM
channel ORA_DISK_1: reading from backup piece /orabk/db_KLIR_13773_1_1_735012734.dbf
`T7R@W22815499channel ORA_DISK_1: piece handle=/orabk/db_KLIR_13773_1_1_735012734.dbf tag=TAG20101114T021212ITPUB个人空间PSc0}o(nn
channel ORA_DISK_1: restored backup piece 1
:?_^-XC+K5g22815499channel ORA_DISK_1: restore complete, elapsed time: 00:11:05
6SeO"Z,~h7ga22815499Finished restore at 17-NOV-10
 
8.Offline 其它不用的表空间。
SQL> alter database datafile 5,7 offline drop;
Database altered.
SQL> alter database datafile 13,14,15,16 offline drop;
Database altered.
 
9、不完全恢复数据库。
ITPUB个人空间-iv{_+aswai
SQL> recover database until time '2010-11-16 16:25:00'   using backup  controlfile;
PW"X[.x*}r22815499ORA-00279: change 2602636589 generated at 11/14/2010 13:16:46 needed for threadITPUB个人空间3W_5rZ3S.Ykm
1
-x-~l8V4c{22815499ORA-00289: suggestion : +ARCHIVE
5x Zst$K22815499ORA-00280: change 2602636589 for thread 1 is in sequence #5709
ITPUB个人空间A/Y @6e$WKC
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
}],^;chN(c22815499thread_1_seq_5709.528.735293603ITPUB个人空间L*Z4z2kx(k E
ORA-00308: cannot open archived log 'thread_1_seq_5709.528.735293603'
&A3G$S6sC)nu?l22815499ORA-27037: unable to obtain file statusITPUB个人空间EV?y*r
Linux-x86_64 Error: 2: No such file or directory
HI/ Jd#[_D3D22815499Additional information: 3

n+C4ts^(q22815499Specify log: {<RET>=suggested | filename | AUTO | CANCEL}ITPUB个人空间J*J[?TT
/orabk/aaa/thread_1_seq_5709.528.735293603
g,e1bpzF9[22815499ORA-00279: change 2602636589 generated at 11/14/2010 06:43:25 needed for threadITPUB个人空间Z Lp!io7W(n'L
2
a2h#D a/x!B B22815499ORA-00289: suggestion : +ARCHIVEITPUB个人空间-lN6Un)oB'd/r!b
ORA-00280: change 2602636589 for thread 2 is in sequence #6914
 
ORA-00289: suggestion : +ARCHIVEITPUB个人空间*~|W$jS&K
ORA-00280: change 2609694870 for thread 1 is in sequence #5824
p7Z+y2`#SB#Pg?22815499ORA-00278: log file '/orabk/aaa/arch11/1_5823_719402218.dbf' no longer needed
"a{1nXNtC22815499for this recovery
ITPUB个人空间,W4vgU2NWIg"ke
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}ITPUB个人空间r(mn+u%E(r { v)@
/orabk/aaa/arch11/1_5824_719402218.dbfITPUB个人空间+M8@`%BF1i
ORA-00279: change 2609942602 generated at 11/16/2010 16:07:30 needed for threadITPUB个人空间0`u|r2Lf9F
2ITPUB个人空间*?-f.]n8]Fi
ORA-00289: suggestion : +ARCHIVEITPUB个人空间xp?A8o
ORA-00280: change 2609942602 for thread 2 is in sequence #6990
*pt `3U$uj22815499ORA-00278: log file '/orabk/aaa/arch22/2_6989_719402218.dbf' no longer neededITPUB个人空间S+ApS)D!R|Tk
for this recovery
........................省略中间部分
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}ITPUB个人空间m$["[[]:@R'b
/orabk/aaa/arch22/2_6990_719402218.dbfITPUB个人空间 s/saB;Gi9m
ORA-00279: change 2609955345 generated at 11/16/2010 16:08:25 needed for thread
%zOO3U:U228154991ITPUB个人空间LfW#V0CM6x
ORA-00289: suggestion : +ARCHIVEITPUB个人空间`0B$@O ~:D!O
ORA-00280: change 2609955345 for thread 1 is in sequence #5825ITPUB个人空间&v:GfX`-`(z
ORA-00278: log file '/orabk/aaa/arch11/1_5824_719402218.dbf' no longer needed
V*a&a:WO5s o22815499for this recovery
ITPUB个人空间W.xE!E%Y6c m$s0We
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
O l(c g%fz22815499/orabk/aaa/arch11/1_5825_719402218.dbf
1JVQ}V5Z22815499Log applied.ITPUB个人空间'm A6U }d2v
Media recovery complete.
 
10、打开数据库。
SQL> alter database open resetlogs;
经过几分钟的等待后,数据成功打开,登录数据库查询需要的文件都已经恢复出来了。谢天谢地!
 
 
这次数据恢复操作,用了近1天的时间,当时发生问题时我都快搞懵了,幸好在朋友的帮助下顺利完数据恢复,在这里要非常感谢他们!顺便记录下恢复期间遇到的几个问题。
<1>、有些日志文件在故障库的日志目录里是没有的,需要从备份中还原,不同节点的日志文件恢复时要写上thread=*命令,例如:
 
RMAN>  restore archivelog from logseq 6914 until logseq 6915thread=2;
Starting restore at 17-NOV-10ITPUB个人空间GU2G G@/E.z X
allocated channel: ORA_DISK_1
N.ER0F2T#~:P*F22815499channel ORA_DISK_1: SID=182 instance=klir2 device type=DISK
channel ORA_DISK_1: starting archived log restore to default destination
!`F!H_L/?'`9?22815499channel ORA_DISK_1: restoring archived log
toyP7TLF22815499archived log thread=2 sequence=6914ITPUB个人空间s0t$Yuq+~!b
channel ORA_DISK_1: reading from backup piece /orabk/arc_KLIR_13864_1_1_735184831.dbf
dz] L8LEyZ&dj22815499channel ORA_DISK_1: piece handle=/orabk/arc_KLIR_13864_1_1_735184831.dbf tag=TAG20101116T020016ITPUB个人空间 d5d{/ceh[
channel ORA_DISK_1: restored backup piece 1
H}5]](TR3uh;rf1@22815499channel ORA_DISK_1: restore complete, elapsed time: 00:00:07ITPUB个人空间"[0`*x @|"o
channel ORA_DISK_1: starting archived log restore to default destinationITPUB个人空间,k(k0[-u2cb;F&T o
channel ORA_DISK_1: restoring archived log
*uv!rx,^7J s_8J;qh22815499archived log thread=2 sequence=6915
v/U;?'L y;NM/L^'F.QV22815499channel ORA_DISK_1: reading from backup piece /orabk/arc_KLIR_13866_1_1_735184956.dbfITPUB个人空间zYT,W e!ll
channel ORA_DISK_1: piece handle=/orabk/arc_KLIR_13866_1_1_735184956.dbf tag=TAG20101116T020016ITPUB个人空间$j7A2wZ8~7mB
channel ORA_DISK_1: restored backup piece 1ITPUB个人空间up.z3o{T
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07ITPUB个人空间,CY&Hx%M [
Finished restore at 17-NOV-10
 
否则会提示以下错误,
RMAN>  restore archivelog from logseq 6914 until logseq 6915;
Starting restore at 17-NOV-10
%pT%k!WN22815499using target database control file instead of recovery catalogITPUB个人空间*HC;F |,[iu
allocated channel: ORA_DISK_1ITPUB个人空间/?f*iJ LQh_
channel ORA_DISK_1: SID=182 instance=klir2 device type=DISK
^NX"X`0F1u4B+s8Z22815499RMAN-00571: ===========================================================ITPUB个人空间i,~KDU dS
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============ITPUB个人空间@/Q.y/}c@T)|
RMAN-00571: ===========================================================
:?-n1z8q+x2S*s|h22815499RMAN-03002: failure of restore command at 11/17/2010 08:15:07ITPUB个人空间4u{ PpRX@ITa
RMAN-20242: specification does not match any archived log in the repository
8^Gb:C2A7fP22815499
<2>、故障库恢复出日志文件后,因为在asm磁盘组里,要进入asmcmd里拷贝出日志文件。
ASMCMD> cp +ARCHIVE/klir/archivelog/2010_11_17/thread_1_seq_5705.369.735274973 /orabk/aaa/
 
<3>、恢复命令要写对,刚开始写的几种命令都不正确。
SQL> recover database until time '2010-11-16 16:25:00'
ORA-00283: recovery session canceled due to errorsITPUB个人空间7]&@M4Ly5K/@Q_
ORA-01610: recovery using the BACKUP CONTROLFILE option must be done
 
SQL>  recover database until time to_date('2010-11-16 16:25:00','yyyy-mm-dd HH24:MI:SS');ITPUB个人空间R[B-G@}#VJ6N
ORA-00285: TIME not given as a string constant
A"o[p})y22815499
<4>、对于这种只是丢失部分表的情况,就可以只还原需要的表空间来打开数据库,可以节省大量的恢复时间。