当前位置: 首页 > ORACLE > 正文

rman 异机恢复 & set newname 的实验

http://blog.csdn.net/shenghuiping2001/article/details/7080821

https://wenku.baidu.com/view/a7ed90f904a1b0717fd5dd0c.html

12月17日rman 异机恢复:

对本次试验的一点说明:

(1)RMAN 异机恢复的时候,db_name必须相同。 如果说要想改成其他的实例名,可以在恢复成功后,用nid 命令修改。 实例名的信息会记录到控制文件里,所以如果在恢复的时候,如果实例名不一致,恢复的时候会报错。

(2)如果恢复的路径和源库不一致,就需要在restore时用set 命令指定新位置。 并且使用switch datafile all将信息更新的到控制文件。

在做duplicate的时候,RMAN 会自动根据pfile中的log_file_name_convert和db_file_name_convert来进行set 的转换。 手工restore时,只能只只能使用set 命令。

(3)异机恢复对相同目录和不同目录都做了说明。

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘/u01/rman/ctl_%F’;

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘/u01/rman/ctl_%F’;
new RMAN configuration parameters are successfully stored

RMAN> show all;

RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘/u01/rman/ctl_%F’;
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM ‘AES128’; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘/u01/pp/oracle/product/10.2/db_1/dbs/snapcf_ezhou.f’; # default

好,先全库备份:
RMAN> run{
2> backup
3> format ‘/u02/rman/full_%d_%t’
4> database;
5> }

Starting backup at 17-DEC-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u02/ezhou/system01.dbf
input datafile fno=00003 name=/u02/ezhou/sysaux01.dbf
input datafile fno=00005 name=/u02/ezhou/example01.dbf
input datafile fno=00002 name=/u02/ezhou/undotbs01.dbf
input datafile fno=00004 name=/u02/ezhou/users01.dbf
channel ORA_DISK_1: starting piece 1 at 17-DEC-11
channel ORA_DISK_1: finished piece 1 at 17-DEC-11
piece handle=/u02/rman/full_EZHOU_770149569 tag=TAG20111217T182608 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:38
Finished backup at 17-DEC-11

Starting Control File and SPFILE Autobackup at 17-DEC-11
piece handle=/u01/rman/ctl_c-4046377924-20111217-00 comment=NONE
Finished Control File and SPFILE Autobackup at 17-DEC-11

RMAN>

看一下备份路径:
[oracle@aoracle rman]$ pwd
/u02/rman
[oracle@aoracle rman]$ ls -l
total 609616
-rw-r—– 1 oracle oinstall 623632384 Dec 17 18:28 full_EZHOU_770149569
[oracle@aoracle rman]$

不过使用RMAN, DB要先启动到nomout 状态。 这个可以用默认的init.ora 来启动。

原来的init.ora要进行修改:
grep -v ^# init.ora > inittest.ora

export ORACLE_SID=xin
sqlplus / as sysdba
sql:> startup nomount pfile=’/u01/pp/oracle/product/10.2/db_1/dbs/inittest.ora;
报错:
ORA-00371: not enough shared pool memory, should be atleast 62198988 bytes

好,下面修改inittest.ora 里的参数:
注释掉:
#db_block_buffers = 100                                                 # SMALL

#shared_pool_size = 3500000                                            # SMALL

就可以了:
SQL> startup nomount pfile=’/u01/pp/oracle/product/10.2/db_1/dbs/inittest.ora;
ORACLE instance started.

Total System Global Area  113246208 bytes
Fixed Size                  1218004 bytes
Variable Size              58722860 bytes
Database Buffers           50331648 bytes
Redo Buffers                2973696 bytes

——————

3. 创建初始化参数
将Target 库的pfile 文件copy过来。

也可以使用RMAN 从我们Target库的备份集中恢复,因为我们之前备份过spfile。不过使用RMAN, DB要先启动到nomout 状态。 这个可以用默认的init.ora 来启动。

[oracle@qs-dmm-rh2 backup]$ export ORACLE_SID=dave

[oracle@qs-dmm-rh2 backup]$ rman target /

Recovery Manager: Release 11.2.0.1.0 – Production on Fri Mar 11 15:11:31 2011

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

connected to target database: DAVE (not mounted)

RMAN> restore spfile to pfile ‘/u01/rman/initezhou.ora’ from ‘/u01/rman/ezhou_spfile_1_1_20110309′

下面很重要的一点就是:

如果修改数据文件保存的位置,那么要修改参数文件控制文件的相关的参数:
*.control_files=’/u01/rman/control01.ctl’,’/u01/rman/control02.ctl’,’/u01/rman/control03.ctl’

*.db_name=’dave’

 

4. 将用pfile将Auxiliary库启动到nomout 状态
SQL> startup nomount pfile=?/dbs/initezhou.ora

 

5. 恢复控制文件
[oracle@qs-dmm-rh2 dbs]$ export ORACLE_SID=ezhou

[oracle@qs-dmm-rh2 dbs]$ rman target /

Recovery Manager: Release 11.2.0.1.0 – Production on Fri Mar 11 15:25:55 2011

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

connected to target database: ezhou (not mounted)

RMAN>  restore controlfile from ‘/u01/backup/ctl_file_15m6qtdc_1_1_20110309’

。。。。。

会看到恢复好的control 文件放到了/u01/rman 下面。

———————————————————————-

好,下面先看一下control 文件:
strings control01.ctl

/u02/ezhou/redo03.log
/u02/ezhou/redo02.log
/u02/ezhou/redo01.log
/u02/ezhou/users01.dbf
/u02/ezhou/sysaux01.dbf
/u02/ezhou/undotbs01.dbf
/u02/ezhou/system01.dbf
/u02/ezhou/temp01.dbf
/u02/ezhou/example01.dbf
/u02/ezhou/redo03.log
/u02/ezhou/redo02.log
/u02/ezhou/redo01.log
/u02/ezhou/users01.dbf
/u02/ezhou/sysaux01.dbf
/u02/ezhou/undotbs01.dbf
/u02/ezhou/system01.dbf
/u02/ezhou/temp01.dbf
/u02/ezhou/example01.dbf
SYSTEM
UNDOTBS1
SYSAUX
USERS
TEMP
EXAMPLE
SYSTEM
UNDOTBS1
SYSAUX
USERS
TEMP
EXAMPLE
CONTROLFILE AUTOBACKUP
CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE
DISK TO ‘/u01/rman/ctl_%F’
CONTROLFILE AUTOBACKUP

下面对control 文件的内容进行更改:
[oracle@aoracle rman]$ env |grep ORA
ORACLE_SID=xin
ORACLE_BASE=/u01/pp/oracle
ORACLE_HOME=/u01/pp/oracle/product/10.2/db_1
[oracle@aoracle rman]$ sqlplus / as sysdba;

SQL*Plus: Release 10.2.0.1.0 – Production on Sat Dec 17 21:02:05 2011

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

Connected to an idle instance.

SQL> startup nomount pfile=’/u01/rman/initxin.ora’;
ORACLE instance started.

Total System Global Area  335544320 bytes
Fixed Size                  1219280 bytes
Variable Size             104858928 bytes
Database Buffers          226492416 bytes
Redo Buffers                2973696 bytes
SQL> alter database mount;

Database altered.

SQL> !
[oracle@aoracle rman]$ rman target /

Recovery Manager: Release 10.2.0.1.0 – Production on Sat Dec 17 21:07:33 2011

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

connected to target database: EZHOU (DBID=4046377924, not open)

RMAN> run {
2> set newname for datafile 1 to “/u01/rman/system01.dbf”;
3> set newname for datafile 2 to “/u01/rman/undotbs01.dbf”;
4> set newname for datafile 3 to “/u01/rman/sysaux01.dbf”;
5> set newname for datafile 4 to “/u01/rman/users01.dbf”;
6> set newname for datafile 5 to “/u01/rman/example01.dbf”;
7> restore database;
8> switch datafile all;
9> }

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 17-DEC-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/rman/system01.dbf
restoring datafile 00002 to /u01/rman/undotbs01.dbf
restoring datafile 00003 to /u01/rman/sysaux01.dbf
restoring datafile 00004 to /u01/rman/users01.dbf
restoring datafile 00005 to /u01/rman/example01.dbf
channel ORA_DISK_1: reading from backup piece /u02/rman/full_EZHOU_770149569
channel ORA_DISK_1: restored backup piece 1
piece handle=/u02/rman/full_EZHOU_770149569 tag=TAG20111217T182608
channel ORA_DISK_1: restore complete, elapsed time: 00:01:05
Finished restore at 17-DEC-11

datafile 1 switched to datafile copy
input datafile copy recid=7 stamp=770160044 filename=/u01/rman/system01.dbf
datafile 2 switched to datafile copy
input datafile copy recid=8 stamp=770160044 filename=/u01/rman/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=9 stamp=770160044 filename=/u01/rman/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=10 stamp=770160045 filename=/u01/rman/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=11 stamp=770160045 filename=/u01/rman/example01.dbf

恢复目录相同:

RMAN> restore database;

Starting restore at 17-DEC-11
using channel ORA_DISK_1

channel ORA_DISK_1: restoring datafile 00001
input datafile copy recid=12 stamp=770160045 filename=/u02/ezhou/system01.dbf
destination for restore of datafile 00001: /u01/rman/system01.dbf
channel ORA_DISK_1: copied datafile copy of datafile 00001
output filename=/u01/rman/system01.dbf recid=17 stamp=770160303
channel ORA_DISK_1: restoring datafile 00002
input datafile copy recid=13 stamp=770160045 filename=/u02/ezhou/undotbs01.dbf
destination for restore of datafile 00002: /u01/rman/undotbs01.dbf
channel ORA_DISK_1: copied datafile copy of datafile 00002
output filename=/u01/rman/undotbs01.dbf recid=18 stamp=770160314
channel ORA_DISK_1: restoring datafile 00003
input datafile copy recid=14 stamp=770160045 filename=/u02/ezhou/sysaux01.dbf
destination for restore of datafile 00003: /u01/rman/sysaux01.dbf
channel ORA_DISK_1: copied datafile copy of datafile 00003
output filename=/u01/rman/sysaux01.dbf recid=19 stamp=770160352
channel ORA_DISK_1: restoring datafile 00004
input datafile copy recid=15 stamp=770160045 filename=/u02/ezhou/users01.dbf
destination for restore of datafile 00004: /u01/rman/users01.dbf
channel ORA_DISK_1: copied datafile copy of datafile 00004
output filename=/u01/rman/users01.dbf recid=20 stamp=770160361
channel ORA_DISK_1: restoring datafile 00005
input datafile copy recid=16 stamp=770160045 filename=/u02/ezhou/example01.dbf
destination for restore of datafile 00005: /u01/rman/example01.dbf
channel ORA_DISK_1: copied datafile copy of datafile 00005
output filename=/u01/rman/example01.dbf recid=21 stamp=770160379
Finished restore at 17-DEC-11

RMAN> recover database;

Starting recover at 17-DEC-11
using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 3 is already on disk as file /u02/ezhou/redo02.log
archive log filename=/u02/ezhou/redo02.log thread=1 sequence=3
media recovery complete, elapsed time: 00:00:04
Finished recover at 17-DEC-11

注意到上面的log file 还是在/u02/ezhou/下没有改变到/u02/rman下。

好,下面先到open 在改变:

RMAN> alter database open;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 12/17/2011 21:28:22
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

RMAN> alter database open resetlogs;

database opened

SQL> select member from v$logfile;

MEMBER
——————————————————————————–
/u02/ezhou/redo03.log
/u02/ezhou/redo02.log
/u02/ezhou/redo01.log

oracle 至少有2组redo log。 所以我们可以将已经完成归档的redo drop掉, 重新创建。

 

SQL> alter database drop logfile group 3;

Database altered.

SQL> alter database add logfile group 3 (‘/u01/rman/redo03.log’) size 50m;

Database altered.

SQL> alter system switch logfile;

System altered.

SQL> alter database drop logfile group 1;

Database altered.

SQL> alter database add logfile group 1 (‘/u01/oradata/redo01.log’) size 50m;

Database altered.

SQL> alter system switch logfile;

System altered.

SQL> alter database drop logfile group 2;

Database altered.

SQL> alter database add logfile group 2 (‘/u01/oradata/redo02.log’) size 50m;

Database altered.

SQL> select group#,member from v$logfile;

GROUP# MEMBER
———- ———————————————————————
3 /u01/rman/redo03.log
2 /u01/rman/redo02.log
1 /u01/rman/redo01.log

———

最后要进行temp 文件的重建。
更多内容,可以参考:http://blog.csdn.net/tianlesoftware/article/details/6240983

本文固定链接: http://t.yjsec.com/index.php/2017/12/19/220/ | 下一站

该日志由 admin 于2017年12月19日发表在 ORACLE 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: rman 异机恢复 & set newname 的实验 | 下一站

rman 异机恢复 & set newname 的实验:等您坐沙发呢!

发表评论

快捷键:Ctrl+Enter