码迷,mamicode.com
首页 > 数据库 > 详细

ORACLE中没有参数文件和控制文件如何通过rman恢复数据库

时间:2015-02-04 21:54:32      阅读:333      评论:0      收藏:0      [点我收藏+]

标签:

场景:

一个DEV告诉我生产环境下某个用户的表都看不到了,需要恢复,而此时生产库上存储自动备份的参数文件控制文件的磁盘目录文件坏块,所以导致rman备份的只有数据文件和归档日志文件,这种情况下,如何在测试服务器上利用rman恢复数据呢?google了很多资料,咨询了朋友,恢复过程如下:





前期准备工作:
事先查询好先查询下原来的数据文件路径
SQL> select name from v$datafile;


NAME
--------------------------------------------------------------------------------
/home/oradata/stuorcl/system01.dbf
/home/oradata/stuorcl/sysaux01.dbf
/home/oradata/stuorcl/undotbs01.dbf
/home/oradata/stuorcl/users01.dbf
/home/oradata/stuorcl/stuorclk01.dbf
/home/oradata/stuorcl/plas01.dbf
/home/oradata/stuorcl/pl01.dbf
/home/oradata/stuorcl/help01.dbf
/home/oradata/stuorcl/adobelc01.dbf
/home/oradata/stuorcl/sms01.dbf


10 rows selected.


SQL> 


事先获得redo日志文件路径
SQL> select member from v$logfile;


MEMBER
--------------------------------------------------------------------------------
/home/oradata/stuorcl/redo03.log
/home/oradata/stuorcl/redo02.log
/home/oradata/stuorcl/redo01.log
/home/oradata/stuorcl/redo_dg_01.log
/home/oradata/stuorcl/redo_dg_02.log
/home/oradata/stuorcl/redo_dg_03.log


6 rows selected.


SQL> 


1,nomount下创建控制文件;
[root@xuelong4 ~]# su - oracle
[oracle@xuelong4 ~]$ sqlplus / as sysdba


SQL*Plus: Release 11.2.0.1.0 Production on Wed Feb 4 13:48:23 2015


Copyright (c) 1982, 2009, Oracle.  All rights reserved.




Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> 


2,启动到nomount状态
SQL> startup nomount
ORACLE instance started.


Total System Global Area 1.1358E+10 bytes
Fixed Size    2216744 bytes
Variable Size 8589937880 bytes
Database Buffers 2751463424 bytes
Redo Buffers   13946880 bytes
SQL> 




3,创建控制文件


CREATE CONTROLFILE REUSE set DATABASE "stuorcl" RESETLOGS ARCHIVELOG
   MAXLOGFILES 16
   MAXLOGMEMBERS 3
   MAXDATAFILES 100
   MAXINSTANCES 8
   MAXLOGHISTORY 454
DATAFILE
‘/home/oradata/stuorcl/system01.dbf‘,
‘/home/oradata/stuorcl/sysaux01.dbf‘,
‘/home/oradata/stuorcl/undotbs01.dbf‘,
‘/home/oradata/stuorcl/users01.dbf‘,
‘/home/oradata/stuorcl/stuorclk01.dbf‘,
‘/home/oradata/stuorcl/plas01.dbf‘,
‘/home/oradata/stuorcl/pl01.dbf‘,
‘/home/oradata/stuorcl/help01.dbf‘,
‘/home/oradata/stuorcl/adobelc01.dbf‘,
‘/home/oradata/stuorcl/sms01.dbf‘
LOGFILE
GROUP 1 (‘/home/oradata/stuorcl/redo03.log‘)  SIZE 10M,
GROUP 2 (‘/home/oradata/stuorcl/redo02.log‘)  SIZE 10M,
GROUP 3 (‘/home/oradata/stuorcl/redo01.log‘)  SIZE 10M,
GROUP 4 (‘/home/oradata/stuorcl/redo_dg_01.log‘)  SIZE 10M,
GROUP 5 (‘/home/oradata/stuorcl/redo_dg_02.log‘)  SIZE 10M,
GROUP 6 (‘/home/oradata/stuorcl/redo_dg_03.log‘)  SIZE 10M
CHARACTER SET ZHS16GBK;


执行过程:
SQL> CREATE CONTROLFILE REUSE set DATABASE "stuorcl" RESETLOGS ARCHIVELOG
   MAXLOGFILES 16
   MAXLOGMEMBERS 3
   MAXDATAFILES 100
   MAXINSTANCES 8
   MAXLOGHISTORY 454
DATAFILE
‘/home/oradata/stuorcl/system01.dbf‘,
‘/home/oradata/stuorcl/sysaux01.dbf‘,
 2    3    4    5    6    7    8    9   10  ‘/home/oradata/stuorcl/undotbs01.dbf‘,
‘/home/oradata/stuorcl/users01.dbf‘,
‘/home/oradata/stuorcl/stuorclk01.dbf‘,
‘/home/oradata/stuorcl/plas01.dbf‘,
‘/home/oradata/stuorcl/pl01.dbf‘,
‘/home/oradata/stuorcl/help01.dbf‘,
‘/home/oradata/stuorcl/adobelc01.dbf‘,
‘/home/oradata/stuorcl/sms01.dbf‘
LOGFILE
GROUP 1 (‘/home/oradata/stuorcl/redo03.log‘)  SIZE 10M,
GROUP 2 (‘/home/oradata/stuorcl/redo02.log‘)  SIZE 10M,
GROUP 3 (‘/home/oradata/stuorcl/redo01.log‘)  SIZE 10M,
GROUP 4 (‘/home/oradata/stuorcl/redo_dg_01.log‘)  SIZE 10M,
GROUP 5 (‘/home/oradata/stuorcl/redo_dg_02.log‘)  SIZE 10M,
GROUP 6 (‘/home/oradata/stuorcl/redo_dg_03.log‘)  SIZE 10M
CHARACTER SET ZHS16GBK; 11   12   13   14   15   16   17   18   19   20   21   22   23   24   25  


Control file created.


SQL> 


4,在新控制文件中注册数据文件备份和归档备份

catalog start with ‘/oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/‘;
在mount状态下执行
RMAN> catalog start with ‘/oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/‘;


released channel: ORA_DISK_1
searching for all files that match the pattern /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/


List of Files Unknown to the Database
=====================================
File Name: /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/full_stuorcl_20150123_3051.bak
File Name: /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/rman_backup.log
File Name: /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/arch_stuorcl_20150123_3050.bak
File Name: /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/arch_stuorcl_20150123_3052.bak


Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done


List of Cataloged Files
=======================
File Name: /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/full_stuorcl_20150123_3051.bak
File Name: /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/arch_stuorcl_20150123_3050.bak
File Name: /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/arch_stuorcl_20150123_3052.bak


List of Files Which Where Not Cataloged
=======================================
File Name: /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/rman_backup.log
  RMAN-07517: Reason: The file header is corrupted


RMAN> 


5,进行修复操作
RMAN>  restore database;

Starting restore at 04-FEB-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=767 device type=DISK


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 00001 to /home/oradata/stuorcl/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /home/oradata/stuorcl/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /home/oradata/stuorcl/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /home/oradata/stuorcl/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /home/oradata/stuorcl/stuorclk01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /home/oradata/stuorcl/plas01.dbf
channel ORA_DISK_1: restoring datafile 00007 to /home/oradata/stuorcl/pl01.dbf
channel ORA_DISK_1: restoring datafile 00008 to /home/oradata/stuorcl/help01.dbf
channel ORA_DISK_1: restoring datafile 00009 to /home/oradata/stuorcl/adobelc01.dbf
channel ORA_DISK_1: restoring datafile 00010 to /home/oradata/stuorcl/sms01.dbf
channel ORA_DISK_1: reading from backup piece /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/full_stuorcl_20150123_3051.bak
channel ORA_DISK_1: piece handle=/oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/full_stuorcl_20150123_3051.bak tag=TAG20150123T030053
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:45:45
Finished restore at 04-FEB-15


RMAN> 


此时去看oracle后台的alert日志,正在一个个修复数据文件,信息如下:
[root@xuelong4 trace]# tail -f /oracle/app/oracle/diag/rdbms/stuunq/stuorcl/trace/alert_stuorcl.log 
GROUP 5 (‘/home/oradata/stuorcl/redo_dg_02.log‘)  SIZE 10M,
GROUP 6 (‘/home/oradata/stuorcl/redo_dg_03.log‘)  SIZE 10M
CHARACTER SET ZHS16GBK
Wed Feb 04 17:05:40 2015
alter database mount
ORA-1100 signalled during: alter database mount
...
Wed Feb 04 17:05:55 2015
alter database mount
ORA-1100 signalled during: alter database mount...
Wed Feb 04 17:08:38 2015
Full restore complete of datafile 8 /home/oradata/stuorcl/help01.dbf.  Elapsed time: 0:00:02 
  checkpoint is 10903299975
  last deallocation scn is 9881798870
Full restore complete of datafile 9 /home/oradata/stuorcl/adobelc01.dbf.  Elapsed time: 0:00:00 
  checkpoint is 10903299975
Wed Feb 04 17:08:53 2015
Full restore complete of datafile 10 /home/oradata/stuorcl/sms01.dbf.  Elapsed time: 0:00:07 
  checkpoint is 10903299975
Wed Feb 04 17:09:52 2015
Full restore complete of datafile 7 /home/oradata/stuorcl/pl01.dbf.  Elapsed time: 0:00:46 
  checkpoint is 10903299975
  last deallocation scn is 10891613103
Wed Feb 04 17:12:41 2015
Full restore complete of datafile 3 /home/oradata/stuorcl/undotbs01.dbf.  Elapsed time: 0:03:28 
  checkpoint is 10903299975
  last deallocation scn is 10903242336
  Undo Optimization current scn is 10903252140
Wed Feb 04 17:14:00 2015
Full restore complete of datafile 4 /home/oradata/stuorcl/users01.dbf.  Elapsed time: 0:05:26 
  checkpoint is 10903299975
  last deallocation scn is 10893349080
Wed Feb 04 17:17:52 2015
Full restore complete of datafile 1 /home/oradata/stuorcl/system01.dbf.  Elapsed time: 0:08:11 
  checkpoint is 10903299975
  last deallocation scn is 10825889348
  Undo Optimization current scn is 10903252140
Wed Feb 04 17:20:27 2015
db_recovery_file_dest_size of 15360 MB is 0.00% used. This is a
user-specified limit on the amount of space that will be used by this
database for recovery-related files, and does not reflect the amount of
space available in the underlying filesystem or ASM diskgroup.
Wed Feb 04 17:20:40 2015
Full restore complete of datafile 2 /home/oradata/stuorcl/sysaux01.dbf.  Elapsed time: 0:12:02 
  checkpoint is 10903299975
  last deallocation scn is 10901674267
  ........




6,开始恢复操作
RMAN>  recover database;


Starting recover at 04-FEB-15
using channel ORA_DISK_1


starting media recovery


channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=29053
channel ORA_DISK_1: reading from backup piece /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/arch_stuorcl_20150123_3052.bak
channel ORA_DISK_1: piece handle=/oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/arch_stuorcl_20150123_3052.bak tag=TAG20150123T032709
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
archived log file name=/oracle/app/oracle/flash_recovery_area/archivelog/1_29053_821708334.dbf thread=1 sequence=29053
unable to find archived log
archived log thread=1 sequence=29054
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 02/04/2015 16:19:14
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 29054 and starting SCN of 10903302108


RMAN> 




在11g官方文档error messages中对错误描述如下:
RMAN-06054: media recovery requesting unknown archived log for thread string with sequence string and starting SCN of string
Cause: Media recovery is requesting a log whose existence is not recorded in the recovery catalog or target database control file.
Action: If a copy of the log is available, then add it to the recovery catalog and/or control file via a CATALOG command and then retry the RECOVER command. If not, then a point-in-time recovery up to the missing log is the only alternative and database can be opened using ALTER DATABASE OPEN RESETLOGS command.


可见,出先此错误的原因是恢复需要的日志记录在控制文件或恢复目录中找不到。解决方法分两种情况:
1.如果相关的日志存在且可用的话,就将此日志记录添加到控制文件或恢复目录中。
2.如果相关的日志已经被删除了或不可用了,那么就按照错误的提示scn将数据库恢复到此scn,本案例是10903302108。也就是说此时数据库只能进行不完全恢复了,在打开数据库时得使用resetlogs打开。


recover database until scn 10903302108;
RMAN> recover database until scn 10903302108;


Starting recover at 04-FEB-15
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 02/04/2015 16:30:30
RMAN-20208: UNTIL CHANGE is before RESETLOGS change


RMAN> 


List of Database Incarnations
DB Key  Inc Key DB Name  DB ID            STATUS  Reset SCN  Reset Time
------- ------- -------- ---------------- --- ---------- ----------
2       2       stuorcl 3391761643       PARENT  945184     25-JUL-13
1       1       stuorcl 3391761643       CURRENT 10909913627 02-FEB-15


RMAN> 
google下,看到http://blog.itpub.net/26442936/viewspace-767439/上面有说明
RMAN> reset database to incarnation 2;
RMAN> restore database until scn 1045382;
RMAN> recover database until scn 1045382;
SQL> alter database open resetlogs;
的方式,不过我的incarnation 2已经是2013年的太早了,这种方式不适合。



尝试rman的不完全恢复记录,切换到SQL窗口去:
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 10903299975 generated at 01/23/2015 03:00:53 needed for
thread 1
ORA-00289: suggestion :
/oracle/app/oracle/flash_recovery_area/archivelog/1_29053_821708334.dbf
ORA-00280: change 10903299975 for thread 1 is in sequence #29053


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}


ORA-00279: change 10903302108 generated at 01/23/2015 03:27:09 needed for
thread 1
ORA-00289: suggestion :
/oracle/app/oracle/flash_recovery_area/archivelog/1_29054_821708334.dbf
ORA-00280: change 10903302108 for thread 1 is in sequence #29054
ORA-00278: log file
‘/oracle/app/oracle/flash_recovery_area/archivelog/1_29053_821708334.dbf‘ no
longer needed for this recovery




Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00308: cannot open archived log
‘/oracle/app/oracle/flash_recovery_area/archivelog/1_29054_821708334.dbf‘
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3




ORA-00308: cannot open archived log
‘/oracle/app/oracle/flash_recovery_area/archivelog/1_29054_821708334.dbf‘
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3




SQL> 


SQL> alter database open resetlogs;


Database altered.


SQL> 


7,去后台验证下数据,找一张一直有日期变化的表数据:
SQL> select  to_char(a.last_login_date,‘yyyy-mm-dd hh24:mi:ss‘) from stu.pst_ac a where to_char(a.last_login_date,‘yyyy-mm-dd hh24:mi:ss‘)>‘2015-01-23 00:00:00:00‘ order by to_char(a.last_login_date,‘yyyy-mm-dd hh24:mi:ss‘)  desc;


TO_CHAR(A.LAST_LOGI
-------------------
2015-01-23 03:10:38
2015-01-23 02:36:13
2015-01-23 01:47:36
2015-01-23 01:29:14
2015-01-23 01:27:41
2015-01-23 01:09:21
2015-01-23 00:52:14
2015-01-23 00:44:52
2015-01-23 00:43:46
2015-01-23 00:32:37
2015-01-23 00:31:59


TO_CHAR(A.LAST_LOGI
-------------------
2015-01-23 00:30:44
2015-01-23 00:27:27
2015-01-23 00:23:20
2015-01-23 00:18:53
2015-01-23 00:17:46
2015-01-23 00:13:25
2015-01-23 00:00:15


18 rows selected.


SQL> 
看到最新为1月23日的数据,表明恢复的数据已经是1月23日的。


去[oracle@xuelong4 admin]$ sqlplus elearning/plel0328@SC_SID;


SQL*Plus: Release 11.2.0.1.0 Production on Wed Feb 4 19:03:56 2015


Copyright (c) 1982, 2009, Oracle.  All rights reserved.




Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> select ut.TABLE_NAME from user_tables ut where rownum<3;


no rows selected

 ----------------------------------------------------------------------------------------------------------------
<版权所有,允许转载,但必须以链接方式注明源地址,否则追究法律责任!>
原博客地址:    http://blog.itpub.net/26230597/viewspace-1426675/
原作者:黄杉 (mchdba)
----------------------------------------------------------------------------------------------------------------

SQL> 
没有一条表记录,所以还是需要找找原因,为什么用户下的表看不见了,~_~。


ORACLE中没有参数文件和控制文件如何通过rman恢复数据库

标签:

原文地址:http://blog.csdn.net/mchdba/article/details/43492939

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!