RMAN 恢复

可以在mount的情况;

alter database create datafile 8----前提在控制文件中已经有datafile相关记录。

然后alter database rename file '+DATA/xxxxxxxxxxxxxx' to '+DATA/yyyyyyyyyyyyyyyyyy' 



alter database backup control file to trace可以产生一个控制文件的文本备份。用于控制文件恢复

可以去alert文件里查看刚才生成的trace file文件名。


实验

先备份整个数据加控制文件spfile


backup database  

RMAN> list backup;

using target database control file instead of recovery catalog

List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
9       Full    1.49G      DISK        00:00:27     18-MAR-13      
        BP Key: 9   Status: AVAILABLE  Compressed: NO  Tag: TAG20130318T052627
        Piece Name: +DATA/orcl/backupset/2013_03_18/nnndf0_tag20130318t052627_0.710.810365187
  List of Datafiles in backup set 9
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 25341971   18-MAR-13 +DATA/orcl/datafile/system.256.793082125
  2       Full 25341971   18-MAR-13 +DATA/orcl/datafile/sysaux.257.793082125
  3       Full 25341971   18-MAR-13 +DATA/orcl/datafile/undotbs1.258.793082127
  4       Full 25341971   18-MAR-13 +DATA/orcl/datafile/users.259.793082127
  5       Full 25341971   18-MAR-13 +DATA/orcl/datafile/undotbs2.267.793082251

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
10      Full    18.17M     DISK        00:00:01     18-MAR-13      
        BP Key: 10   Status: AVAILABLE  Compressed: NO  Tag: TAG20130318T052702
        Piece Name: +DATA/orcl/autobackup/2013_03_18/s_810365222.706.810365223
  SPFILE Included: Modification time: 17-MAR-13
  SPFILE db_unique_name: ORCL
  Control File Included: Ckp SCN: 25342056     Ckp time: 18-MAR-13



删除所有的数据文件,控制文件,联机日志文件;


orcl1>select name from v$controlfile
  2  union 
  3  select name from v$datafile
  4  union
  5  select member name from v$logfile;

NAME
----------------------------------------------------------------------
+DATA/orcl/controlfile/current.260.793082219
+DATA/orcl/controlfile/current.261.793082219
+DATA/orcl/datafile/sysaux.257.793082125
+DATA/orcl/datafile/system.256.793082125
+DATA/orcl/datafile/undotbs1.258.793082127
+DATA/orcl/datafile/undotbs2.267.793082251
+DATA/orcl/datafile/users.259.793082127
+DATA/orcl/onlinelog/group_1.262.793082223
+DATA/orcl/onlinelog/group_1.263.793082223
+DATA/orcl/onlinelog/group_2.264.793082223
+DATA/orcl/onlinelog/group_2.265.793082225

NAME
----------------------------------------------------------------------
+DATA/orcl/onlinelog/group_3.268.793082307
+DATA/orcl/onlinelog/group_3.269.793082307
+DATA/orcl/onlinelog/group_4.270.793082309
+DATA/orcl/onlinelog/group_4.271.793082309

15 rows selected.

.

关闭两个实例

shutdown abort; --所有实例


进行删除操作:--删除上面列出的所有文件


恢复步骤:


先从备份中恢复控制文件

sal>startup nomount;

[oracle@juliaz2 ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Mar 18 06:50:11 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (not mounted)

RMAN> restore controlfile from '+DATA/orcl/autobackup/2013_03_18/s_810365222.706.810365223';

Starting restore at 18-MAR-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=134 instance=orcl1 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=+DATA/orcl/controlfile/current.267.810370223
output file name=+DATA/orcl/controlfile/current.258.810370223
Finished restore at 18-MAR-13


rman>restore controlfile form '控制文件备份所在路径'


控制文件恢复成功后


rman > sql 'alter database mount' ;

RMAN> sql 'alter database mount';

sql statement: alter database mount
released channel: ORA_DISK_1

RMAN> 

rman>restore database ;

RMAN> restore database ;

Starting restore at 18-MAR-13
Starting implicit crosscheck backup at 18-MAR-13
allocated channel: ORA_DISK_1
Crosschecked 3 objects
Finished implicit crosscheck backup at 18-MAR-13

Starting implicit crosscheck copy at 18-MAR-13
using channel ORA_DISK_1
Crosschecked 16 objects
Finished implicit crosscheck copy at 18-MAR-13

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: +dg1/ORCL/ARCHIVELOG/2013_03_18/thread_1_seq_426.257.810368515
File Name: +dg1/ORCL/ARCHIVELOG/2013_03_18/thread_1_seq_427.258.810368563
File Name: +dg1/ORCL/ARCHIVELOG/2013_03_18/thread_1_seq_428.259.810368569
File Name: +dg1/ORCL/ARCHIVELOG/2013_03_18/thread_2_seq_460.260.810368569
File Name: +dg1/ORCL/ARCHIVELOG/2013_03_18/thread_1_seq_429.261.810369187
File Name: +dg1/ORCL/ARCHIVELOG/2013_03_18/thread_1_seq_430.262.810369189

using channel ORA_DISK_1

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 +DATA/orcl/datafile/system.256.793082125
channel ORA_DISK_1: restoring datafile 00002 to +DATA/orcl/datafile/sysaux.257.793082125
channel ORA_DISK_1: restoring datafile 00003 to +DATA/orcl/datafile/undotbs1.258.793082127
channel ORA_DISK_1: restoring datafile 00004 to +DATA/orcl/datafile/users.259.793082127
channel ORA_DISK_1: restoring datafile 00005 to +DATA/orcl/datafile/undotbs2.267.793082251
channel ORA_DISK_1: reading from backup piece +DATA/orcl/backupset/2013_03_18/nnndf0_tag20130318t052627_0.710.810365187
channel ORA_DISK_1: piece handle=+DATA/orcl/backupset/2013_03_18/nnndf0_tag20130318t052627_0.710.810365187 tag=TAG20130318T052627
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 18-MAR-13


接下来确定恢复终点;

查看控制文件中归档日志记录;

查看磁盘上的归档日志记录

sql>select name from v$archived_log;

orcl1>select name from v$archived_log;
+DG1/orcl/archivelog/2013_03_18/thread_1_seq_426.257.810368515
+DG1/orcl/archivelog/2013_03_18/thread_1_seq_427.258.810368563
+DG1/orcl/archivelog/2013_03_18/thread_1_seq_428.259.810368569
+DG1/orcl/archivelog/2013_03_18/thread_2_seq_460.260.810368569

NAME
----------------------------------------------------------------------
+DG1/orcl/archivelog/2013_03_18/thread_1_seq_429.261.810369187
+DG1/orcl/archivelog/2013_03_18/thread_1_seq_430.262.810369189

442 rows selected.

再看看磁盘上的归档日志

ASMCMD> pwd
+dg1/orcl/archivelog/2013_03_18
ASMCMD> ls
thread_1_seq_426.257.810368515
thread_1_seq_427.258.810368563
thread_1_seq_428.259.810368569
thread_1_seq_429.261.810369187
thread_1_seq_430.262.810369189
thread_2_seq_460.260.810368569
ASMCMD> 


有些归档日志是在备份之后产生的,所以不被当前控制文件所知道。需要把这些文件登记到控制文件中;

可以在我的实验里没有。

登记备份后产生的日志需要用rman的catalog命令;

rman>catalog  archivelog '归档文件所在路径‘;

。。。

直到全部注册到controlfile;


确认恢复终点

sql>select thread#,sequence#,name,next_change# from v$archived_log

	 1	  426 +DG1/orcl/archivelog/2013_03_18/thread_1_seq_426.257.810368515		 25350729
	 1	  427 +DG1/orcl/archivelog/2013_03_18/thread_1_seq_427.258.810368563		 25352313
	 1	  428 +DG1/orcl/archivelog/2013_03_18/thread_1_seq_428.259.810368569		 25359744
	 2	  460 +DG1/orcl/archivelog/2013_03_18/thread_2_seq_460.260.810368569		 25360192

   THREAD#  SEQUENCE# NAME								     NEXT_CHANGE#
---------- ---------- ---------------------------------------------------------------------- ------------
	 1	  429 +DG1/orcl/archivelog/2013_03_18/thread_1_seq_429.261.810369187		 25387789
	 1	  430 +DG1/orcl/archivelog/2013_03_18/thread_1_seq_430.262.810369189		 25387794

442 rows selected.

orcl1>l
  1* select thread#,sequence#,name,next_change# from v$archived_log


再执行恢复;

sql>recover database using backup controlfile until cancel;也可以用rman工具,但是需要使用set until提前指定恢复终点,比较麻烦,还是sql中的简单。

orcl1>recover database using backup controlfile until cancel ;
ORA-00279: change 25341971 generated at 03/18/2013 05:26:27 needed for thread 1
ORA-00289: suggestion : +DG1/orcl/archivelog/2013_03_18/thread_1_seq_426.257.810368515
ORA-00280: change 25341971 for thread 1 is in sequence #426


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
+DG1/orcl/archivelog/2013_03_18/thread_1_seq_426.257.810368515
ORA-00279: change 25341971 generated at 03/17/2013 23:18:17 needed for thread 2
ORA-00289: suggestion : +DG1/orcl/archivelog/2013_03_18/thread_2_seq_460.260.810368569
ORA-00280: change 25341971 for thread 2 is in sequence #460


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
+DG1/orcl/archivelog/2013_03_18/thread_2_seq_460.260.810368569
ORA-00279: change 25350729 generated at 03/18/2013 06:21:54 needed for thread 1
ORA-00289: suggestion : +DG1/orcl/archivelog/2013_03_18/thread_1_seq_427.258.810368563
ORA-00280: change 25350729 for thread 1 is in sequence #427
ORA-00278: log file '+DG1/orcl/archivelog/2013_03_18/thread_1_seq_426.257.810368515' no longer needed for this recovery


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
 +DG1/orcl/archivelog/2013_03_18/thread_1_seq_427.258.810368563
ORA-00279: change 25352313 generated at 03/18/2013 06:22:43 needed for thread 1
ORA-00289: suggestion : +DG1/orcl/archivelog/2013_03_18/thread_1_seq_428.259.810368569
ORA-00280: change 25352313 for thread 1 is in sequence #428
ORA-00278: log file '+DG1/orcl/archivelog/2013_03_18/thread_1_seq_427.258.810368563' no longer needed for this recovery


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
+DG1/orcl/archivelog/2013_03_18/thread_1_seq_428.259.810368569
ORA-00279: change 25359744 generated at 03/18/2013 06:22:48 needed for thread 1
ORA-00289: suggestion : +DG1/orcl/archivelog/2013_03_18/thread_1_seq_429.261.810369187
ORA-00280: change 25359744 for thread 1 is in sequence #429
ORA-00278: log file '+DG1/orcl/archivelog/2013_03_18/thread_1_seq_428.259.810368569' no longer needed for this recovery


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
+DG1/orcl/archivelog/2013_03_18/thread_1_seq_429.261.810369187
ORA-00279: change 25360192 generated at 03/18/2013 06:22:49 needed for thread 2
ORA-00289: suggestion : +DG1
ORA-00280: change 25360192 for thread 2 is in sequence #461
ORA-00278: log file '+DG1/orcl/archivelog/2013_03_18/thread_2_seq_460.260.810368569' no longer needed for this recovery


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.


如果使用rman ,需要下面的方法

rman> run {

set until sequence 64 thread 2;

restore database;

recover database;

}

如果在rman中我们不提前确认能够恢复的终点,并且用set until 明确指出.Oracle会尝试恢复所有的归档。

在单实例情况下,每个归档日志中的scn号是连续分布的,因此这种尝试肯定会成功;但是在RAC环境下,scn是在实例间分布的,因此归档日志间的scn可能是不连续。这时某些归档日志虽然文件存在,但是却不能恢复到最后时间点。


以resetlogs方式打开数据库

orcl1>alter database open resetlogs;

Database altered.

orcl1>

打开其他实例



最后,进行数据库完全备份。


在以上操作过程,不清楚节点在哪一个步骤自动在本地生成了spfile文件,

生成正确的pfile,然后用pfile生成正确的spfile,还需要修改一下本地的initsid.ora 文件,和ocr里面spfile的文件路径。我们一般是用srvctl来启动和关闭数据库的,而srvctl读取的ocr里面的配置信息,所以要更新ocr的spfile信息

orcl2>create spfile='+DATA/orcl/spfileorcl.ora' from pfile='/tmp/pfileorcl1.ora';
[oracle@juliaz2 dbs]$ pwd
/u01/app/oracle/dbs
[oracle@juliaz2 dbs]$ more initorcl1.ora
SPFILE='+DATA/orcl/spfileorcl.ora'		# line added by Agent
[oracle@juliaz2 dbs]$ 
[root@juliaz2 ~]# srvctl modify database -d orcl -p +DATA/orcl/spfileorcl.ora
[[root@juliaz2 dbs]# srvctl config database -d orcl -a
Database unique name: orcl
Database name: orcl
Oracle home: /u01/app/oracle
Oracle user: oracle
Spfile: +DATA/orcl/spfileorcl.ora
Domain: 
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: orcl
Database instances: orcl1,orcl2
Disk Groups: DATA
Services: 
Database is enabled
Database is administrator managed
[root@juliaz2 dbs]# 


参考图书:大话Oracle RAC

oracle联机文档











评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值