Chinaunix首页 | 论坛 | 博客
  • 博客访问: 18670436
  • 博文数量: 7460
  • 博客积分: 10434
  • 博客等级: 上将
  • 技术积分: 78178
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-02 22:54
文章分类

全部博文(7460)

文章存档

2011年(1)

2009年(669)

2008年(6790)

分类: 数据库开发技术

2008-05-28 09:00:20

最近通过做实验总结出一种数据库恢复方法,对今后的工作很有帮助:

数据库为非归档状态,只有一周前的数据文件的备份,无redolog,归档日志和controlfile的备份,此种情况一但数据库出故障只能做不完全恢复,会丢失一周前做备份时到出故障那一时候的所有数据,具体恢复方法如下:

操作系统为solaris8,内存2G,2颗CPU.

实验步骤:
$sqlplus /nolog
SQL>connect / as sysdba
SQL> archive log list
Database log mode No Archive Mode
Automatic archival Enabled
Archive destination /opt/oracle/arch/ORCL
Oldest online log sequence 895
Current log sequence 897

SQL> select * from v$logfile;

GROUP# STATUS
---------- -------
MEMBER
--------------------------------------------------------------------------------
3
/opt/oracle/db04/oradata/ORCL/redo03.log

2
/opt/oracle/db03/oradata/ORCL/redo02.log

1
/opt/oracle/db02/oradata/ORCL/redo01.log

SQL> select * from v$controlfile;

STATUS
-------
NAME
--------------------------------------------------------------------------------

/opt/oracle/db02/oradata/ORCL/control01.ctl


/opt/oracle/db03/oradata/ORCL/control02.ctl


/opt/oracle/db04/oradata/ORCL/control03.ctl

SQL>alter database backup controlfile to trace;
(备份控制文件,此时会在$ORACLE_BASE/admin/ORCL/udump目录里生成trace文件)

SQL> shutdown immediate (关闭当前数据库)
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> quit
Disconnected

模拟数据丢失:

删除当前所有的数据文件,控制文件和redolog文件:

$rm -rf ?/opt/oracle/db02/oradata/ORCL/*

$rm /opt/oracle/db03/oradata/ORCL/redo02.log

$rm /opt/oracle/db03/oradata/ORCL/control02.ctl

$rm /opt/oracle/db04/oradata/ORCL/redo03.log

$rm /opt/oracle/db04/oradata/ORCL/control03.ctl

把一周前备份的数据文件copy回来,目录结构和以前一样,但这时因为没有redolog和controlfile文件,数据库只能启动到nomount状态:

编辑udump目录下生成的orcl_ora_7140.trc文件,把里面的创建controlfile的那部分内容粘贴下来放在SQL里执行:
(这里要注意一定要用resetlogs方式重建控制文件,resetlogs之后会生成新的redolog,并且把当前redofile的sequence置为1,否则创建控制文件会失败):
SQL>STARTUP NOMOUNT
SQL> CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS NOARCHIVELOG
2 MAXLOGFILES 32
3 MAXLOGMEMBERS 2
4 MAXDATAFILES 254
5 MAXINSTANCES 8
6 MAXLOGHISTORY 907
7 LOGFILE
8 GROUP 1 '/opt/oracle/db02/oradata/ORCL/redo01.log' SIZE 50000K,
9 GROUP 2 '/opt/oracle/db03/oradata/ORCL/redo02.log' SIZE 50000K,
10 GROUP 3 '/opt/oracle/db04/oradata/ORCL/redo03.log' SIZE 50000K
11 DATAFILE
12 '/opt/oracle/db02/oradata/ORCL/system01.dbf',
13 '/opt/oracle/db02/oradata/ORCL/tools01.dbf',
14 '/opt/oracle/db02/oradata/ORCL/rbs01.dbf',
15 '/opt/oracle/db02/oradata/ORCL/temp01.dbf',
16 '/opt/oracle/db02/oradata/ORCL/users01.dbf',
17 '/opt/oracle/db02/oradata/ORCL/indx01.dbf',
18 '/opt/oracle/db02/oradata/ORCL/drsys01.dbf',
19 '/opt/oracle/db02/oradata/ORCL/wacos.dbf',
20 '/opt/oracle/db02/oradata/ORCL/wacos01.dbf',
21 '/opt/oracle/db02/oradata/ORCL/wacos02.dbf',
22 '/opt/oracle/db02/oradata/ORCL/wacos03.dbf',
23 '/opt/oracle/db02/oradata/ORCL/wacos04.dbf',
24 '/opt/oracle/db02/oradata/ORCL/wacos05.dbf',
25 '/opt/oracle/db02/oradata/ORCL/wacos06.dbf',
26 '/opt/oracle/db02/oradata/ORCL/nms.dbf',
27 '/opt/oracle/db02/oradata/ORCL/test.dbf'
28 CHARACTER SET WE8ISO8859P1;

Control file created.

SQL> alter database open resetlogs;(以resetlogs方式打开数据库)
Database altered.

SQL> select status from v$instance; (检查数据库的状态)
STATUS
-------
OPEN

SQL> select * from v$logfile; (检查logfile的状态)
GROUP# STATUS
---------- -------
MEMBER
--------------------------------------------------------------------------------
3
/opt/oracle/db04/oradata/ORCL/redo03.log

2
/opt/oracle/db03/oradata/ORCL/redo02.log

1
/opt/oracle/db02/oradata/ORCL/redo01.log


SQL> select * from v$controlfile; (检查控制文件的状态)

STATUS
-------
NAME
--------------------------------------------------------------------------------

/opt/oracle/db02/oradata/ORCL/control01.ctl


/opt/oracle/db03/oradata/ORCL/control02.ctl


/opt/oracle/db04/oradata/ORCL/control03.ctl

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