最近有人问controlfile如果没有单独备份,如何恢复的问题。如果是用rman备份的controlfile,原则上是要用rman恢复它(在rman里restore controlfie)。在rman nocatalog的情况下,但rman可以运行进行恢复的前提是oracle mount状态。oracle mount状态的前提是controlfile要在。死胡同了。(感谢yddll提醒,修改了上句有歧意的说法)。所以以前在oracle备份的建议里我都是建议用文件的方式备份controlfile(见http://bbs.chinaunix.net/viewthread.php?tid=550177)。
如果万一真的没有单独备份controlfile,所有的datafile、controlfile都没了,要恢复,以下方法就是救命大法了。忘记贴过这个内容没有,没见过的赶快记下。
(备份是用NetBackup,bplist是NetBackup的指令;别的备份软件应该也有相应的指令)
关于如何在rman没有catalog的情况下恢复用Rman 备份到磁带上的controlfile
1. 利用 bplist 命令查出最新备份的 controlfile 所在的备份集
# bplist -C oraserver -S bkserver -t 4 -R /
/cntrl_47_1_487002297
/cntrl_46_1_487002110
/cntrl_43_1_486814317
/al_42_1_486814273
/al_40_1_486814236
/al_41_1_486814236
/al_39_1_485975390
/al_38_1_485975073
/al_37_1_485964377
/al_36_1_485956945
/al_35_1_485956730
/al_34_1_485956488
/al_33_1_485798568
/cntrl_32_1_485795684
/al_31_1_485795653
/cntrl_30_1_485794954
/al_29_1_485794918
/cntrl_28_1_485719603
/al_26_1_485719551
/al_27_1_485719551
/bk_25_1_485719418
/bk_24_1_485719417
其中oraserver为oracle所在的NBU客户端,bkserver为 NBU MasterServer.
如上所示/cntrl_47_1_487002297 为最新的controlfile 备份集。
2. 将现有的数据库shutdown之后启动到nomount状态
SQL> conn / as sysdba
Connected.
SQL> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount <pfile=.....>可写可不写,看情况
ORACLE instance started.
Total System Global Area 69652640 bytes
Fixed Size 73888 bytes
Variable Size 52621312 bytes
Database Buffers 16777216 bytes
Redo Buffers 180224 bytes
3. 在SQL中敲入一下脚本
SQL>
SQL> declare
devtype varchar2(256);
done boolean;
begin
devtype:=dbms_backup_restore.deviceallocate('sbt_tape',params=>'');
dbms_backup_restore.restoresetdatafile;
dbms_backup_restore.restorecontrolfileto('/tmp/abc.cf');
dbms_backup_restore.restorebackuppiece('cntrl_47_1_487002297',done=>done
);
end;
/
其中'/tmp/abc.cf'为我们要取出的controlfile 所存放的位置和名称;
'cntrl_47_1_487002297'为先前我们得到的Controlfile 所在的备份集名称
其余不需更改!!
此脚本运行的结果为:
PL/SQL procedure successfully completed.
4. 将/tmp/abc.cf文件改名为正确的controlfile 名字
5. 启动数据库到mount状态
6. 再执行RMAN的恢复脚本,恢复数据。
[ 本帖最后由 老邱 于 2008-3-3 09:55 编辑 ]
alex_linux 回复于:2008-03-01 11:14:34
好文 .赞一个.
收下了
问下 4. 将/tmp/abc.cf文件改名为正确的controlfile 名字
改了名字.后要不要手工把controlfile的文件 copy到原来位置呢?还是就放在那里就好会自动恢复呢?
[ 本帖最后由 alex_linux 于 2008-3-1 11:19 编辑 ]
xiaomao2006 回复于:2008-03-01 15:42:13
顶,大师
无牙 回复于:2008-03-01 21:17:09
顶,牛!
kylinbird 回复于:2008-03-01 21:54:55
3. 在SQL中敲入一下脚本
SQL>
SQL> declare
devtype varchar2(256);
done boolean;
begin
devtype:=dbms_backup_restore.deviceallocate('sbt_tape',params=>'');
dbms_backup_restore.restoresetdatafile;
dbms_backup_restore.restorecontrolfileto('/tmp/abc.cf');
dbms_backup_restore.restorebackuppiece('cntrl_47_1_487002297',done=>done
);
end;
/
请问以上pq/sql语句的目的是只恢复控制文件还是控制文件和数据文件一起恢复,其中一句dbms_backup_restore.restoresetdatafile;
怎么看着像是恢复数据文件啊
maping 回复于:2008-03-02 23:02:21
N
太强了
老邱 回复于:2008-03-03 00:09:42
引用:原帖由 alex_linux 于 2008-3-1 11:14 发表 [url=http://bbs.chinaunix.net/redirect.php?goto=findpost&pid=8025623&ptid=1059208]
问下 4. 将/tmp/abc.cf文件改名为正确的controlfile 名字
改了名字.后要不要手工把controlfile的文件 copy到原来位置呢?还是就放在那里就好会自动恢复呢?
copy到pfile或spfile里指定的controlfile=...位置。这与NBU无关,了解oracle本身各种文件(pfile, controlfile, datafile, logfile)的关系和启动过程就明白了。
老邱 回复于:2008-03-03 00:14:27
引用:
请问以上pq/sql语句的目的是只恢复控制文件还是控制文件和数据文件一起恢复,其中一句dbms_backup_restore.restoresetdatafile;
怎么看着像是恢复数据文件啊
不知道,这时候应该不会能恢复数据文件的。以前我测试过,很管用。有条件的兄弟可以再测试一下。
lsw 回复于:2008-03-03 10:08:33
不错,太牛了。。
fly1928 回复于:2008-03-03 10:32:26
好文,如果早几年,我的客户就有福了.
redwaves 回复于:2008-03-03 12:35:37
引用:原帖由 fly1928 于 2008-3-3 10:32 发表 [url=http://bbs.chinaunix.net/redirect.php?goto=findpost&pid=8030608&ptid=1059208]
好文,如果早几年,我的客户就有福了.
这个办法以版主早写过的呀.
星海夜航 回复于:2008-05-05 15:27:36
正好遇到这样的问题,环境为tsm+oracle10g,测试结果如下
SQL> declare
2 devtype varchar2(256);
3 done boolean;
4 begin
5 devtype:=dbms_backup_restore.deviceallocate('sbt_tape',params=>'ENV=(TDPO_OPTFILE=/opt/tivoli/tsm/client/oracle/bin64/tdpodbac.opt)');
6 dbms_backup_restore.restoresetdatafile;
7 dbms_backup_restore.restorecontrolfileto('/tmp/abc.cf');
8 dbms_backup_restore.restorebackuppiece('df_652960629_409_1',done=>done);
9 end;
10 /
PL/SQL procedure successfully completed.
$ cp abc.cf /xxx/xxxx/xxxx/data/xxxprd1_control01.ctl
$ cp xxxprd1_control01.ctl xxxxprd1_control02.ctl
$ rman target / catalog rman/rman@rman
Recovery Manager: Release 10.2.0.3.0 - Production on Mon May 5 07:12:18 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: accaprd1 (not mounted)
connected to recovery catalog database
RMAN> alter database mount;
database mounted
星海夜航 回复于:2008-05-05 16:09:07
很奇怪的问题,使用catalog+tsm+rman备份数据库,测试我把所有controlfile全部删除,数据库down,在nomount下无法恢复通过rman备份到磁带的controlfile
RMAN>startup nomount;
RMAN> run{
2> allocate channel t1 type 'sbt_tape' parms
3> 'ENV=(TDPO_OPTFILE=/opt/tivoli/tsm/client/oracle/bin64/tdpodbac.opt)';
4> restore controlfile to '/opt/tivoli/ctl.bak';
5> }
allocated channel: t1
channel t1: sid=559 devtype=SBT_TAPE
channel t1: Data Protection for Oracle: version 5.4.1.0
Starting restore at 05-MAY-08
released channel: t1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 05/05/2008 06:50:31
RMAN-06026: some targets not found - aborting restore
RMAN-06024: no backup or copy of the control file found to restore
但是通过命令可以看到controlfile在磁带中有很多份备份
RMAN> list backup of controlfile;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
190553 Incr 1 7.50M SBT_TAPE 00:00:00 2008-03-07 02:23:51
BP Key: 190560 Status: AVAILABLE Compressed: NO Tag: TAG20080306T181846
Handle: df_648699831_272_1 Media: 221
Control File Included: Ckp SCN: 11868796108 Ckp time: 2008-03-07 02:23:51
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
191816 Incr 1 7.50M SBT_TAPE 00:00:00 2008-03-08 02:25:02
BP Key: 191823 Status: AVAILABLE Compressed: NO Tag: TAG20080307T181956
Handle: df_648786302_276_1 Media: 221
Control File Included: Ckp SCN: 11868884271 Ckp time: 2008-03-08 02:25:02
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
193070 Incr 0 7.50M SBT_TAPE 00:00:00 2008-03-09 02:25:52
BP Key: 193077 Status: AVAILABLE Compressed: NO Tag: TAG20080308T181936
Handle: df_648872752_280_1 Media: 221
Control File Included: Ckp SCN: 11868975130 Ckp time: 2008-03-09 02:25:52
后来通过楼上的方法恢复了controlfile,后来recover时有问题,再测试,
出现RMAN-06004: ORACLE error from recovery catalog database: RMAN-20011: target database incarnation is not current in recovery catalog
于是我reset database到一个incarnation后,在nomount下也可以恢复controlfile和数据文件,这是何解?
RMAN> startup nomount;
connected to target database (not started)
Oracle instance started
Total System Global Area 633339904 bytes
Fixed Size 2275384 bytes
Variable Size 293357512 bytes
Database Buffers 335544320 bytes
Redo Buffers 2162688 bytes
RMAN> reset database to incarnation 99362;
database reset to incarnation 99362
RMAN> run{
2> allocate channel t1 type 'sbt_tape' parms
3> 'ENV=(TDPO_OPTFILE=/opt/tivoli/tsm/client/oracle/bin64/tdpodbac.opt)';
4> restore controlfile;
5> }
allocated channel: t1
channel t1: sid=559 devtype=SBT_TAPE
channel t1: Data Protection for Oracle: version 5.4.1.0
Starting restore at 2008-05-05 07:56:11
channel t1: starting datafile backupset restore
channel t1: restoring control file
channel t1: reading from backup piece df_652960629_409_1
channel t1: restored backup piece 1
piece handle=df_652960629_409_1 tag=TAG20080425T015104
channel t1: restore complete, elapsed time: 00:00:03
output filename=/xxx/xxxx/accaprd1/data/accaprd1_control01.ctl
output filename=/xxx/xxxx/accaprd1/data/accaprd1_control02.ctl
Finished restore at 2008-05-05 07:56:16
released channel: t1
[ 本帖最后由 星海夜航 于 2008-5-5 16:22 编辑 ]
|