手工恢复

1、恢复过程查看的试图:

1)v$recovery_file:查看需要恢复的datafile

2)v$recovery_log:查看recover需要的redo日志

3)v$archived_log:查看已经归档的日志

2、手工完全恢复

实验一:所有数据文件和控制文件都丢失

1)先将控制文件dump到trace中

SQL> alter database backup controlfile to trace as '/u01/app/oracle/admin/EMREP/udump/haha.trc';

2)创建实验表

SQL> create table emp1 as select * from scott.emp;

插入数据提交并归档

SQL> insert into emp1 select * from scott.emp;
SQL> commit;
SQL> alter system archive log current;

插入数据只提交
SQL> insert into emp1 select * from scott.emp;
SQL> commit;

不提交不归档
SQL> insert into emp1 select * from scott.emp;

 

3)模拟断电,破会数据文件和控制文件

SQL> shutdown abort

[oracle@gc2 hot_bak]$ cd /u01/app/oracle/oradata/EMREP/
[oracle@gc2 EMREP]$ ls
control01.ctl  example01.dbf     redo01.log  sysaux01.dbf  undotbs01.dbf
control02.ctl  gguser.dbf        redo02.log  system01.dbf  users01.dbf
control03.ctl  goldengate01.dbf  redo03.log  temp01.dbf
[oracle@gc2 EMREP]$ rm *.dbf
[oracle@gc2 EMREP]$ rm *.ctl

 

4)启动数据库失败

SQL> startup
ORACLE instance started.
Total System Global Area  608174080 bytes
Fixed Size                  1220844 bytes
Variable Size             197136148 bytes
Database Buffers          406847488 bytes
Redo Buffers                2969600 bytes
ORA-00205: error in identifying control file, check alert log for more info

 

5)恢复解决:

(1)重建控制文件,因为日志没有丢失,所以这里用NORESETLOGS

[oracle@gc2 udump]$ more haha.trc

CREATE CONTROLFILE REUSE DATABASE "EMREP" NORESETLOGS FORCE LOGGING ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u01/app/oracle/oradata/EMREP/redo01.log'  SIZE 50M,
  GROUP 2 '/u01/app/oracle/oradata/EMREP/redo02.log'  SIZE 50M,
  GROUP 3 '/u01/app/oracle/oradata/EMREP/redo03.log'  SIZE 50M
-- STANDBY LOGFILE

DATAFILE
  '/u01/app/oracle/oradata/EMREP/system01.dbf',
  '/u01/app/oracle/oradata/EMREP/undotbs01.dbf',
  '/u01/app/oracle/oradata/EMREP/sysaux01.dbf',
  '/u01/app/oracle/oradata/EMREP/users01.dbf',
  '/u01/app/oracle/oradata/EMREP/example01.dbf',
  '/u01/app/oracle/oradata/EMREP/goldengate01.dbf',
  '/u01/app/oracle/oradata/EMREP/gguser.dbf'
CHARACTER SET WE8ISO8859P1
;

重建报错,我们需要先转储备份的数据文件

[oracle@gc2 hot_bak]$ cp * /u01/app/oracle/oradata/EMREP/

[oracle@gc2 hot_bak]$ cp control01.ctl /u01/app/oracle/oradata/EMREP/control01.ctl
[oracle@gc2 hot_bak]$ cp control01.ctl /u01/app/oracle/oradata/EMREP/control02.ctl
[oracle@gc2 hot_bak]$ cp control01.ctl /u01/app/oracle/oradata/EMREP/control03.ctl

再次重建成功;

查看scn号发现不一致

SQL> select file#,checkpoint_change# from v$datafile;
         1             998993
         2             998993
         3             998993
         4             998993
         5             998993
         6             998993
         7             998993
SQL> select file#,checkpoint_change# from v$datafile_header;
         1             998253
         2             998289
         3             998313
         4             998340
         5             998360
         6             998384
         7             998410

需要恢复数据库

SQL> recover database;
Media recovery complete.
SQL> alter database open;

SQL> select count(*) from emp1;
        42

数据恢复到最后一次提交。

 

实验二:只有数据文件丢失了

1)创建实验环境

SQL> create table emp2 as select * from scott.emp;
SQL> insert into emp2 select * from scott.emp;
SQL> commit;
SQL> alter system archive log current;
SQL> insert into emp2 select * from scott.emp;
SQL> commit;
SQL> insert into emp2 select * from scott.emp;
SQL> select count(*) from emp2;
        56

 

2)模拟断电,破坏试验

SQL> shutdown abort
ORACLE instance shut down.

删除所有的数据文件

[oracle@gc2 EMREP]$ ls
control01.ctl  example01.dbf     redo01.log  sysaux01.dbf   users01.dbf
control02.ctl  gguser.dbf        redo02.log  system01.dbf
control03.ctl  goldengate01.dbf  redo03.log  undotbs01.dbf
[oracle@gc2 EMREP]$ rm *.dbf

3)启动失败

SQL> startup
ORACLE instance started.
Total System Global Area  608174080 bytes
Fixed Size                  1220844 bytes
Variable Size             197136148 bytes
Database Buffers          406847488 bytes
Redo Buffers                2969600 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/app/oracle/oradata/EMREP/system01.dbf'

查看需要恢复的数据文件

SQL> select file#,error from v$recover_file;
         1 FILE NOT FOUND
         2 FILE NOT FOUND
         3 FILE NOT FOUND
         4 FILE NOT FOUND
         5 FILE NOT FOUND
         6 FILE NOT FOUND
         7 FILE NOT FOUND

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

         1 /u01/app/oracle/oradata/EMREP/system01.dbf
         2 /u01/app/oracle/oradata/EMREP/undotbs01.dbf
         3 /u01/app/oracle/oradata/EMREP/sysaux01.dbf
         4 /u01/app/oracle/oradata/EMREP/users01.dbf
         5 /u01/app/oracle/oradata/EMREP/example01.dbf
         6 /u01/app/oracle/oradata/EMREP/goldengate01.dbf
         7 /u01/app/oracle/oradata/EMREP/gguser.dbf

转储备份:

[oracle@gc2 hot_bak]$ cp *.dbf /u01/app/oracle/oradata/EMREP/

恢复:

SQL> recover database;
ORA-00279: change 998253 generated at 07/27/2014 13:20:11 needed for thread 1
ORA-00289: suggestion : /home/oracle/EMREP/1_23_839513627.dbf
ORA-00280: change 998253 for thread 1 is in sequence #23


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto            ---让系统自己找需要的日志
Log applied.
Media recovery complete.
SQL> alter database open;
SQL> select count(*) from emp2;
        42

数据恢复到最后一次的提交。

你可能感兴趣的:(不完全恢复,手工恢复,完全恢复,重建控制文件)