Chinaunix首页 | 论坛 | 博客
  • 博客访问: 337078
  • 博文数量: 81
  • 博客积分: 2107
  • 博客等级: 大尉
  • 技术积分: 742
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-30 09:38
文章分类

全部博文(81)

文章存档

2011年(2)

2010年(28)

2009年(45)

2008年(6)

我的朋友

分类: Oracle

2010-09-16 16:10:15

只有rman的备份文件恢复过程
Created by foway in uplooking.com 2008: 欢迎转载,但请保留本行说明,谢谢!

1.
通过rman备份文件恢复spfile
2.
通过rman备份文件恢复controlfile
3.
通过rman备份文件恢复datafile
4.
利用恢复回来的controlfiledatafile生成redolog
5.
测试交易是否存在,并全备
 
======================郭苗苗添加================================
使用这段进行完全备份
$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
RMAN> run {
2> allocate channel dsk type disk format '/opt/oracle/backup/%U.bak' ;
3> backup database plus archivelog;
4> backup current controlfile;
5> }
===============================================================
 
 

系统环境所有的文件如下:

[oracle@foway dbs]$ pwd
/opt/oracle/10g/dbs
[oracle@foway dbs]$ ls
initdw.ora
init.ora

[oracle@foway dbs]$ls /opt/oracle/oradata
已没有任何资料
[oracle@foway dbs]$ls /opt/oracle/admin
已没有任何资料
[oracle@foway dbs] ls /opt/oracle/flash_recovery_area/
ORCL
[oracle@foway dbs]ls /opt/oracle/flash_recovery_area/ORCL/backupset/
2008_07_18
[oracle@foway dbs]ls /opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/
o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkp
o1_mf_nnndf_TAG20080718T203240_482fkb0k_.bkp

在我这台电脑上, ,系统中所有的ORCL相关的数据文件,参数文件,日志文件,控制文件全部不在了, 没有其他可用的备份文件了,只有rman备份的文件在,这可怎么办呢?

没办法只能恢复了,可怎么恢复呢?

要恢复数据文件用rman备份? 能吗? 当然不能了,因为restore必须在mount or open状态下.
参数文件,控制文件都没有怎么mount?

mount必须有参数文件,控制文件,为此我们必须解决这2个难题了.
在解决难题前先准备ORCL的必须的目录:
[oracle@foway dbs]mkdir /opt/oracle/oradata/orcl
[oracle@foway dbs]mkdir /opt/oracle/admin/orcl/adump –p
[oracle@foway dbs]mkdir /opt/oracle/admin/orcl/cdump
[oracle@foway dbs]mkdir /opt/oracle/admin/orcl/bdump
[oracle@foway dbs]mkdir /opt/oracle/admin/orcl/udump
[oracle@foway dbs]mkdir /opt/oracle/admin/orcl/dpdump
[oracle@foway dbs]mkdir /opt/oracle/admin/orcl/pfile


难题1:spfile
有人说没参数文件我新建立一个pfile,当然这个办法是可行的,不过在10grman备份是自动备份了spfile,所以我们可以利用rman来恢复spfile.

[oracle@foway dbs]rman target / nocatalog

Recovery Manager: Release 10.2.0.4.0 - Production on Fri Jul 18 21:21:47 2008

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


connected to target database (not started)

RMAN> list backup;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of list command at 07/18/2008 21:24:37
RMAN-06403: could not obtain a fully authorized session
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux Error: 2: No such file or directorylist copy;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of list command at 07/18/2008 21:24:51
RMAN-06403: could not obtain a fully authorized session
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux Error: 2: No such file or directory

看到上面的是正常的,因为数据库没有启动呢.
于是我们先启动数据库到nomout
RMAN>startup nomount

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/opt/oracle/10g/dbs/initorcl.ora'

starting Oracle instance without parameter file for retrival of spfile
Oracle instance started

Total System Global Area
159383552 bytes


Fixed Size
1218268 bytes

Variable Size
54528292 bytes

Database Buffers
100663296 bytes

Redo Buffers

2973696 bytes


RMAN>list backup;
RMAN>list copy;
将与上次执行看到的一样,此时也是正常的,不必担心,下面就是利用rman备份文件来解决难题1.
RMAN> restore spfile
from '/opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkp';
Starting restore at 18-JUL-08
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=36 devtype=DISK

channel ORA_DISK_1: autobackup found: /opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkp
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 18-JUL-08

下面是来验证spfileorcl.ora文件是否已存在:
[oracle@foway dbs]$ pwd
/opt/oracle/10g/dbs
[oracle@foway dbs]$ ls
initdw.ora
init.ora
spfileorcl.ora

恭喜你:spfile已恢复了
有了参数文件,就需要解决控制文件恢复了
难题2. 控制文件恢复

这个又怎么恢复呢? 用rman的自动备份控制文件的rman备份吗? 是的没错,只有从rman备份文件中提取出来的controlfile才能使用rman备份文件恢复datafile的.



那么这里有来种办法来实现从rman备份文件中提取出controlfie了.

方法1.

RMAN>restore controlfile from ‘/…备份文件..’;

恢复的控制文件将放在$ORACLE_HOME/dbs/cncontrl.dbf不过这个方法有时恢复的控制文件中记录的dbname与实际不一致.



方法2: 利用dbms_backup_restore提取controlfile

步骤:

[oracle@foway dbs]$sqlplus /nolog

SQL*Plus: Release 10.2.0.4.0 - Production on Fri Jul 18 21:38:21 2008



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



SQL> conn /as sysdba

Connected.

由于在刚才使用rman时执行了startup nomount,所以这里是connected,下面我们到nomount状态

SQL> startup force nomount

ORACLE instance started.



Total System Global Area  167772160 bytes

Fixed Size                  1218316 bytes

Variable Size              62916852 bytes

Database Buffers          100663296 bytes

Redo Buffers                2973696 bytes

SQL>DECLARE

2devtype varchar2(256);

3done boolean;

4BEGIN

5devtype:=sys.dbms_backup_restore.deviceAllocate(type=>'',ident=>'T1');

6sys.dbms_backup_restore.restoreSetDatafile;

7sys.dbms_backup_restore.restoreControlfileTo(cfname=>'/opt/oracle/oradata/orcl/control01.ctl');

8sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>'/opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkp',params=>null);

9 sys.dbms_backup_restore.deviceDeallocate;

10 end;

11/



PL/SQL procedure successfully completed.



下面验证control01.ctl是否恢复:

[oracle@foway dbs]$ ls /opt/oracle/oradata/orcl/

control01.ctl

[oracle@foway dbs]$

看到了control01.ctl 恭喜你:难题2 解决了.

于是我们可以启动数据库到mount状态了.

[oracle@foway dbs]$sqlplus /nolog



SQL*Plus: Release 10.2.0.4  - Production on Fri Jul 18 21:45:32 2008



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



SQL> conn /as sysdba

Connected.

SQL> startup force mount

ORACLE instance started.



Total System Global Area  167772160 bytes

Fixed Size                  1218316 bytes

Variable Size              62916852 bytes

Database Buffers          100663296 bytes

Redo Buffers                2973696 bytes

ORA-00205: error in identifying control file, check alert log for more info



我们已经恢复了控制文件了,怎么还是有错误呢,其实不用担心,看看spfile中的记录先

SQL> show parameter control_files



NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

control_files                        string      /opt/oracle/oradata/orcl/contr

                                                 ol01.ctl, /opt/oracle/oradata/

                                                 orcl/control02.ctl, /opt/oracl

                                                 e/oradata/orcl/control03.ctl

SQL>

既然如此,我们就把控制文件同步下好了.

SQL> ho cp /opt/oracle/oradata/orcl/control01.ctl /opt/oracle/oradata/orcl/control02.ctl

SQL> ho cp /opt/oracle/oradata/orcl/control01.ctl /opt/oracle/oradata/orcl/control03.ctl

SQL> alter database mount;



Database altered.



SQL> ho ls /opt/oracle/oradata/orcl/

control01.ctl  control02.ctl  control03.ctl



好了到这里我们已经成功解决了难题2了.



有了恢复后的控制文件,我们就可以使用rman查看与使用以前的rman备份了.



恢复datafile 步骤:

rman target / nocatalog



Recovery Manager: Release 10.2.0.4 - Production on Fri Jul 18 21:49:10 2008



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



connected to target database: ORCL (DBID=1188209463, not open)

using target database control file instead of recovery catalog



RMAN>

看到了 红色部分了吗,太好了终于看到了正常的rman登陆信息了.

那就list copy|backup 看看能找到我们的

o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkp

o1_mf_nnndf_TAG20080718T203240_482fkb0k_.bkp

文件吗.

RMAN> list copy;



specification does not match any archive log in the recovery catalog



RMAN> list backup;





List of Backup Sets

===================



BS Key  Type LV Size       Device Type Elapsed Time Completion Time

------- ---- -- ---------- ----------- ------------ ---------------

1       Full    495.41M    DISK        00:00:41     18-JUL-08      

        BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20080718T203240

        Piece Name: /opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/o1_mf_nnndf_TAG20080718T203240_482fkb0k_.bkp

  List of Datafiles in backup set 1

  File LV Type Ckp SCN    Ckp Time  Name

  ---- -- ---- ---------- --------- ----

  1       Full 453304     18-JUL-08 /opt/oracle/oradata/orcl/system01.dbf

  2       Full 453304     18-JUL-08 /opt/oracle/oradata/orcl/undotbs01.dbf

  3       Full 453304     18-JUL-08 /opt/oracle/oradata/orcl/sysaux01.dbf

  4       Full 453304     18-JUL-08 /opt/oracle/oradata/orcl/users01.dbf



RMAN>

太好了,总于可以使用restore,recover来恢复datafile了.

RMAN> restore database;



Starting restore at 18-JUL-08

Starting implicit crosscheck backup at 18-JUL-08

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=156 devtype=DISK

Crosschecked 1 objects

Finished implicit crosscheck backup at 18-JUL-08



Starting implicit crosscheck copy at 18-JUL-08

using channel ORA_DISK_1

Finished implicit crosscheck copy at 18-JUL-08



searching for all files in the recovery area

cataloging files...

cataloging done



List of Cataloged Files

=======================

File Name: /opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkp



using channel ORA_DISK_1



channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00001 to /opt/oracle/oradata/orcl/system01.dbf

restoring datafile 00002 to /opt/oracle/oradata/orcl/undotbs01.dbf

restoring datafile 00003 to /opt/oracle/oradata/orcl/sysaux01.dbf

restoring datafile 00004 to /opt/oracle/oradata/orcl/users01.dbf

channel ORA_DISK_1: reading from backup piece /opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/o1_mf_nnndf_TAG20080718T203240_482fkb0k_.bkp

channel ORA_DISK_1: restored backup piece 1

piece handle=/opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/o1_mf_nnndf_TAG20080718T203240_482fkb0k_.bkp tag=TAG20080718T203240

channel ORA_DISK_1: restore complete, elapsed time: 00:00:56

Finished restore at 18-JUL-08



RMAN>

此时可以在$ORACLE_BASE/oradata/orcl/下看到期望已久的datafile了.

[oracle@foway dbs] ls /opt/oracle/oradata/orcl/

control01.ctl  control02.ctl  control03.ctl  sysaux01.dbf  system01.dbf  undotbs01.dbf  users01.dbf

[oracle@foway dbs]

不过此时还没有完哈,需要在接在励.



由于没有redo log日志文件所以我们不应用日志恢复:

RMAN> recover database noredo;



Starting recover at 18-JUL-08

using channel ORA_DISK_1

Finished recover at 18-JUL-08



RMAN>



到目前我们已经拥有了参数文件,控制文件,数据文件了:

[oracle@foway dbs] ls /opt/oracle/oradata/orcl/

ls /opt/oracle/oradata/orcl/

control01.ctl  control02.ctl  control03.ctl  sysaux01.dbf  system01.dbf  

undotbs01.dbf  users01.dbf

[oracle@foway dbs] ls /opt/oracle/10g/dbs/

alert_orcl.log  hc_orcl.dat  initdw.ora  init.ora  lkORCL  spfileorcl.ora

还差一个密码文件,以及相关的日志文件了.

先解决密码文件:

[oracle@foway dbs] orapwd file=/opt/oracle/10g/dbs/orapworcl password=uplooking entries=5

[oracle@foway dbs] ls /opt/oracle/10g/dbs/

ls /opt/oracle/10g/dbs/

alert_orcl.log  initdw.ora  lkORCL     spfileorcl.ora

hc_orcl.dat     init.ora    orapworcl



下面需要大家坚持不懈的完成最后一个工作了.

那就是通过已经恢复的controlfile and datafile 来演算出redo log file了.

步骤:

[oracle@foway dbs]sqlplus /nolog

SQL*Plus: Release 10.2.0.4 - Production on Fri Jul 18 21:58:05 2008



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



SQL> conn /as sysdba

Connected.

SQL> startup force mount

ORACLE instance started.



Total System Global Area  167772160 bytes

Fixed Size                  1218316 bytes

Variable Size              62916852 bytes

Database Buffers          100663296 bytes

Redo Buffers                2973696 bytes

Database mounted.

SQL>alter system set "_allow_resetlogs_corruption"=TRUE;

alter system set "_allow_resetlogs_corruption"=TRUE

                 *

ERROR at line 1:

ORA-02095: specified initialization parameter cannot be modified



SQL> alter system set "_allow_resetlogs_corruption"=TRUE scope=spfile;



System altered.



SQL>ho ls /opt/oracle/oradata/orcl/

control01.ctl  control03.ctl  sysaux01.dbf  undotbs01.dbf

control02.ctl  orapworcl      system01.dbf  users01.dbf



下面没有redo log file ,下面我将演算出redo log

SQL>startup force

ORACLE instance started.



Total System Global Area  167772160 bytes

Fixed Size                  1218316 bytes

Variable Size              62916852 bytes

Database Buffers          100663296 bytes

Redo Buffers                2973696 bytes

Database mounted.

ORA-01589: must use RESETLOGS or NORESETLOGS option for database open



SQL>alter database open resetlogs;



Database altered.

SQL> ho ls /opt/oracle/oradata/orcl/

control01.ctl  orapworcl   redo03.log    temp01.dbf

control02.ctl  redo01.log  sysaux01.dbf  undotbs01.dbf

control03.ctl  redo02.log  system01.dbf  users01.dbf



SQL>

好了到这里,非常高兴了,你已经成功的从只有rman备份文件中恢复了参数文件,控制文件,所有数据文件,日志文件了.



通常到这里还需要你全备数据库的哈,别忘了!


如果备份文件没有包含控制文件的备份,也就是只有数据文件如何恢复?
方法也比较简单.
1.建立密码文件,参数文件,数据存放目录,日志存放目录.
2.指定ORACLE_SID,然后通过dbms_backup_restore从备份中读出数据文件
3.建立控制文件
4.加日志参数后resetlogs生成日志文件
5.测试交易是否存在,并全备

具体步骤参看:
只有数据文件的备份如何恢复一例

阅读(4676) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~