gdufo

 

Rman全备份不完全恢复数据库

数据库今天宕机了,数据文件和控制文件在一个磁盘,全部损坏,redo文件和

 

归档日志在两外一个磁盘,完好无损,只有两天前的rman全备份。经过30分钟的奋战,数据全部恢复。

 

模拟环境,具体恢复如下:

 

1:首先用rman全备份数据库数据(模拟两天前的rman全备份)

 

[oracle@www oracle]$ rman target /

 

Recovery Manager: Release 9.2.0.8.0 - Production

 

Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.

 

connected to target database: EXITGOGO (DBID=267967027)

 


RMAN> backup database;

 

Starting backup at 23-11-06

 

using target database controlfile instead of recovery catalog

 

allocated channel: ORA_DISK_1

 

channel ORA_DISK_1: sid=11 devtype=DISK

 

channel ORA_DISK_1: starting full datafile backupset

 

channel ORA_DISK_1: specifying datafile(s) in backupset

 

input datafile fno=00001 name=/free/oracle/oradata/exitgogo/system01.dbf

 

input datafile fno=00002 name=/free/oracle/oradata/exitgogo/undotbs01.dbf

 

input datafile fno=00003 name=/free/oracle/oradata/exitgogo/users01.dbf

 

input datafile fno=00006 name=/free/oracle/oradata/exitgogo/pub.dbf

 

input datafile fno=00004 name=/free/oracle/oradata/exitgogo/tools01.dbf

 

input datafile fno=00005 name=/free/oracle/oradata/exitgogo/indx01.dbf

 

channel ORA_DISK_1: starting piece 1 at 23-11-06

 

channel ORA_DISK_1: finished piece 1 at 23-11-06

 

piece handle=/free/oracle/product/9.2.0.8/dbs/03i34pja_1_1 comment=NONE

 

channel ORA_DISK_1: backup set complete, elapsed time: 00:01:06

 

Finished backup at 23-11-06

 


Starting Control File Autobackup at 23-11-06

 

piece handle=/free/oracle/orabak/c-267967027-20061123-01 comment=NONE

 

Finished Control File Autobackup at 23-11-06

 


RMAN> show all;

 

RMAN configuration parameters are:

 

CONFIGURE RETENTION POLICY TO REDUNDANCY 2;

 

CONFIGURE BACKUP OPTIMIZATION ON;

 

CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default

 

CONFIGURE CONTROLFILE AUTOBACKUP ON;

 

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/free/oracle/orabak/%F';

 

CONFIGURE DEVICE TYPE DISK PARALLELISM 1;

 

CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

 

CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

 

RMAN configuration has no stored or default parameters

 

CONFIGURE MAXSETSIZE TO UNLIMITED; # default

 

CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/free/oracle/product/9.2.0.8/dbs/snapcf_exitgogo.f'; # default

 


RMAN>quit

 

2:创建一个新的表空间,然后添加测试数据(模拟两天之间数据库的变化)

 


创建了一个新的表空间pub,然后创建了用户pub

 

[oracle@www oracle]$ sqlplus  pub/pub

 

SQL*Plus: Release 9.2.0.8.0 - Production on 星期四 11 23 17:37:28 2006

 

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

 

Connected to:

 

Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production

 

With the Partitioning and Oracle Data Mining options

 

JServer Release 9.2.0.8.0 – Production

 

添加一点测试数据:

 

SQL> create table gaojf1 as  select * from all_objects;

 

Table created.

 

SQL> insert into gaojf1 select * from gaojf1;

 

5884 rows created.

 

SQL> /

 

11768 rows created.

 

SQL> /

 

。。。。。。。。。。。

 

188288 rows created.

 


SQL> /

 

376576 rows created.

 

SQL> commit;

 

Commit complete.

 

SQL> quit

 

Disconnected from Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production

 

With the Partitioning and Oracle Data Mining options

 

JServer Release 9.2.0.8.0 - Production

 


3:删除所有数据文件和控制文件(模拟数据库宕机)

 

[oracle@www exitgogo]$ls -sh

 

total 886M

 

3.5M control01.ctl   33M indx01.dbf   51M redo02.log    136K temp01.dbf     129M users01.dbf 3.5M control02.ctl  101M pub.dbf      51M redo03.log     65M tools01.dbf 3.5M control03.ctl   51M redo01.log  201M system01.dbf  201M undotbs01.dbf

 

[oracle@www exitgogo]$  rm -rf ./*.dbf ./*.ctl

 

[oracle@www exitgogo]$ ls

 

redo01.log  redo02.log  redo03.log

 


4:恢复开始:

 

[oracle@www exitgogo]$ rman target /

 

Recovery Manager: Release 9.2.0.8.0 - Production

 

Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.

 

connected to target database (not started)

 

RMAN> startup nomount

 

Oracle instance started

 

Total System Global Area     235999648 bytes

 

Fixed Size                      450976 bytes

 

Variable Size                201326592 bytes

 

Database Buffers              33554432 bytes

 

Redo Buffers                    667648 bytes

 


首先从原来的全备份中恢复控制文件

 

RMAN>

 

restore controlfile from '/free/oracle/orabak/c-267967027-20061123-01';

 


Starting restore at 23-11-06

 

using target database controlfile instead of recovery catalog

 

allocated channel: ORA_DISK_1

 

channel ORA_DISK_1: sid=13 devtype=DISK

 

channel ORA_DISK_1: restoring controlfile

 

channel ORA_DISK_1: restore complete

 

replicating controlfile

 

input filename=/free/oracle/oradata/exitgogo/control01.ctl

 

output filename=/free/oracle/oradata/exitgogo/control02.ctl

 

output filename=/free/oracle/oradata/exitgogo/control03.ctl

 

Finished restore at 23-11-06

 

RMAN> alter database mount;

 

database mounted

 

RMAN> list backup;

 

List of Backup Sets

 

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

 


BS Key  Type LV Size       Device Type Elapsed Time Completion Time

 

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

 

1       Full    3M         DISK        00:00:00     23-11-06    

 

        BP Key: 1   Status: AVAILABLE   Tag:

 

        Piece Name: /free/oracle/orabak/c-267967027-20061123-01

 

  Controlfile Included: Ckp SCN: 73561        Ckp time: 23-11-06

 


BS Key  Type LV Size       Device Type Elapsed Time Completion Time

 

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

 

2       Full    223M       DISK        00:00:57     23-11-06    

 

        BP Key: 2   Status: AVAILABLE   Tag: TAG20061123T173423

 

        Piece Name: /free/oracle/product/9.2.0.8/dbs/03i34p90_1_1

 

  List of Datafiles in backup set 2

 

  File LV Type Ckp SCN    Ckp Time   Name

 

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

 

  1       Full 73688      23-11-06 /free/oracle/oradata/exitgogo/system01.dbf

 

  2       Full 73688      23-11-06 /free/oracle/oradata/exitgogo/undotbs01.dbf

 

  3       Full 73688      23-11-06 /free/oracle/oradata/exitgogo/users01.dbf

 

  4       Full 73688      23-11-06 /free/oracle/oradata/exitgogo/tools01.dbf

 

  5       Full 73688      23-11-06 /free/oracle/oradata/exitgogo/indx01.dbf

 



还原数据文件

 

RMAN> restore database;

 

Starting restore at 23-11-06

 


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 /free/oracle/oradata/exitgogo/system01.dbf

 

restoring datafile 00002 to /free/oracle/oradata/exitgogo/undotbs01.dbf

 

restoring datafile 00003 to /free/oracle/oradata/exitgogo/users01.dbf

 

restoring datafile 00004 to /free/oracle/oradata/exitgogo/tools01.dbf

 

restoring datafile 00005 to /free/oracle/oradata/exitgogo/indx01.dbf

 

channel ORA_DISK_1: restored backup piece 1

 

piece handle=/free/oracle/product/9.2.0.8/dbs/03i34p90_1_1 tag=TAG20061123T173423 params=NULL

 

channel ORA_DISK_1: restore complete

 

Finished restore at 23-11-06

 

RMAN> quit

 


下面进入sqlplus进行不完全恢复

 


[oracle@www exitgogo]$ sqlplus  "/as sysdba"

 


SQL*Plus: Release 9.2.0.8.0 - Production on 星期四 11 23 17:51:07 2006

 

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

 

Connected to:

 

Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production

 

With the Partitioning and Oracle Data Mining options

 

JServer Release 9.2.0.8.0 - Production

 

SQL> select name from v$datafile;

 

NAME

 

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

 

/free/oracle/oradata/exitgogo/system01.dbf

 

/free/oracle/oradata/exitgogo/undotbs01.dbf

 

/free/oracle/oradata/exitgogo/users01.dbf

 

/free/oracle/oradata/exitgogo/tools01.dbf

 

/free/oracle/oradata/exitgogo/indx01.dbf

 


可以看到,由于rman的全备份早于创建pub表空间,因此restore恢复中没有记录pub表空间的信息,但是由于redo file中还记录了pub表空间创建的信息,因此,先recover试试!

 


SQL> recover database using backup controlfile;

 

ORA-00279: change 73688 generated at 11/23/2006 17:34:24 needed for thread 1

 

ORA-00289: suggestion :

 

/free/oracle/product/9.2.0.8/dbs/archexitgogo/T0001S0000000008.ARC

 

ORA-00280: change 73688 for thread 1 is in sequence #8

 

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

 

auto

 

ORA-00283: recovery session canceled due to errors

 

ORA-01244: unnamed datafile(s) added to controlfile by media recovery

 

ORA-01110: data file 6: '/free/oracle/oradata/exitgogo/pub.dbf'

 

ORA-01112: media recovery not started

 


可以看到,在恢复了一个归档日志以后,oracle认出了pub表空间,同时提示了ORA-01244 错误,继续往下看:

 

 

 

SQL> select name from v$datafile;

 

NAME

 

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

 

/free/oracle/oradata/exitgogo/system01.dbf

 

/free/oracle/oradata/exitgogo/undotbs01.dbf

 

/free/oracle/oradata/exitgogo/users01.dbf

 

/free/oracle/oradata/exitgogo/tools01.dbf

 

/free/oracle/oradata/exitgogo/indx01.dbf

 

/free/oracle/product/9.2.0.8/dbs/UNNAMED00006

 

 

6 rows selected.

 

 

可以看到,oracle中莫名的多出了一个文件UNNAMED00006,

 

IXDBA.NET社区论坛

出现这个文件的原因是由于redo file中记录了pub的信息,在通过recover恢复后,系统也认到了有pub这个表空间的存在,但是由于控制文件中没有记录这个文件的信息,所以oracle抛了一个错误,说发现一个没有命名的文件,然后oracle系统本身给这个文件做了一个命名。

 

 

可以通过下面的方式把pub表空间数据文件移动到合适的位置。

 

 

SQL>

 

alter database create datafile 6 as '/free/oracle/oradata/exitgogo/pub.dbf';

 

Database altered.

 

SQL> col name format a40

 

SQL>  select file#,name from v$datafile;

 

 

     FILE# NAME

 

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

 

         1 /free/oracle/oradata/exitgogo/system01.d bf

 

         2 /free/oracle/oradata/exitgogo/undotbs01.dbf

 

         3 /free/oracle/oradata/exitgogo/users01.dbf

 

         4 /free/oracle/oradata/exitgogo/tools01.dbf

 

     FILE# NAME

 

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

 

         5 /free/oracle/oradata/exitgogo/indx01.dbf

 

         6 /free/oracle/oradata/exitgogo/pub.dbf

 

6 rows selected.

 

 

继续恢复:

 

SQL> recover database using backup controlfile;

 

ORA-00279: change 73805 generated at 11/23/2006 17:37:18 needed for thread 1

 

ORA-00289: suggestion :

 

/free/oracle/product/9.2.0.8/dbs/archexitgogo/T0001S0000000008.ARC

 

ORA-00280: change 73805 for thread 1 is in sequence #8

 

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

 

auto

 

ORA-00279: change 74363 generated at 11/23/2006 17:38:51 needed for thread 1

 

ORA-00289: suggestion :

 

/free/oracle/product/9.2.0.8/dbs/archexitgogo/T0001S0000000009.ARC

 

ORA-00280: change 74363 for thread 1 is in sequence #9

 

ORA-00278: log file

 

'/free/oracle/product/9.2.0.8/dbs/archexitgogo/T0001S0000000008.ARC' no longer

 

needed for this recovery

 

 

ORA-00308: cannot open archived log

 

'/free/oracle/product/9.2.0.8/dbs/archexitgogo/T0001S0000000009.ARC'

 

ORA-27037: unable to obtain file status

 

Linux Error: 2: No such file or directory

 

Additional information: 3

 

由于我的归档没有T0001S0000000009了,所以可能需要redo file了

 

SQL> recover database using backup controlfile;

 

ORA-00279: change 74363 generated at 11/23/2006 17:38:51 needed for thread 1

 

ORA-00289: suggestion :

 

/free/oracle/product/9.2.0.8/dbs/archexitgogo/T0001S0000000009.ARC

 

ORA-00280: change 74363 for thread 1 is in sequence #9

 

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

 

/free/oracle/oradata/exitgogo/redo01.log

 

ORA-00310: archived log contains sequence 7; sequence 9 required

 

ORA-00334: archived log: '/free/oracle/oradata/exitgogo/redo01.log'

 

 

SQL> recover database using backup controlfile;

 

ORA-00279: change 74363 generated at 11/23/2006 17:38:51 needed for thread 1

 

ORA-00289: suggestion :

 

/free/oracle/product/9.2.0.8/dbs/archexitgogo/T0001S0000000009.ARC

 

ORA-00280: change 74363 for thread 1 is in sequence #9

 

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

 

/free/oracle/oradata/exitgogo/redo02.log

 

ORA-00310: archived log contains sequence 8; sequence 9 required

 

ORA-00334: archived log: '/free/oracle/oradata/exitgogo/redo02.log'

 

 

SQL> recover database using backup controlfile;

 

ORA-00279: change 74363 generated at 11/23/2006 17:38:51 needed for thread 1

 

ORA-00289: suggestion :

 

/free/oracle/product/9.2.0.8/dbs/archexitgogo/T0001S0000000009.ARC

 

ORA-00280: change 74363 for thread 1 is in sequence #9

 

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

 

/free/oracle/oradata/exitgogo/redo03.log

 

Log applied.

 

Media recovery complete.

 

可以看到,新建的pub表空间的数据信息在redo03.log中存在,这是因为我的测试数据量很小的原因。如果从rman全备份后到系统宕机这段时间数据量很大的话,可能有很多的归档信息需要恢复,同时redo file也是不可少的。

 

SQL> alter database open resetlogs;

 

alter database open resetlogs

 

*

 

ERROR at line 1:

 

ORA-01153: an incompatible media recovery is active

 

SQL> quit

 

Disconnected from Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production

 

With the Partitioning and Oracle Data Mining options

 

JServer Release 9.2.0.8.0 - Production

 

[oracle@www exitgogo]$ sqlplus  "/as sysdba"

 

SQL*Plus: Release 9.2.0.8.0 - Production on 星期四 11 23 18:02:00 2006

 

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

 

Connected to:

 

Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production

 

With the Partitioning and Oracle Data Mining options

 

JServer Release 9.2.0.8.0 - Production

 

SQL> alter database open resetlogs;

 

Database altered.

 

SQL> conn pub/pub

 

Connected.

 

SQL> select count(*) from gaojf1;

 

  COUNT(*)

 

----------

 

    753152

 

SQL>

 

可以看到,数据完全恢复,

 

 

这样恢复完成后,马上又做了一个全库的rman备份。

posted on 2009-12-01 09:58 gdufo 阅读(1458) 评论(0)  编辑  收藏 所属分类: Database (oracle, sqlser,MYSQL)

导航

统计

常用链接

留言簿(6)

随笔分类

随笔档案

文章分类

文章档案

收藏夹

Hibernate

友情链接

搜索

最新评论

阅读排行榜

评论排行榜