CSDN博客

img cn_chenfeng

数据库恢复一例

发表于2004/9/17 16:54:00  973人阅读

分类: oracle技术

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

数据库为非归档状态,假如只有一周前的数据文件的备份,无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 file_name,tablespace_name from dba_data_files;

FILE_NAME                                          TABLESPACE_NAME
-------------------------------------------------- ------------------------------
/opt/oracle/db02/oradata/ORCL/system01.dbf         SYSTEM
/opt/oracle/db02/oradata/ORCL/tools01.dbf          TOOLS
/opt/oracle/db02/oradata/ORCL/rbs01.dbf              RBS
/opt/oracle/db02/oradata/ORCL/temp01.dbf           TEMP
/opt/oracle/db02/oradata/ORCL/users01.dbf          USERS
/opt/oracle/db02/oradata/ORCL/indx01.dbf           INDX
/opt/oracle/db02/oradata/ORCL/drsys01.dbf          DRSYS
/opt/oracle/db02/oradata/ORCL/test.dbf             TEST

8 rows selected.

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

确认数据文件的路径,并做物理冷备份:
$  tar  cvf   /backup/full.tar  /opt/oracle/db02/oradata/ORCL     /opt/oracle/db03/oradata/ORCL    /opt/oracle/db04/oradata/ORCL

模拟数据丢失:

删除当前所有的数据文件,控制文件和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

将做备份后的tar包解开,还原备份:

$tar xvf  /backup/full.tar

删除所有的控制文件和日志文件,只留下数据文件: 

$rm /opt/oracle/db02/oradata/ORCL/control01.ctl
$rm /opt/oracle/db03/oradata/ORCL/control02.ctl
$rm /opt/oracle/db04/oradata/ORCL/control03.ctl
$rm /opt/oracle/db02/oradata/ORCL/redo01.log
$rm /opt/oracle/db03/oradata/ORCL/red02.log
$rm /opt/oracle/db04/oradata/ORCL/red03.log

因为此时只有datafile, 无redofile和controlfile, 数据库只能启动到nomount状态:
SQL> startup nomount
ORACLE instance started.

Total System Global Area 1134141116 bytes
Fixed Size                   102076 bytes
Variable Size             311750656 bytes
Database Buffers          819200000 bytes
Redo Buffers                3088384 bytes

编辑udump目录下生成的orcl_ora_7140.trc文件,把里面的创建controlfile的那部分内容粘贴下来放在SQL里执行:
(这里要注意一定要用resetlogs方式重建控制文件,resetlogs之后会生成新的redolog,并且把当前redofile的sequence置为1,否则创建控制文件会失败):
SQL> CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS NOARCHIVELOG
   
MAXLOGFILES 32
    MAXLOGMEMBERS 2
    MAXDATAFILES 254
    MAXINSTANCES 8
    MAXLOGHISTORY 907
LOGFILE
  GROUP 1 '/opt/oracle/db02/oradata/ORCL/redo01.log'  SIZE 50000K,
  GROUP 2 '/opt/oracle/db03/oradata/ORCL/redo02.log'  SIZE 50000K,
  GROUP 3 '/opt/oracle/db04/oradata/ORCL/redo03.log'  SIZE 50000K
DATAFILE
  '/opt/oracle/db02/oradata/ORCL/system01.dbf',
  '/opt/oracle/db02/oradata/ORCL/tools01.dbf',
  '/opt/oracle/db02/oradata/ORCL/rbs01.dbf',
  '/opt/oracle/db02/oradata/ORCL/temp01.dbf',
  '/opt/oracle/db02/oradata/ORCL/users01.dbf',
  '/opt/oracle/db02/oradata/ORCL/indx01.dbf',
  '/opt/oracle/db02/oradata/ORCL/drsys01.dbf',
  '/opt/oracle/db02/oradata/ORCL/test.dbf',
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的状态,发现生成了新的redolog)
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

0 0

相关博文

我的热门文章

img
取 消
img