数据库备份文件 无备份丢失部分数据文件和控制文件恢复
无备份丢失部分数据文件和控制文件恢复
前提:
需要有除丢失文件以外其他文件的备份
丢失的文件需要是在其他文件备份后创建的
所有其他文件备份后的归档都在存在
恢复步骤:
拷贝任一未丢失文件的备份回来
创建新控制文件 但控制文件不包括丢失的数据文件
进行恢复
碰到
ORA : recovery session canceled due to errors ORA : unnamed datafile(s) added to controlfile by media recovery ORA : data file : D:ORACLEORADATAxxxxxxxx DBF
select name from v$datafile找出uname file
alter database create datafile D:ORACLEORA DATABASEUNNAMEDxxxxx as D:ORACLEORADATA xxxxxxxx DBF ;
继续恢复
恢复完成 打开
可能会遇到的问题:
如果没有拷贝备份回来直接重建不包含丢失文件的控制文件时 可以打开数据库 但丢失的文件会显示成missingxxxx的file name 这时候就会不能恢复
试验过程:
Microsoft Windows XP [版本 ]
(C) 版权所有 Microsoft Corp
C:Documents and Settingsqigong>oradim startup sid test
C:Documents and Settingsqigong>sqlplus / as sysdba
SQL*Plus: Release Production on 星期三 月 : :
Copyright (c) Oracle All rights reserved
Connected to: Oracle Database g Enterprise Edition Release Production With the Partitioning OLAP and Data Mining options
SQL> shutdown immediate; Database closed Database dismounted ORACLE instance shut down SQL> exit Disconnected from Oracle Database g Enterprise Edition Release Producti With the Partitioning OLAP and Data Mining options
C:Documents and Settingsqigong>sqlplus / as sysdba
SQL*Plus: Release Production on 星期三 月 : :
Copyright (c) Oracle All rights reserved
Connected to an idle instance
SQL> startup nomount; ORACLE instance started
Total System Global Area bytes Fixed Size bytes Variable Size bytes Database Buffers bytes Redo Buffers bytes SQL> alter database mount; alter database mount * ERROR at line : ORA : error in identifying controlfile check alert log for more info
SQL> shutdown ORA : database not mounted
ORACLE instance shut down SQL> startup ORACLE instance started
Total System Global Area bytes Fixed Size bytes Variable Size bytes Database Buffers bytes Redo Buffers bytes Database mounted Database opened SQL> alter system switch logfile;
System altered
SQL> /
System altered
SQL> /
System altered
SQL> create tablespace test datafile c:test dbf size m extent management local segment space management auto uniform size k;
Tablespace created
SQL> insert into testlost values( );
row created
SQL> mit;
Commit plete
SQL> create table testlost (a number) tablespace test ;
Table created
SQL> shutdown immediate; Database closed Database dismounted ORACLE instance shut down SQL> startup nomount ORACLE instance started
Total System Global Area bytes Fixed Size bytes Variable Size bytes Database Buffers bytes Redo Buffers bytes
C:Documents and Settingsqigong>rman
Recovery Manager: Release Production
Copyright (c) Oracle All rights reserved
RMAN> connect target
connected to target database: test (not mounted)
RMAN> restore controlfile from autobackup;
Starting restore at 月 using target database controlfile instead of recovery catalog allocated channel: ORA_DISK_ channel ORA_DISK_ : sid= devtype=DISK
recovery area destination: C:oracleproduct flash_recovery_area database name (or lock name space) used for search: TEST channel ORA_DISK_ : autobackup found in the recovery area channel ORA_DISK_ : autobackup found: C:ORACLEPRODUCT FLASH_RECOVERY_AREATESTAUTOBACKUP _ _ O _MF_S_ _ LOS FCX_ BKP channel ORA_DISK_ : controlfile restore from autobackup plete output filename=C:ORACLEPRODUCT ORADATATESTCONTROL CTL output filename=C:ORACLEPRODUCT ORADATATESTCONTROL CTL output filename=C:ORACLEPRODUCT ORADATATESTCONTROL CTL Finished restore at 月
RMAN> exit
RMAN : WARNING: unable to generate V$RMAN_STATUS or V$RMAN_OUTPUT row RMAN : WARNING: disabling update of the V$RMAN_STATUS and V$RMAN_OUTPUT rows
SQL> alter database mount; alter database mount * ERROR at line : ORA : invalid password file C:oracleproduct Db_ DATABASEPWDtest ORA
SQL> DECLARE devtype varchar ( ); done boolean; BEGIN devtype:=sys dbms_backup_restore deviceAllocate (type=> ident=> ); sys dbms_backup_restore restoreSetDatafile; sys dbms_backup_restore restoreDatafileTo(dfnumber=> toname=> c:test DBF ); sys dbms_backup_restore restoreBackupPiece(done=>done handle=> C: FUAT K_ _ _ sys dbms_backup_restore deviceDeallocate; END; /
PL/SQL procedure successfully pleted
SQL> shutdown immediate; ORA : database not open Database dismounted ORACLE instance shut down SQL> startup nomount ORACLE instance started
Total System Global Area bytes Fixed Size bytes Variable Size bytes Database Buffers bytes Redo Buffers bytes SQL> CREATE CONTROLFILE REUSE DATABASE TEST NORESETLOGS ARCHIVELOG MAXLOGFILES MAXLOGMEMBERS MAXDATAFILES MAXINSTANCES MAXLOGHISTORY LOGFILE GROUP C:ORACLEPRODUCT ORADATATESTREDO LOG SIZE M GROUP C:ORACLEPRODUCT ORADATATESTREDO LOG SIZE M GROUP C:ORACLEPRODUCT ORADATATESTREDO LOG SIZE M STANDBY LOGFILE DATAFILE C:ORACLEPRODUCT ORADATATESTSYSTEM DBF C:ORACLEPRODUCT ORADATATESTUNDOTBS DBF C:ORACLEPRODUCT ORADATATESTSYSAUX DBF C:ORACLEPRODUCT ORADATATESTUSERS DBF C:ORACLEPRODUCT ORADATATESTEXAMPLE DBF C:TBS DBF C:TBS DBF C:TBS DBF C:TBS DBF C:TBS DBF C:TBS DBF C:TBS DBF C:TBS DBF C:TEST DBF CHARACTER SET ZHS GBK ;
Control file created
SQL> recover database; ORA : change generated at / / : : needed for thread ORA : suggestion : C:ORACLEARCHIVEARC _ ORA : change for thread is in sequence #
Specify log: {<RET>=suggested | filename | AUTO | CANCEL} auto ORA : recovery session canceled due to errors ORA : unnamed datafile(s) added to controlfile by media recovery ORA : data file : C:TEST DBF
ORA : media recovery not started
SQL> select name from v$datafile;
NAME C:ORACLEPRODUCT ORADATATESTSYSTEM DBF C:ORACLEPRODUCT ORADATATESTUNDOTBS DBF C:ORACLEPRODUCT ORADATATESTSYSAUX DBF C:ORACLEPRODUCT ORADATATESTUSERS DBF C:ORACLEPRODUCT ORADATATESTEXAMPLE DBF C:TBS DBF C:TBS DBF C:TBS DBF C:TBS DBF C:TBS DBF C:TBS DBF
NAME C:TBS DBF C:TBS DBF C:TEST DBF C:WINDOWSSYSTEM UNNAMED
rows selected
SQL> alter database create datafile C:WINDOWSSYSTEM UNNAMED as c:test db
Database altered
SQL> recover database; Media recovery plete SQL> alter database open;
Database altered
SQL> select * from testlost ;
no rows selected
SQL> select * from testlost;
A 在上面这个试验里面我们可能还会有一个疑问 既然控制文件里面记载的是unamedxxxxxxx的文件名 数据字典的里面的filename也是 unamedxxxxxxx(实际上数据字典里面不保存文件名 所有的文件名都只包含在控制文件当中) 日志里也是没有记载文件名 那么当我们 recover database的时候为什么会出现
ORA : recovery session canceled due to errors
ORA : unnamed datafile(s) added to controlfile by media recovery
ORA : data file : C:TEST DBF
ORA : media recovery not started
Oracle他是从哪里得到这个unamedxxxxxxx文件的真实文件是 C:TEST DBF 呢?
先来看看日志里记载了什么东西
用logminer查一下
EXECUTE DBMS_LOGMNR_D BUILD(dictionary_filename => l_dictionary ora dictionary_location => /disk /oradata/ );
EXECUTE DBMS_LOGMNR ADD_LOGFILE( LogFileName => /disk /oradata/redo log Options => dbms_logmnr NEW);
EXECUTE DBMS_LOGMNR START_LOGMNR(DictFileName => /disk /oradata/l_dictionary ora );
SELECT sql_redo FROM V$LOGMNR_CONTENTS where upper(sql_redo) like %TEST% ;
SQL_REDO create tablespace test datafile c:test dbf size m reuse extent management local segment space management auto uniform size k; 只发现了这句ddl 并没有往数据字典里插入文件名
再来看create tablespace的trace文件 …… insert into ts$ (ts# name online$ contents$ undofile# undoblock# blocksize dflmaxext dflinit dflincr dflextpct dflminext dflminlen inc# owner# scnwrp scnbas pitrscnwrp pitrscnbas dflogging affstrength bitmapped plugged directallowed flags spare spare ) values (: : : : : : : : : : : : : : : : : : : : : : : : )
insert into file$ (file# blocks ts# status$ relfile# maxextend inc crscnwrp crscnbas spare ) values (: : DECODE(: NULL : ) : DECODE(: NULL : ) : : : : DECODE(: NULL : )) ……
这两条语句说明了oracle在ts$ file$分别插入了新创建表空间和文件的信息 但并不包括文件名
看起来好像这个文件名是无出处的 即不直接取至日志 也不存在于数据字典 控制文件中则存在着错误的文件名 那他究竟从哪里来呢?
看下控制文件中包含这个文件的dump 信息
DATA FILE # : (name # ) C:WINDOWSSYSTEM UNNAMED creation size= block size= status= x head= tail= dup= tablespace index= krfil= prev_file= unrecoverable scn: x / / : : Checkpoint cnt: scn: x d e / / : : Stop scn: x d e / / : : Creation Checkpointed at scn: x c / / : :

lishixinzhi/Article/program/Oracle/201311/16821