Oracle恢復實驗筆記

系統 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: 表或視圖不存在

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章