关闭

Oracle恢复实验笔记

479人阅读 评论(0) 收藏 举报

系统 win2000 pro   备份恢复的实验 整理

 用户管理的
准备工作:

做备份恢复时,把undo改小一点
SQL>CREATE UNDO TABLESPACE undo1
DATAFILE 'D:/oracle/oradata/a00215/undo01.dbf'
SIZE 4M AUTOEXTEND ON;
SQL>ALTER SYSTEM SET UNDO_TABLESPACE=UNDO1;
SQL>DROP TABLESPACE UNDOTBS1;

1) SQL> create pfile from spfile;
2) shutdown immediate
3) 用写字板打开initSID.ora 编辑这个静态参数文件
 加三行代码
 *.log_archive_start=true
 *.log_archive_dest='D:/oracle/oradata/archive00/'
 *.log_archive_format='awu%s.arc'
   OS保存
4) SQL> create spfile from pfile;
5) SQL> startup mount
6) SQL> alter database archivelog
7) SQL> alter database open;
8) SQL> archive log list;
9)  创建scott用户,供实验用
SQL> @D:/oracle/ora92/rdbms/admin/scott.sql 
10) SQL> shutdown immediate
11) 做一个完全的冷备份,OS下,将文件(e.g. D:/oracle/oradata/a00215/...) 复制出 (我这里是到D:/oracle/oradata/backup00/...)

完全恢复
1.1.1   lab1
描述:
数据库关闭状态,需要恢复System datafiles,Undo segment datafiles,Whole database
在这里,我们给scott用户创建一个表,然后破坏undo,恢复后,看看表中的数据还在不在

1) SQL>  conn sys/oracle as sysdba
   SQL> startup
2) SQL> create table scott.com1(n1 number);
   SQL> insert into scott.com1 values(1);
   SQL> commit;
   SQL> alter system switch logfile;
   SQL> insert into scott.com1 values(2);
   SQL> shutdown abort
3) 此时,把undo破坏
   在‘服务‘中,将OracleServiceA00215停止
    删除(OS)undo文件
4) 在‘服务‘中,将OracleServiceA00215启动
5) conn / as sysdba
startup
ORACLE 例程已经启动。
Total System Global Area  135338868 bytes
Fixed Size                   453492 bytes
Variable Size             109051904 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes
数据库装载完毕。
ORA-01157: 无法标识/锁定数据文件 9 - 请参阅 DBWR 跟踪文件
ORA-01110: 数据文件 9: 'D:/ORACLE/ORADATA/A00215/UNDO01.DBF'

(不发的话,可以看警告日志D:/oracle/admin/a00215/bdump/alert_a00215.log,
Sat Sep 25 14:18:18 2004
Errors in file d:/oracle/admin/a00215/bdump/a00215_dbw0_1552.trc:
ORA-01157: cannot identify/lock data file 9 - see DBWR trace file
ORA-01110: data file 9: 'D:/ORACLE/ORADATA/A00215/UNDO01.DBF'
ORA-27041: unable to open file
OSD-04002: 无法打开文件
O/S-Error: (OS 2) 系统找不到指定的文件。)

6) 恢复:
SQL> SHUTDOWN ABORT
将备份的undo01.dbf copy回去
SQL> STARTUP MOUNT
SQL> recover database(或者recover datafile 9//或者 recover'D:/ORACLE/ORADATA/A00215/UNDO01.DBF')

SQL> select * from scott.com1;

        N1
----------
         1

1.1.2  lab2
描述
数据库打开的时候,并且恢复的时候数据库也开启,此时受损的文件不能是system或者undo文件

如下操作,都在数据库open时进行                                                               
1) SQL> create table scott.com2 (n1 number) tablespace users;                                
   SQL> insert into scott.com2 values(1);                                                    
   SQL> commit;                                                                              
   SQL> alter system switch logfile;                                                         
                                                                                             
2) 破坏users01.dbf (users 表空间)                                                            
   我这里采取的办法是先将users 表空间offline,再造一个同名(0字节)的覆盖,也可以采取其他办法。
 
3)恢复
alter tablespace users offline immediate;

此时 select * from scott.com2;
报错:
ERROR 位于第 1 行:
ORA-00376: 此时无法读取文件 7
ORA-01110: 数据文件 7: 'D:/ORACLE/ORADATA/A00215/USERS01.DBF'

OS将备份的users01.dbf copy回去

SQL> recover tablespace users
SQL> alter tablespace users online;
SQL>  select * from scott.com2;
        N1
----------
         1
        
1.1.3  lab3
描述
和实验二类似,不同之处在于数据库损坏时为关闭状态,此时受损的文件不能是system或者undo文件
1)数据库关闭时,删除users01.dbf
恢复
2)SQL> conn / as sysdba
   SQL> startup
报错
ORA-01157: 无法标识/锁定数据文件 7 - 请参阅 DBWR 跟踪文件
ORA-01110: 数据文件 7: 'D:/ORACLE/ORADATA/A00215/USERS01.DBF'

OS将备份的users01.dbf copy回去
SQL> alter tablespace users offline immediate;
SQL> alter database open
SQL> alter tablespace users online;
SQL>  select * from scott.com2;
        N1
----------
         1
        
1.1.4  lab4
没有备份的情况下,恢复一个数据文件,不能是system或者undo段

准备
SQL> create tablespace testtbs datafile 'D:/oracle/oradata/a00215/testtbs.dbf' size 1m;
SQL> alter system switch logfile;
SQL> create table scott.com4 (n1 number) tablespace testtbs;
SQL>  alter system switch logfile;
SQL> insert into scott.com4 values(1);
SQL> commit;
SQL>  alter system switch logfile;

搞坏 testtbs.dbf
  我这里采取的办法是先将testtbs 表空间offline,然后把这个重命名。


SQL> select * from scott.com4;
select * from scott.com4
                    *
ERROR 位于第 1 行:
ORA-00376: 此时无法读取文件 2
ORA-01110: 数据文件 2: 'D:/ORACLE/ORADATA/A00215/TESTTBS.DBF'

恢复


再造一个文件
SQL> ALTER DATABASE CREATE DATAFILE
  2   'D:/oracle/oradata/a00215/testtbs.dbf';
 
SQL> recover tablespace testtbs
SQL> alter tablespace testtbs online;
SQL>  select * from scott.com4;

        N1
----------
         1
        
        
不完全恢复
做不完全恢复时,做实验前都要把数据库给备份一下

1.2.1 lab5
基于时间的恢复

SQL> select * from scott.emp;

EMPNO ENAME      JOB         MGR HIREDATE          SAL      COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
 7369 SMITH      CLERK      7902 1980-12-17     800.00               20
 7499 ALLEN      SALESMAN   7698 1981-2-20     1600.00    300.00     30
 7521 WARD       SALESMAN   7698 1981-2-22     1250.00    500.00     30
 7566 JONES      MANAGER    7839 1981-4-2      2975.00               20
 7654 MARTIN     SALESMAN   7698 1981-9-28     1250.00   1400.00     30
 7698 BLAKE      MANAGER    7839 1981-5-1      2850.00               30
 7782 CLARK      MANAGER    7839 1981-6-9      2450.00               10
 7839 KING       PRESIDENT       1981-11-17    5000.00               10
 7844 TURNER     SALESMAN   7698 1981-9-8      1500.00      0.00     30
 7900 JAMES      CLERK      7698 1981-12-3      950.00               30
 7902 FORD       ANALYST    7566 1981-12-3     3000.00               20
 7934 MILLER     CLERK      7782 1982-1-23     1300.00               10
   
The current time is 12:00 p.m. on March 9, 2002.
The EMPLOYEES table has been dropped.
The table was dropped at approximately 11:45 a.m.
Database activity is minimal because most staff are currently in a meeting.
The table must be recovered.

为了模拟这个场景,我们将数据库恢复到删除emp表之前的样子
1)
SQL> select * from scott.com1;

        N1
----------
         1
取现在的系统时间
SQL> select to_char(sysdate,'yyyy-mm-dd:hh24:mi:ss') from dual;

2004-09-25:16:10:24
2)
删除emp表

SQL> drop table scott.emp 
SQL> insert into scott.com1 values(2);
SQL> commit;
SQL> alter system switch logfile;

在2004-09-25:16:10:24之后,又在scott.com1 中插入 数字 2

SQL> select * from scott.com1;

        N1
----------
         1
         2

恢复     
SQL> shutdown immediate

OS 中将所有的数据文件拿回来(除了control file 和redo log file)

SQL> startup mount
SQL> recover database until time '2004-09-25:16:10:24'
ORA-00279: 更改 226776 (在 09/25/2004 15:51:01 生成) 对于线程 1 是必需的
ORA-00289: 建议: D:/ORACLE/ORADATA/ARCHIVE00/AWU706.ARC
ORA-00280: 更改 226776 对于线程 1 是按序列 # 706 进行的


指定日志: {<RET>=suggested | filename | AUTO | CANCEL}
auto
已应用的日志。
完成介质恢复。

数据库恢复到2004-09-25:16:10:24的样子,为了使数据文件和redo log以及control file同步,必须重新reset日志。
SQL> alter database open resetlogs;

SQL> select * from scott.emp;

EMPNO ENAME      JOB         MGR HIREDATE          SAL      COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
 7369 SMITH      CLERK      7902 1980-12-17     800.00               20
 7499 ALLEN      SALESMAN   7698 1981-2-20     1600.00    300.00     30
 7521 WARD       SALESMAN   7698 1981-2-22     1250.00    500.00     30
 7566 JONES      MANAGER    7839 1981-4-2      2975.00               20
 7654 MARTIN     SALESMAN   7698 1981-9-28     1250.00   1400.00     30
 7698 BLAKE      MANAGER    7839 1981-5-1      2850.00               30
 7782 CLARK      MANAGER    7839 1981-6-9      2450.00               10
 7839 KING       PRESIDENT       1981-11-17    5000.00               10
 7844 TURNER     SALESMAN   7698 1981-9-8      1500.00      0.00     30
 7900 JAMES      CLERK      7698 1981-12-3      950.00               30
 7902 FORD       ANALYST    7566 1981-12-3     3000.00               20
 7934 MILLER     CLERK      7782 1982-1-23     1300.00               10
 
 emp表恢复了
 
 SQL> select * from scott.com1;

        N1
----------
         1
 
在2004-09-25:16:10:24之后,又在scott.com1 中插入的数字 2被丢失

1.2.2 lab6
Cancel-based recovery:用cancel代替归档日志名的输入。可以恢复到具体的某一个归档日志
Scenario:
The current time is 12:00 p.m. on March 9,2002.
The EMPLOYEES table was dropped while someone was trying to fix bad blocks.
Log files exist on the same disk.
The table was dropped at approximately 11:45 a.m.
Staff are currently in a meeting.

简单的说,就是当前的redo log 坏了

准备
SQL> create table scott.test1(n1 number);
SQL> insert into scott.test1 values(1);
SQL> insert into scott.test1 values(2);
SQL> commit;
SQL> alter system switch logfile;
SQL> insert into scott.test1 values(3);
SQL> insert into scott.test1 values(4);
SQL> commit;
SQL> select * from v$log;
    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME        
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- -------------------
         1          1          1    1048576          1 YES INACTIVE                247234 2004-09-25:16:24:03
         2          1          2    1048576          1 YES ACTIVE                  267451 2004-09-25:17:00:56
         3          1          3    1048576          1 NO  CURRENT                 267609 2004-09-25:17:02:27


SQL> shutdown abort

三号组为当前日志,可将其删除或者重命名


恢复
OS 中将所有的数据文件拿回来(除了control file 和redo log file)

SQL> startup mount


SQL> recover database until cancel                                     
ORA-00279: 更改 247235 (在 09/25/2004 16:24:05 生成) 对于线程 1 是必需的
ORA-00289: 建议: D:/ORACLE/ORADATA/ARCHIVE00/AWU1.ARC                  
ORA-00280: 更改 247235 对于线程 1 是按序列 # 1 进行的                  
                                                                       
                                                                       
指定日志: {<RET>=suggested | filename | AUTO | CANCEL}                 
                                                                       
ORA-00279: 更改 267451 (在 09/25/2004 17:13:15 生成) 对于线程 1 是必需的
ORA-00289: 建议: D:/ORACLE/ORADATA/ARCHIVE00/AWU2.ARC                  
ORA-00280: 更改 267451 对于线程 1 是按序列 # 2 进行的                  
ORA-00278: 此恢复不再需要日志文件 'D:/ORACLE/ORADATA/ARCHIVE00/AWU1.ARC'
                                                                       
                                                                         
指定日志: {<RET>=suggested | filename | AUTO | CANCEL}                   
                                                                       
ORA-00279: 更改 267595 (在 09/25/2004 17:13:58 生成) 对于线程 1 是必需的
ORA-00289: 建议: D:/ORACLE/ORADATA/ARCHIVE00/AWU3.ARC                  
ORA-00280: 更改 267595 对于线程 1 是按序列 # 3 进行的                  
ORA-00278: 此恢复不再需要日志文件 'D:/ORACLE/ORADATA/ARCHIVE00/AWU2.ARC'
                                                                       
                                                                       
指定日志: {<RET>=suggested | filename | AUTO | CANCEL}                 
cancel                                                                 
介质恢复已取消。


SQL> select * from scott.test1;       
                              
             N1                    
     ----------                                                         
              1                    
              2                 
test1 中的  3,4因为没有及时归档,结果丢失


1.2.3 lab7
恢复时,使用备份的控制文件
The current time is 12:00 p.m. on March 9, 2002.
The tablespace containing the EMPLOYEES table has been dropped.
The error occurred around 11:45 a.m.
Many employee records were updated this morning, but not since 11:00 a.m.
Backups are taken every night.(教材的描述)

我制造的情景

SQL> create table scott.test2(n1 number) tablespace users;
SQL> alter system switch logfile;
SQL> insert into scott.test2 values(1);
SQL> commit;
SQL> alter system switch logfile;
SQL> drop tablespace users including contents and datafiles;
SQL> create table scott.test3(n1 number) tablespace tools;
SQL> insert into scott.test3 values(1);
SQL> commit;
SQL> alter system switch logfile;

现在需要把 test2给找回来

SQL> shutdown immediate;
OS: 把datafile和control file都copy回来

打开 D:/oracle/admin/a00215/bdump/alert_a00215.log

找到最近一次drop tablespace
Sat Sep 25 23:26:54 2004
drop tablespace users including contents and datafiles

应将数据库恢复到
2004-09-25:23:26:53 的样子

SQL> startup
提示日志不匹配
ORA-00314: 日志 3 (线程 1),预计序号 1 与 4 不匹配
ORA-00312: 联机日志 3 线程 1: 'D:/ORACLE/ORADATA/A00215/REDO03.LOG'

SQL> recover database until time '2004-09-25:23:26:53' using backup controlfile;
ORA-00279: 更改 267597 (在 09/25/2004 17:17:23 生成) 对于线程 1 是必需的
ORA-00289: 建议: D:/ORACLE/ORADATA/ARCHIVE00/AWU1.ARC
ORA-00280: 更改 267597 对于线程 1 是按序列 # 1 进行的


指定日志: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: 更改 294226 (在 09/25/2004 23:25:58 生成) 对于线程 1 是必需的
ORA-00289: 建议: D:/ORACLE/ORADATA/ARCHIVE00/AWU2.ARC
ORA-00280: 更改 294226 对于线程 1 是按序列 # 2 进行的
ORA-00278: 此恢复不再需要日志文件 'D:/ORACLE/ORADATA/ARCHIVE00/AWU1.ARC'


ORA-00279: 更改 294368 (在 09/25/2004 23:26:35 生成) 对于线程 1 是必需的
ORA-00289: 建议: D:/ORACLE/ORADATA/ARCHIVE00/AWU3.ARC
ORA-00280: 更改 294368 对于线程 1 是按序列 # 3 进行的
ORA-00278: 此恢复不再需要日志文件 'D:/ORACLE/ORADATA/ARCHIVE00/AWU2.ARC'


已应用的日志。
完成介质恢复。

SQL> alter database open resetlogs;
SQL> select * from scott.test2;       
                              
             N1                    
     ----------                                                         
              1                    
            
SQL> select * from scott.test3;
select * from scott.test3
                    *
ERROR 位于第 1 行:
ORA-00942: 表或视图不存在

rman管理的

将上述七个实验基本再做一遍

准备工作: 用catalog和不用catalog(恢复目录数据库)
不用catalog 的方式,采用目标数据库控制文件(control file)

必须是归档模式
用写字板打开initSID.ora 编辑这个静态参数文件          
 加三行代码                                       
 *.log_archive_start=true                         
 *.log_archive_dest='D:/oracle/oradata/archive00/'
 *.log_archive_format='awu%s.arc'                 
   OS保存                                                


还用scott用户
SQL> drop user scott cascade
创建scott用户,供实验用
SQL> @D:/oracle/ora92/rdbms/admin/scott.sql

D:/>rman target sys/oracle nocatalog
RMAN> startup mount
RMAN> backup database
2> format 'D:/oracle/oradata/rmanbackup00/a00215_%s_%p.rmn';

这样就准备了一个备份,数据库必须在mount状态进行

2.1.1 lab8
数据库关闭状态,需要恢复System datafiles,Undo segment datafiles,Whole database
在这里,我们给scott用户创建一个表,然后破坏undo,恢复后,看看表中的数据还在不在
1) SQL>  conn sys/oracle as sysdba
   SQL> startup
2) SQL> create table scott.com1(n1 number);
   SQL> insert into scott.com1 values(1);
   SQL> commit;
   SQL> alter system switch logfile;
   SQL> insert into scott.com1 values(2);
   SQL> shutdown abort
3) 此时,把undo破坏
   在‘服务‘中,将OracleServiceA00215停止
    删除(OS)undo文件
4) 在‘服务‘中,将OracleServiceA00215启动
5) conn / as sysdba
startup
ORACLE 例程已经启动。
Total System Global Area  135338868 bytes
Fixed Size                   453492 bytes
Variable Size             109051904 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes
数据库装载完毕。
ORA-01157: 无法标识/锁定数据文件 9 - 请参阅 DBWR 跟踪文件
ORA-01110: 数据文件 9: 'D:/ORACLE/ORADATA/A00215/UNDO01.DBF'

(不发的话,可以看警告日志D:/oracle/admin/a00215/bdump/alert_a00215.log,
Sat Sep 25 14:18:18 2004
Errors in file d:/oracle/admin/a00215/bdump/a00215_dbw0_1552.trc:
ORA-01157: cannot identify/lock data file 9 - see DBWR trace file
ORA-01110: data file 9: 'D:/ORACLE/ORADATA/A00215/UNDO01.DBF'
ORA-27041: unable to open file
OSD-04002: 无法打开文件
O/S-Error: (OS 2) 系统找不到指定的文件。)


恢复


RMAN> RESTORE DATABASE;
RMAN>  RECOVER DATABASE;
RMAN> alter database open;
SQL> select * from scott.com1;

        N1
----------
         1


2.1.2 lab9

数据库打开的时候,并且恢复的时候数据库也开启,此时受损的文件不能是system或者undo文件   

如下操作,都在数据库open时进行                                                               
1) SQL> create table scott.com2 (n1 number) tablespace users;                                
   SQL> insert into scott.com2 values(1);                                                    
   SQL> commit;                                                                              
   SQL> alter system switch logfile;                                                         
                                                                                             
2) 破坏users01.dbf (users 表空间)                                                            
   我这里采取的办法是先将users 表空间offline,再造一个同名(0字节)的覆盖,也可以采取其他办法。
  
SQL> select * from scott.com2;
select * from scott.com2
                    *
ERROR 位于第 1 行:
ORA-00376: 此时无法读取文件 7
ORA-01110: 数据文件 7: 'D:/ORACLE/ORADATA/A00215/USERS01.DBF'
                                                                                                                          
3)恢复

RMAN> run {
2>  sql "alter tablespace users offline immediate";
3>  set newname for datafile 7 to 'D:/oracle/oradata/a00215/users02.dbf';
4>  restore tablespace users;
5>  switch datafile 7;
6>  recover tablespace users;
7>  sql "alter tablespace users online";}

SQL>  select * from scott.com2;

        N1
----------
         1
        
2.1.3 lab10
描述
和实验二类似,不同之处在于数据库损坏时为关闭状态,此时受损的文件不能是system或者undo文件
1)数据库关闭时,删除users02.dbf

恢复
SQL> startup
ORA-01157: 无法标识/锁定数据文件 7 - 请参阅 DBWR 跟踪文件
ORA-01110: 数据文件 7: 'D:/ORACLE/ORADATA/A00215/USERS02.DBF'

RMAN>
 run {
 set newname for datafile 7 to 'D:/oracle/oradata/a00215/users01.dbf';
 restore tablespace users;
 switch datafile 7;
 recover tablespace users;
 alter database open;}
 
 SQL>  select * from scott.com2;

        N1
----------
         1
        
        

2.1.4 lab11
没有备份的情况下,恢复一个数据文件,不能是system或者undo段
SQL> drop tablespace testtbs  INCLUDING CONTENTS;

SQL> create tablespace testtbs datafile 'D:/oracle/oradata/a00215/testtbs.dbf' size 1m;
SQL> alter system switch logfile;
SQL> create table scott.com4 (n1 number) tablespace testtbs;
SQL> alter system switch logfile;
SQL> insert into scott.com4 values(1);
SQL> commit;
SQL> alter system switch logfile;

假设 testtbs.dbf坏了
  我这里采取的办法是先将testtbs.dbf指向另外一个目录。

SQL>  alter tablespace testtbs offline immediate;

SQL>  alter database create datafile 'D:/oracle/oradata/a00215/testtbs.dbf' as 'D:/oracle/oradata/a00215/u1/testtbs1.dbf';                                        

SQL> select * from scott.com4;
select * from scott.com4
                    *
ERROR 位于第 1 行:
ORA-00376: 此时无法读取文件 2
ORA-01110: 数据文件 2: 'D:/ORACLE/ORADATA/A00215/TESTTBS.DBF'

恢复
 
RMAN>  run{                                                                
2> set newname for datafile 2 to 'D:/oracle/oradata/a00215/u1/testtbs1.dbf';
3> }                                                                       

RMAN>  recover tablespace testtbs ;

SQL>  alter tablespace testtbs online;                           
SQL>  select * from scott.com4;
                                                                                                                                                  
        N1                                                                                                                                               
----------                                                                                                                                               
         1                    
        
恢复成功。

不完全恢复的三个实验

 

2.2.1 lab12
基于时间的恢复

注册表 HKEY_LOCAL_MACHINE/SOFTWARE/ORACLE/HOME0  确认存在 NLS_DATE_FORMAT=’YYYY-MM-DD:HH24:MI:SS’,如果没有,则加上
SQL> select to_char(sysdate,'yyyy-mm-dd:hh24:mi:ss') from dual;
2004-09-26:17:43:43

SQL> select * from scott.emp;

EMPNO ENAME      JOB         MGR HIREDATE          SAL      COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
 7369 SMITH      CLERK      7902 1980-12-17     800.00               20
 7499 ALLEN      SALESMAN   7698 1981-2-20     1600.00    300.00     30
 7521 WARD       SALESMAN   7698 1981-2-22     1250.00    500.00     30
 7566 JONES      MANAGER    7839 1981-4-2      2975.00               20
 7654 MARTIN     SALESMAN   7698 1981-9-28     1250.00   1400.00     30
 7698 BLAKE      MANAGER    7839 1981-5-1      2850.00               30
 7782 CLARK      MANAGER    7839 1981-6-9      2450.00               10
 7839 KING       PRESIDENT       1981-11-17    5000.00               10
 7844 TURNER     SALESMAN   7698 1981-9-8      1500.00      0.00     30
 7900 JAMES      CLERK      7698 1981-12-3      950.00               30
 7902 FORD       ANALYST    7566 1981-12-3     3000.00               20
 7934 MILLER     CLERK      7782 1982-1-23     1300.00               10
 2004-09-26:17:43:43之后,将scott.emp表删除
SQL> drop table scott.emp  ;
SQL> create table scott.com1 (n1 number);
SQL> insert into scott.com1 values(1);
SQL> alter system switch logfile;
SQL>  select * from scott.com1;

        N1
----------
         1


将数据库恢复到2004-09-26:17:43:43的时间点
SQL> shutdown abort
SQL> startup mount
RMAN> RUN {
    SET UNTIL TIME = '2004-09-26:17:43:42';
    RESTORE DATABASE;
    RECOVER DATABASE;
    ALTER DATABASE OPEN RESETLOGS; }

SQL> select * from scott.emp;

EMPNO ENAME      JOB         MGR HIREDATE          SAL      COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
 7369 SMITH      CLERK      7902 1980-12-17     800.00               20
 7499 ALLEN      SALESMAN   7698 1981-2-20     1600.00    300.00     30
 7521 WARD       SALESMAN   7698 1981-2-22     1250.00    500.00     30
 7566 JONES      MANAGER    7839 1981-4-2      2975.00               20
 7654 MARTIN     SALESMAN   7698 1981-9-28     1250.00   1400.00     30
 7698 BLAKE      MANAGER    7839 1981-5-1      2850.00               30
 7782 CLARK      MANAGER    7839 1981-6-9      2450.00               10
 7839 KING       PRESIDENT       1981-11-17    5000.00               10
 7844 TURNER     SALESMAN   7698 1981-9-8      1500.00      0.00     30
 7900 JAMES      CLERK      7698 1981-12-3      950.00               30
 7902 FORD       ANALYST    7566 1981-12-3     3000.00               20
 7934 MILLER     CLERK      7782 1982-1-23     1300.00               10
 
SQL> select * from scott.com1;
select * from scott.com1
                    *
ERROR 位于第 1 行:
ORA-00942: 表或视图不存在


2.2.2 lab13
基于序列号 (sequence number)
做不完全恢复之前,要给数据库做一个备份 这里用rman 做

sequence number是指 redo log的序列号

SQL> create table scott.test1(n1 number);
SQL> insert into scott.test1 values(1); 
SQL> insert into scott.test1 values(2); 
SQL> commit;                            
SQL> alter system switch logfile;       
SQL> insert into scott.test1 values(3); 
SQL> insert into scott.test1 values(4); 
SQL> commit;                            
SQL> select * from v$log;               
                                                                                                            
    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME        
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- -------------------
         1          1        661    1048576          1 YES ACTIVE                  153702 2004-09-26:18:35:31
         2          1        662    1048576          1 NO  CURRENT                 153866 2004-09-26:18:35:53
         3          1        660    1048576          1 YES INACTIVE                132723 2004-09-26:15:40:25
SQL> shutdown abort
2号组为当前组,将其破坏
SQL> startup mount

RUN {
    SET UNTIL SEQUENCE 662 THREAD 1;
    RESTORE DATABASE; 
    RECOVER DATABASE;
    ALTER DATABASE OPEN RESESTLOGS;}
   
   
SQL> select * from scott.test1
  2  /                       
                             
        N1                   
----------                   
         1                   
         2                   
scott.test1 中3,4没有归档,丢失

 

2.2.3  lab14
恢复时,使用备份的控制文件

这里必须建立恢复目录catalog,而不能用control file

注,以上的六个实验,也能用catalog再做一遍

准备工作
这里先建一个数据库orcl(用来存放catalog)
创建表空间
SQL> create tablespace rman_ts datafile          
  2  'D:/oracle/oradata/orcl/rman_ts.dbf' size 20m
  3   autoextend on next 1m maxsize unlimited    
  4  extent management local uniform size 128k;  

创建用户
SQL> create user rman_owner identified by rman_owner    
  2  default tablespace rman_ts                             
  3  quota unlimited on rman_ts;                            
       
授权
 grant connect,resource,recovery_catalog_owner to rman_owner;


登陆a00215数据库和恢复目录数据库(orcl)
D:/>rman catalog rman_owner/rman_owner@orcl target sys/oracle@a00215

创建恢复目录
RMAN> create catalog tablespace rman_ts

注册在恢复目录中的数据库
RMAN> register database;

给数据库做一个备份

注意:可能需要切换副本
RMAN> list incarnation of database;


数据库 Incarnations 列表
DB 关键字  Inc 关键字 DB 名  DB ID            CUR 重置 SCN   重置时间
------- ------- -------- ---------------- --- ---------- ----------
1       11      A00215   3493611191       NO  1          2004-09-26:15:12:55
1       2       A00215   3493611191       YES 153867     2004-09-26:18:42:50


RMAN>  reset database to incarnation 11;

SQL> create table scott.test1(n1 number) tablespace users;
SQL> insert into scott.test1 values(1);
SQL> insert into scott.test1 values(2);
SQL> alter system switch logfile
  2  /
SQL> drop tablespace users including contents and datafiles;
SQL>  create table scott.test2(n1 number) tablespace tools;
SQL> insert into scott.test2 values(2);
SQL> shutdown abort

在 alert_a00215.log里
Sun Sep 26 20:49:23 2004                              
 drop tablespace users including contents and datafiles


恢复到2004-09-26:20:49:22的样子

RMAN> startup nomount
RMAN>
 run {                           
 set until time='2004-09-26:20:49:22';                                  
 restore controlfile;               
 alter database mount;              
 restore database;                  
 recover database;                  
 alter database open resetlogs;}  

恢复完之后
 
SQL> select * from scott.test1
  2  /                       
                             
        N1                   
----------                   
         1                   


SQL> select * from scott.test2;
select * from scott.test2
                    *
ERROR 位于第 1 行:
ORA-00942: 表或视图不存在

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:4643次
    • 积分:65
    • 等级:
    • 排名:千里之外
    • 原创:2篇
    • 转载:3篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档