- 招聘 : Linux运维
- 论坛徽章:
- 0
|
模拟的场景:
硬盘损坏,所有的控制文件,数据文件,redo...全部丢失
无catalog
有rman 的全库备份和archive log的备份,备份在磁带上。
1.环境准备
Netbackup client : node2
Netbackup Server : nub-server
Netbackup version : 6.0 + oracle Agent
Oracle RDBMS version : 10.2.0.2
1.1 做备份
(Netbackup的配置这里不多描述,请参考其它文档)
[oracle@node2 ~]$ $ORACLE_HOME/bin/rman target /
Recovery Manager: Release 10.2.0.2.0 - Production on Wed Jul 23 14:54:35 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: STREAM2 (DBID=1117116731)
先删除所有的备份
RMAN> allocate channel for maintenance type 'SBT_TAPE';
released channel: ORA_DISK_1
allocated channel: ORA_MAINT_SBT_TAPE_1
channel ORA_MAINT_SBT_TAPE_1: sid=91 devtype=SBT_TAPE
channel ORA_MAINT_SBT_TAPE_1: VERITAS NetBackup for Oracle - Release 6.0 (2006110304)
RMAN> delete backup;
List of Backup Pieces
BP Key BS Key Pc# Cp# Status Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
5 5 1 1 AVAILABLE SBT_TAPE STREAM2_tablespace_20080715_8.bak
6 6 1 1 AVAILABLE SBT_TAPE STREAM2_tablespace_20080715_9.bak
Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=STREAM2_tablespace_20080715_8.bak recid=5 stamp=660161646
deleted backup piece
backup piece handle=STREAM2_tablespace_20080715_9.bak recid=6 stamp=660161825
Deleted 2 objects
RMAN> list backup;
RMAN>
做全库备份,并include current controlfile;
RMAN> run {
2> allocate channel t1 type 'sbt_tape';
3> send 'NB_ORA_CLIENT=node2,NB_ORA_SERV=nub-server';
4> backup incremental level 0
5> filesperset 15
6> database format 'dbfull_%I_%t_%s_%p' diskratio=0 include current controlfile;
7> release channel t1;
8> }
allocated channel: t1
channel t1: sid=100 devtype=SBT_TAPE
channel t1: VERITAS NetBackup for Oracle - Release 6.0 (2006110304)
sent command to channel: t1
Starting backup at 23-JUL-08
channel t1: starting incremental level 0 datafile backupset
channel t1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/oradata/stream2/system01.dbf
input datafile fno=00003 name=/u01/oradata/stream2/sysaux01.dbf
input datafile fno=00005 name=/u01/oradata/stream2/example01.dbf
input datafile fno=00002 name=/u01/oradata/stream2/undotbs01.dbf
input datafile fno=00006 name=/u01/oradata/stream2/streams_tbs.dbf
input datafile fno=00004 name=/u01/oradata/stream2/users01.dbf
channel t1: starting piece 1 at 23-JUL-08
channel t1: finished piece 1 at 23-JUL-08
piece handle=dbfull_1117116731_660844580_14_1 tag=TAG20080723T155620 comment=API Version 2.0,MMS Version 5.0.0.0
channel t1: backup set complete, elapsed time: 00:03:10
channel t1: starting incremental level 0 datafile backupset
channel t1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel t1: starting piece 1 at 23-JUL-08
channel t1: finished piece 1 at 23-JUL-08
piece handle=dbfull_1117116731_660844771_15_1 tag=TAG20080723T155620 comment=API Version 2.0,MMS Version 5.0.0.0
channel t1: backup set complete, elapsed time: 00:02:04
Finished backup at 23-JUL-08
released channel: t1
备份归档:
RMAN> run{
2> allocate channel t1 type 'sbt_tape';
3> send 'NB_ORA_CLIENT=node2,NB_ORA_SERV=nub-server';
4> sql 'alter system archive log current';
5> backup format 'arch_%I_%t_%s_%p' diskratio=0 archivelog all delete input;
6> release channel t1;
7> }
using target database control file instead of recovery catalog
allocated channel: t1
channel t1: sid=91 devtype=SBT_TAPE
channel t1: VERITAS NetBackup for Oracle - Release 6.0 (2006110304)
sent command to channel: t1
sql statement: alter system archive log current
Starting backup at 23-JUL-08
current log archived
released channel: t1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 07/23/2008 16:05:55
RMAN-06059: expected archived log not found, lost of archived log compromises recoverability
ORA-19625: error identifying file /u01/oradata/stream2_arch/1_7_657198652.dbf
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
上面这个问题的原因是:
手动删除过归档日志,但是信息还保存在controlfile中,需要crosscheck这些信息。
RMAN> crosscheck archivelog all;
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=91 devtype=DISK
validation failed for archived log
archive log filename=/u01/oradata/stream2_arch/1_7_657198652.dbf recid=1 stamp=657214492
validation failed for archived log
archive log filename=/u01/oradata/stream2_arch/1_8_657198652.dbf recid=2 stamp=660148746
validation failed for archived log
archive log filename=/u01/oradata/stream2_arch/1_9_657198652.dbf recid=3 stamp=660828063
validation failed for archived log
archive log filename=/u01/oradata/stream2_arch/1_10_657198652.dbf recid=4 stamp=660840663
validation succeeded for archived log
archive log filename=/u01/oradata/stream2_arch/1_11_657198652.dbf recid=5 stamp=660845154
validation succeeded for archived log
archive log filename=/u01/oradata/stream2_arch/1_12_657198652.dbf recid=6 stamp=660845155
Crosschecked 6 objects
RMAN> list archivelog all;
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - --------- ----
1 1 7 X 12-JUN-08 /u01/oradata/stream2_arch/1_7_657198652.dbf
2 1 8 X 12-JUN-08 /u01/oradata/stream2_arch/1_8_657198652.dbf
3 1 9 X 15-JUL-08 /u01/oradata/stream2_arch/1_9_657198652.dbf
4 1 10 X 23-JUL-08 /u01/oradata/stream2_arch/1_10_657198652.dbf
5 1 11 A 23-JUL-08 /u01/oradata/stream2_arch/1_11_657198652.dbf
6 1 12 A 23-JUL-08 /u01/oradata/stream2_arch/1_12_657198652.dbf
RMAN> run{
2> allocate channel t1 type 'sbt_tape';
3> send 'NB_ORA_CLIENT=node2,NB_ORA_SERV=nub-server';
4> sql 'alter system archive log current';
5> backup format 'arch_%I_%t_%s_%p' diskratio=0 archivelog all delete input;
6> release channel t1;
7> }
released channel: ORA_DISK_1
allocated channel: t1
channel t1: sid=91 devtype=SBT_TAPE
channel t1: VERITAS NetBackup for Oracle - Release 6.0 (2006110304)
sent command to channel: t1
sql statement: alter system archive log current
Starting backup at 23-JUL-08
current log archived
channel t1: starting archive log backupset
channel t1: specifying archive log(s) in backup set
input archive log thread=1 sequence=11 recid=5 stamp=660845154
input archive log thread=1 sequence=12 recid=6 stamp=660845155
input archive log thread=1 sequence=13 recid=7 stamp=660845283
input archive log thread=1 sequence=14 recid=8 stamp=660845286
channel t1: starting piece 1 at 23-JUL-08
channel t1: finished piece 1 at 23-JUL-08
piece handle=arch_1117116731_660845286_16_1 tag=TAG20080723T160806 comment=API Version 2.0,MMS Version 5.0.0.0
channel t1: backup set complete, elapsed time: 00:01:52
channel t1: deleting archive log(s)
archive log filename=/u01/oradata/stream2_arch/1_11_657198652.dbf recid=5 stamp=660845154
archive log filename=/u01/oradata/stream2_arch/1_12_657198652.dbf recid=6 stamp=660845155
archive log filename=/u01/oradata/stream2_arch/1_13_657198652.dbf recid=7 stamp=660845283
archive log filename=/u01/oradata/stream2_arch/1_14_657198652.dbf recid=8 stamp=660845286
Finished backup at 23-JUL-08
released channel: t1
RMAN>
查看一下所有的备份
RMAN> list backup;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
7 Incr 0 643.50M SBT_TAPE 00:03:09 23-JUL-08
BP Key: 7 Status: AVAILABLE Compressed: NO Tag: TAG20080723T155620
Handle: dbfull_1117116731_660844580_14_1 Media:
List of Datafiles in backup set 7
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 0 Incr 578944 23-JUL-08 /u01/oradata/stream2/system01.dbf
2 0 Incr 578944 23-JUL-08 /u01/oradata/stream2/undotbs01.dbf
3 0 Incr 578944 23-JUL-08 /u01/oradata/stream2/sysaux01.dbf
4 0 Incr 578944 23-JUL-08 /u01/oradata/stream2/users01.dbf
5 0 Incr 578944 23-JUL-08 /u01/oradata/stream2/example01.dbf
6 0 Incr 578944 23-JUL-08 /u01/oradata/stream2/streams_tbs.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
8 Incr 0 7.00M SBT_TAPE 00:02:00 23-JUL-08
BP Key: 8 Status: AVAILABLE Compressed: NO Tag: TAG20080723T155620
Handle: dbfull_1117116731_660844771_15_1 Media:
Control File Included: Ckp SCN: 578982 Ckp time: 23-JUL-08
SPFILE Included: Modification time: 23-JUL-08
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
9 5.75M SBT_TAPE 00:01:48 23-JUL-08
BP Key: 9 Status: AVAILABLE Compressed: NO Tag: TAG20080723T160806
Handle: arch_1117116731_660845286_16_1 Media:
List of Archived Logs in backup set 9
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 11 576844 23-JUL-08 579972 23-JUL-08
1 12 579972 23-JUL-08 579978 23-JUL-08
1 13 579978 23-JUL-08 580115 23-JUL-08
1 14 580115 23-JUL-08 580121 23-JUL-08
1.2 删除所有数据文件,控制文件,redo
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
[oracle@node2 stream2]$ ls
control01.ctl control03.ctl redo01.log redo03.log sysaux01.dbf temp01.dbf users01.dbf
control02.ctl example01.dbf redo02.log streams_tbs.dbf system01.dbf undotbs01.dbf
[oracle@node2 stream2]$ rm ./*
[oracle@node2 stream2]$ pwd
/u01/oradata/stream2
[oracle@node2 stream2]$ cd ../stream2_arch
[oracle@node2 stream2_arch]$ ls -l
total 0
2 开始恢复
将数据库启动到nomount状态,
(
如果需要的话也可以新安装一台机器,
配置好Netbackup的客户端
安装好oracle,并且创建一个instance
)
2.1 先要获取dbid:
好多种方式,我的备份集使用了%I,所以备份的名称中有dbid
![]()
[oracle@node2 ~]$ $ORACLE_HOME/bin/rman target /
Recovery Manager: Release 10.2.0.2.0 - Production on Wed Jul 23 17:23:16 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: stream2 (not mounted)
RMAN> set dbid=1117116731
executing command: SET DBID
2.2 从Netbackup 恢复控制文件
RMAN> run {
2> allocate channel t1 type 'sbt_tape';
3> send 'NB_ORA_CLIENT=node2,NB_ORA_SERV=nub-server';
4> restore controlfile from 'dbfull_1117116731_660844771_15_1';
5> release channel t1;
6> }
(控制文件没有恢复之前,rman肯定查不到备份信息,可以通过在netbackup中可以找到近期的备份,然后通过job的detail看到备份的file list,看上面那张图)
using target database control file instead of recovery catalog
allocated channel: t1
channel t1: sid=101 devtype=SBT_TAPE
channel t1: VERITAS NetBackup for Oracle - Release 6.0 (2006110304)
sent command to channel: t1
Starting restore at 23-JUL-08
channel t1: restoring control file
channel t1: restore complete, elapsed time: 00:01:58
output filename=/u01/oradata/stream2/control01.ctl
output filename=/u01/oradata/stream2/control02.ctl
output filename=/u01/oradata/stream2/control03.ctl
Finished restore at 23-JUL-08
released channel: t1
RMAN> sql 'alter database mount';
sql statement: alter database mount
RMAN> list backup;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
7 Incr 0 643.50M SBT_TAPE 00:03:09 23-JUL-08
BP Key: 7 Status: AVAILABLE Compressed: NO Tag: TAG20080723T155620
Handle: dbfull_1117116731_660844580_14_1 Media:
List of Datafiles in backup set 7
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 0 Incr 578944 23-JUL-08 /u01/oradata/stream2/system01.dbf
2 0 Incr 578944 23-JUL-08 /u01/oradata/stream2/undotbs01.dbf
3 0 Incr 578944 23-JUL-08 /u01/oradata/stream2/sysaux01.dbf
4 0 Incr 578944 23-JUL-08 /u01/oradata/stream2/users01.dbf
5 0 Incr 578944 23-JUL-08 /u01/oradata/stream2/example01.dbf
6 0 Incr 578944 23-JUL-08 /u01/oradata/stream2/streams_tbs.dbf
很明显,里边没有archive log 的备份信息,因为备份控制文件的时候还没有做archive log备份。
所以,想通过rman restore archivelog就不可能了。
RMAN> run {
2> allocate channel t1 type 'sbt_tape';
3> send 'NB_ORA_CLIENT=node2,NB_ORA_SERV=nub-server';
4> restore archivelog all;
5> release channel t1;
6> }
allocated channel: t1
channel t1: sid=101 devtype=SBT_TAPE
channel t1: VERITAS NetBackup for Oracle - Release 6.0 (2006110304)
sent command to channel: t1
Starting restore at 23-JUL-08
released channel: t1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 07/23/2008 17:29:46
RMAN-06026: some targets not found - aborting restore
RMAN-06025: no backup of log thread 1 seq 10 lowscn 556389 found to restore
RMAN-06025: no backup of log thread 1 seq 9 lowscn 531476 found to restore
RMAN-06025: no backup of log thread 1 seq 8 lowscn 496237 found to restore
RMAN-06025: no backup of log thread 1 seq 7 lowscn 495496 found to restore
很明显,根本就不知道还有seq 11,12,13,14 这几个archivelog(RMAN-06025错误只是提示,不需要关心)
///////
不要想用restore archivelog all from 'xxx',会抱错:
RMAN> run {
2> allocate channel t1 type 'sbt_tape';
3> send 'NB_ORA_CLIENT=node2,NB_ORA_SERV=nub-server';
4> restore archivelog all from 'arch_1117116731_660845286_16_1';
5> release channel t1;
6> }
using target database control file instead of recovery catalog
allocated channel: t1
channel t1: sid=82 devtype=SBT_TAPE
channel t1: VERITAS NetBackup for Oracle - Release 6.0 (2006110304)
sent command to channel: t1
Starting restore at 24-JUL-08
released channel: t1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 07/24/2008 17:14:00
RMAN-06509: only SPFILE or control file can be restored from autobackup
////////////
没办法,使用dbms_backup_restore
[oracle@node2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.2.0 - Production on Thu Jul 24 16:06:06 2008
Copyright (c) 1982, 2005, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> select open_mode from v$database;
OPEN_MODE
----------
MOUNTED
SQL> DECLARE
2 devtype varchar2(256);
3 done boolean;
4 BEGIN
5 devtype:=sys.dbms_backup_restore.deviceAllocate(type=>'sbt_tape',ident=>'T1',params=>'ENV=(NB_ORA_CLIENT=node2,NB_ORA_SERV=nub-server)');
6 sys.dbms_backup_restore.restoreSetArchivedLog;
7 sys.dbms_backup_restore.restoreArchivedLogRange;
8 sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>'arch_1117116731_660845286_16_1');
9 sys.dbms_backup_restore.deviceDeallocate;
10 END;
11 /
PL/SQL procedure successfully completed.
handle可通过下图获取
![]()
//////
具体,dbms_backup_restore的语法可以参考 $ORACLE_HOME/rdbms/admin/dbmsbkrs.sql 里的注释
--*********************************************
-- Restore Conversation Initiation Procedures--
--********************************************-- 部分。
5 devtype:=sys.dbms_backup_restore.deviceAllocate(type=>'sbt_tape',ident=>'T1',params=>'ENV=(NB_ORA_CLIENT=node2,NB_ORA_SERV=nub-server)');
说明:类似rman的分配通道
6 sys.dbms_backup_restore.restoreSetArchivedLog;
PROCEDURE restoreSetArchivedLog(destination IN varchar2 default NULL);
是否转换文件恢复位置,用了默认值,就是no。
7 sys.dbms_backup_restore.restoreArchivedLogRange;
PROCEDURE restoreArchivedLogRange(
low_change IN number default 0
,high_change IN number default 281474976710655 );
这里都用了默认值,0-281474976710655。
8 sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>'arch_1117116731_660845286_16_1');
PROCEDURE restoreBackupPiece( handle IN varchar2
,done OUT boolean
,params IN varchar2 default NULL
,fromdisk IN boolean default FALSE );
handle就是备份集名称。
9 sys.dbms_backup_restore.deviceDeallocate;
释放通道
//////
[ 本帖最后由 天涯明月刀 于 2008-7-28 17:29 编辑 ] |
|