RMAN还原与恢复2(RMAN Incomplete Recovery)

---恢复内容开始---

一.RMAN实现不完全恢复

步骤:

a.加载数据到mount状态(建议恢复前先做备份);

b.为高并发分配多个通道;

c.还原所有(所需)的数据文件;

d.使用until time,until sequence,until scn来恢复数据库;

e.使用resetlogs打开数据库;

f.全备数据库;

演示RMAN基于until time的例子:

 1 SQL> insert into user1.t select 9,'polestar' from dual;                    
 2 1 row created.                    
 3 SQL> commit;                                                --注意commit是将日志缓冲内容写入到日志文件
 4 
 5 -bash-3.00$ strings redo03.log |grep polestar               --查看联机日志文件中不存在刚刚插入的记录
 6 polestar
 7 -bash-3.00$ 
 8                         
 9 SQL> alter system switch logfile;                        
10 System altered.            
11 SQL>                         
12 
13 --全备
14 RMAN> run{
15 2> allocate channel ch1 type disk;
16 3> allocate channel ch2 type disk;
17 4> backup as compressed backupset database plus archivelog delete input
18 5> format '/tmp/backup/Whole_lg_%U'
19 6> tag='Wholebak_Pluslog';
20 7> release channel ch1;
21 8> release channel ch2;
22 9> }
23 
24 
25 --系统时间
26 SQL> select to_char(sysdate,'YYYY-MM-DD  HH24:MI:SS') as TO_CHAR  from dual;
27 
28 TO_CHAR
29 --------------------
30 2013-01-26  17:50:13
31 
32 --删除表
33 SQL> drop table user1.t;
34 
35 Table dropped.
36 
37 SQL> 
38 
39 --将数据库打开到mount状态
40 SQL> startup mount
41 
42 --恢复
43 RMAN> run{
44 2> allocate channel ch1 type disk;
45 3> allocate channel ch2 type disk;
46 4> set until time "to_date('2013-01-26 17:50:13','yyyy-mm-dd hh24:mi:ss')";   
47 5> restore database;
48 6> recover database;
49 7> alter database open resetlogs;
50 8> release channel ch1;
51 9> release channel ch2;
52 10> }
53 
54 --检验恢复结果
55 SQL> select * from user1.t order by 1;
56 
57         ID NAME
58 ---------- ----------------
59          0 oracle
60          1 oracle
61          2 oracle
62          3 oracle
63          4 oracle
64          5 oracle
65          6 oracle
66          7 myrman
67          8 inspur
68          9 polestar
69 
70 10 rows selected.
71 
72 SQL> 

二. SPFILE文件丢失的恢复

  SPFILE参数文件可以在RMAN中进行备份,因此可以使用RMAN来恢复SPFILE文件。可以自动备份SPFILE。

  SPFILE的自动备份是随着控制文件的备份一起被完成的,因此可以通过自动备份控制文件来实现自动备份SPFILE文件的目的。其次,在备份系统表空间时将引发控制文件的自动备份,而不论是否设置自动备份参数为ON,此时同样也备份SPFILE文件。

SPFILE文件恢复步骤:

a. startup nomount [force];

b. set dbid=dbid_no;

c. restore spfile from autobackup | '<dir>'

d. startup force; 如果d执行失败则转到e,f,否则不用执行e,f。

e. set dbid=dbid_no;

f. startup;

 1 --下面设定控制文件的自动备份以及设置其备份路径(注意要预先知道目标数据库的DBID,此次演示的DBID为)
 2 RMAN> CONFIGURE CONTROLFILE AUTOBACKUP on;
 3 
 4 new RMAN configuration parameters:
 5 CONFIGURE CONTROLFILE AUTOBACKUP ON;
 6 new RMAN configuration parameters are successfully stored
 7 
 8 RMAN> configure controlfile autobackup format for device type disk to '/tmp/backup/ctl_%d_%F';
 9 
10 new RMAN configuration parameters:
11 CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/tmp/backup/ctl_%d_%F';
12 new RMAN configuration parameters are successfully stored
13 
14 RMAN> 
15 
16 SQL> alter tablespace users add datafile '/u01/oradata/sunbak/users03.dbf' size 5m 
17 
18 -bash-3.00$ ls /tmp/backup           --执行上一条alter tablespace users add datafile 语句将引发控制文件的自动备份
19 ctl_SUN_c-1913551800-20130222-01
20 -bash-3.00$    
21 
22 
23 --关机
24 SQL> shutdown immediate;
25 
26 --模拟损坏spfile文件
27 -bash-3.00$ mv spfilesun.ora spfilesun.ora.bak   --将原来的spfile文件重命名
28 
29 --恢复
30 [oracle@oradb ~]$ rman target / nocatalog
31 
32 RMAN> startup nomount force;
33 
34 RMAN> set dbid=1913551800;
35 
36 RMAN> restore spfile from autobackup;   --此处并没有找到文件路径,按Oracle联机文档,在nomount状态应该可以找到
37 RMAN-06172: no autobackup found or specified handle is not a valid copy or piece
38 
39 RMAN> restore spfile from '/u01/bk/rmbk/auto_ctl_ORCL_c-1263182651-20101124-00';    --手动指定路径
40 RMAN> startup force; 
41           

三.控制文件的恢复处理

  控制文件中描述了数据库的相关物理信息,如创建时间、DBID、数据文件、日志文件等相关信息,因此一旦控制文件丢失数据库将不能启动,鉴于其重要性,控制文件的备份与恢复将单独列出。

 1 --将原来的控制文件重命名
 2 -bash-3.00$ mv control01.ctl.bak control01.ctl    
 3 -bash-3.00$ mv control02.ctl.bak control02.ctl    
 4 -bash-3.00$ mv control03.ctl.bak control03.ctl          
 5 
 6 --Nocatalog状态下控制文件的恢复同Spfile文件及其相似(详情请查文档)
 7 [oracle@oradb ~]$ rman target / nocatalog
 8 
 9 RMAN> startup nomount force;
10 
11 RMAN> set dbid=1913551800;
12 
13 RMAN> RESTORE CONTROLFILE FROM '/tmp/backup/ctl_SUN_c-1913551800-20130222-01';                    
14 RMAN>  ALTER DATABASE MOUNT;
15 
16 --此时参考:用户管理的完全恢复6:控制文件损坏(控制文件前后内容改变)
17 SQL> recover database using backup controlfile;
18 ORA-01507: database not mounted
19 
20 SQL> recover database using backup controlfile;
21 ORA-00279: change 831957 generated at 02/22/2013 20:46:02 needed for thread 1
22 ORA-00289: suggestion : /u01/admin/sun/arch/1_2_805747372.dbf
23 ORA-00280: change 831957 for thread 1 is in sequence #2
24 
25 Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
26 /u01/oradata/sunbak/redo01.log
27 Log applied.
28 Media recovery complete.
29 SQL> alter database open resetlogs;
30 
31 Database altered.
32 
33 SQL> 

---恢复内容结束---

posted @ 2013-02-23 10:33  PoleStar  阅读(359)  评论(0编辑  收藏  举报