案例3――在做完全恢复时,丢失了部分归档日志 (recover database until cancel;)
1、基于cancel 的不完全恢复
――模拟环境
SQL> col table_name for a20
SQL> col tablespace_name for a10
SQL> select table_name,tablespace_name from user_tables;
TABLE_NAME TABLESPACE
-------------------- ----------
DEPT USERS
EMP USERS
BONUS USERS
SALGRADE USERS
EMPLOYEES USERS
EMP2 USERS
TB02 CUUG
TB01 TEST
ADMIN_EXT_EMPLOYEES
EMP1 USERS
10 rows selected.
SQL> conn /as sysdba
Connected.
SQL> select * from scott.tb02;
ID
----------
1
2
3
4
5
6
7
8
8 rows selected.
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARCHIVED STATUS FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- --------- ------------ ------------- -------------------
1 1 1 104857600 3 YES INACTIVE 851230 2012-03-23 16:04:13
4 1 4 104857600 3 NO CURRENT 851518 2012-03-23 16:13:25
3 1 3 104857600 3 YES INACTIVE 851509 2012-03-23 16:13:09
2 1 2 104857600 3 YES INACTIVE 851500 2012-03-23 16:12:53
SQL> insert into scott.tb02 values(9);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system archive log current;
System altered.
SQL> insert into scott.tb02 values(10);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system archive log current;
System altered.
SQL> insert into scott.tb02 values(11);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system archive log current;
System altered.
SQL> select name from v$archived_log;
NAME
--------------------------------------------------
/disk1/arch/anny/arch_1_3_778691360.log
/disk1/arch/anny/arch_1_4_778691360.log
/disk1/arch/anny/arch_1_5_778691360.log
/disk1/arch/anny/arch_1_6_778691360.log
/disk1/arch/anny/arch_1_1_778694653.log
/disk1/arch/anny/arch_1_2_778694653.log
/disk1/arch/anny/arch_1_3_778694653.log
/disk1/arch/anny/arch_1_4_778694653.log
/disk1/arch/anny/arch_1_5_778694653.log
/disk1/arch/anny/arch_1_6_778694653.log
52 rows selected.
SQL> select * from scott.tb02;
ID
----------
1
2
3
4
5
6
7
8
9
10
11
11 rows selected.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
――users 表空间datafile被误删除
[oracle@solaris10 ~]$rm /u01/app/oracle/oradata/anny/cuug01.dbf
[oracle@solaris10 ~]$mv /disk1/arch/anny/arch_1_1_778694653.log /disk1/arch/anny/arch_1_1_778694653.log.bak
[oracle@solaris10 ~]$mv /disk1/arch/anny/arch_1_2_778694653.log /disk1/arch/anny/arch_1_2_778694653.log.bak
[oracle@solaris10 ~]$
――做完全恢复
SQL> startup
ORACLE instance started.
Total System Global Area 314572800 bytes
Fixed Size 1279964 bytes
Variable Size 58722340 bytes
Database Buffers 251658240 bytes
Redo Buffers 2912256 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 12 - see DBWR trace file
ORA-01110: data file 12: '/u01/app/oracle/oradata/anny/cuug01.dbf'
SQL> select file#,error from v$recover_file;
FILE# ERROR
---------- -----------------------------------------------------------------
12 FILE NOT FOUND
1 row selected.
――启动database 失败,restore datafile
[oracle@solaris10 ~]$cp /disk1/backup/anny/cold_bak/cuug01.dbf /u01/app/oracle/oradata/anny/
――recover datafile
SQL> recover datafile 12;
ORA-00279: change 850758 generated at 03/23/2012 15:29:42 needed for thread 1
ORA-00289: suggestion : /disk1/arch/anny/arch_1_1_778691360.log
ORA-00280: change 850758 for thread 1 is in sequence #1
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: change 850903 generated at 03/23/2012 15:35:17 needed for thread 1
ORA-00289: suggestion : /disk1/arch/anny/arch_1_2_778691360.log
ORA-00280: change 850903 for thread 1 is in sequence #2
ORA-00278: log file '/disk1/arch/anny/arch_1_1_778691360.log' no longer needed for this recovery
ORA-00279: change 851178 generated at 03/23/2012 15:43:29 needed for thread 1
ORA-00289: suggestion : /disk1/arch/anny/arch_1_3_778691360.log
ORA-00280: change 851178 for thread 1 is in sequence #3
ORA-00278: log file '/disk1/arch/anny/arch_1_2_778691360.log' no longer needed for this recovery
ORA-00279: change 851181 generated at 03/23/2012 15:43:30 needed for thread 1
ORA-00289: suggestion : /disk1/arch/anny/arch_1_4_778691360.log
ORA-00280: change 851181 for thread 1 is in sequence #4
ORA-00278: log file '/disk1/arch/anny/arch_1_3_778691360.log' no longer needed for this recovery
ORA-00279: change 851183 generated at 03/23/2012 15:43:31 needed for thread 1
ORA-00289: suggestion : /disk1/arch/anny/arch_1_5_778691360.log
ORA-00280: change 851183 for thread 1 is in sequence #5
ORA-00278: log file '/disk1/arch/anny/arch_1_4_778691360.log' no longer needed for this recovery
ORA-00279: change 851187 generated at 03/23/2012 15:43:36 needed for thread 1
ORA-00289: suggestion : /disk1/arch/anny/arch_1_6_778691360.log
ORA-00280: change 851187 for thread 1 is in sequence #6
ORA-00278: log file '/disk1/arch/anny/arch_1_5_778691360.log' no longer needed for this recovery
ORA-00279: change 851230 generated at 03/23/2012 16:04:13 needed for thread 1
ORA-00289: suggestion : /disk1/arch/anny/arch_1_1_778694653.log
ORA-00280: change 851230 for thread 1 is in sequence #1
ORA-00278: log file '/disk1/arch/anny/arch_1_6_778691360.log' no longer needed for this recovery
ORA-00308: cannot open archived log '/disk1/arch/anny/arch_1_1_778694653.log'
ORA-27037: unable to obtain file status
Intel SVR4 UNIX Error: 2: No such file or directory
Additional information: 3
――完全恢复失败,缺少归档日志:(/disk1/arch/anny/arch_1_1_778694653.log)
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 12 needs media recovery
ORA-01110: data file 12: '/u01/app/oracle/oradata/anny/cuug01.dbf'
――只能做基于cancel的不完全恢复
――转储所有的datafile
[oracle@solaris10 ~]$cp /disk1/backup/anny/cold_bak/*.dbf /u01/app/oracle/oradata/anny/
SQL> recover database until cancel;――第一次选择auto
ORA-00279: change 850758 generated at 03/23/2012 15:29:42 needed for thread 1
ORA-00289: suggestion : /disk1/arch/anny/arch_1_1_778691360.log
ORA-00280: change 850758 for thread 1 is in sequence #1
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: change 850903 generated at 03/23/2012 15:35:17 needed for thread 1
ORA-00289: suggestion : /disk1/arch/anny/arch_1_2_778691360.log
ORA-00280: change 850903 for thread 1 is in sequence #2
ORA-00278: log file '/disk1/arch/anny/arch_1_1_778691360.log' no longer needed for this recovery
ORA-00279: change 851178 generated at 03/23/2012 15:43:29 needed for thread 1
ORA-00289: suggestion : /disk1/arch/anny/arch_1_3_778691360.log
ORA-00280: change 851178 for thread 1 is in sequence #3
ORA-00278: log file '/disk1/arch/anny/arch_1_2_778691360.log' no longer needed for this recovery
ORA-00279: change 851181 generated at 03/23/2012 15:43:30 needed for thread 1
ORA-00289: suggestion : /disk1/arch/anny/arch_1_4_778691360.log
ORA-00280: change 851181 for thread 1 is in sequence #4
ORA-00278: log file '/disk1/arch/anny/arch_1_3_778691360.log' no longer needed for this recovery
ORA-00279: change 851183 generated at 03/23/2012 15:43:31 needed for thread 1
ORA-00289: suggestion : /disk1/arch/anny/arch_1_5_778691360.log
ORA-00280: change 851183 for thread 1 is in sequence #5
ORA-00278: log file '/disk1/arch/anny/arch_1_4_778691360.log' no longer needed for this recovery
ORA-00279: change 851187 generated at 03/23/2012 15:43:36 needed for thread 1
ORA-00289: suggestion : /disk1/arch/anny/arch_1_6_778691360.log
ORA-00280: change 851187 for thread 1 is in sequence #6
ORA-00278: log file '/disk1/arch/anny/arch_1_5_778691360.log' no longer needed for this recovery
ORA-00279: change 851230 generated at 03/23/2012 16:04:13 needed for thread 1
ORA-00289: suggestion : /disk1/arch/anny/arch_1_1_778694653.log
ORA-00280: change 851230 for thread 1 is in sequence #1
ORA-00278: log file '/disk1/arch/anny/arch_1_6_778691360.log' no longer needed for this recovery
ORA-00308: cannot open archived log '/disk1/arch/anny/arch_1_1_778694653.log'
ORA-27037: unable to obtain file status
Intel SVR4 UNIX Error: 2: No such file or directory
Additional information: 3
SQL> recover database until cancel;
ORA-00279: change 851230 generated at 03/23/2012 15:45:23 needed for thread 1
ORA-00289: suggestion : /disk1/arch/anny/arch_1_1_778694653.log
ORA-00280: change 851230 for thread 1 is in sequence #1
――再执行一次,选择cancel ,在丢失的归档日志前终止recover
SQL> recover database until cancel;
ORA-00279: change 851230 generated at 03/23/2012 15:45:23 needed for thread 1
ORA-00289: suggestion : /disk1/arch/anny/arch_1_1_778694653.log
ORA-00280: change 851230 for thread 1 is in sequence #1
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.
查看告警日志:
ALTER DATABASE RECOVER CANCEL
Fri Mar 23 16:35:27 2012
Media Recovery Canceled
Completed: ALTER DATABASE RECOVER CANCEL
Fri Mar 23 16:38:20 2012
alter database open
Fri Mar 23 16:38:20 2012
ORA-1113 signalled during: alter database open...
Fri Mar 23 16:44:17 2012
ALTER DATABASE RECOVER database until cancel
Fri Mar 23 16:44:17 2012
Media Recovery Start
Media Recovery start incarnation depth : 1, target inc# : 8, irscn : 851229
ORA-279 signalled during: ALTER DATABASE RECOVER database until cancel ...
Fri Mar 23 16:44:20 2012
ALTER DATABASE RECOVER CONTINUE DEFAULT
Fri Mar 23 16:44:20 2012
Media Recovery Log /disk1/arch/anny/arch_1_1_778691360.log
ORA-279 signalled during: ALTER DATABASE RECOVER CONTINUE DEFAULT ...
Fri Mar 23 16:44:20 2012
ALTER DATABASE RECOVER CONTINUE DEFAULT
Fri Mar 23 16:44:20 2012
Media Recovery Log /disk1/arch/anny/arch_1_2_778691360.log
ORA-279 signalled during: ALTER DATABASE RECOVER CONTINUE DEFAULT ...
Fri Mar 23 16:44:20 2012
ALTER DATABASE RECOVER CONTINUE DEFAULT
Fri Mar 23 16:44:20 2012
Media Recovery Log /disk1/arch/anny/arch_1_3_778691360.log
ORA-279 signalled during: ALTER DATABASE RECOVER CONTINUE DEFAULT ...
Fri Mar 23 16:44:20 2012
ALTER DATABASE RECOVER CONTINUE DEFAULT
Fri Mar 23 16:44:20 2012
Media Recovery Log /disk1/arch/anny/arch_1_4_778691360.log
ORA-279 signalled during: ALTER DATABASE RECOVER CONTINUE DEFAULT ...
Fri Mar 23 16:44:20 2012
ALTER DATABASE RECOVER CONTINUE DEFAULT
Fri Mar 23 16:44:20 2012
Media Recovery Log /disk1/arch/anny/arch_1_5_778691360.log
ORA-279 signalled during: ALTER DATABASE RECOVER CONTINUE DEFAULT ...
Fri Mar 23 16:44:20 2012
ALTER DATABASE RECOVER CONTINUE DEFAULT
Fri Mar 23 16:44:20 2012
Media Recovery Log /disk1/arch/anny/arch_1_6_778691360.log
ORA-279 signalled during: ALTER DATABASE RECOVER CONTINUE DEFAULT ...
Fri Mar 23 16:44:21 2012
ALTER DATABASE RECOVER CONTINUE DEFAULT
Fri Mar 23 16:44:21 2012
Media Recovery Log /disk1/arch/anny/arch_1_1_778694653.log
Errors with log /disk1/arch/anny/arch_1_1_778694653.log
ORA-308 signalled during: ALTER DATABASE RECOVER CONTINUE DEFAULT ...
Fri Mar 23 16:44:21 2012
ALTER DATABASE RECOVER CANCEL
Fri Mar 23 16:44:21 2012
Media Recovery Canceled
Completed: ALTER DATABASE RECOVER CANCEL
Fri Mar 23 16:44:25 2012
ALTER DATABASE RECOVER database until cancel
Media Recovery Start
ORA-279 signalled during: ALTER DATABASE RECOVER database until cancel ...
Fri Mar 23 16:44:29 2012
ALTER DATABASE RECOVER CANCEL
Fri Mar 23 16:44:29 2012
Media Recovery Canceled
Completed: ALTER DATABASE RECOVER CANCEL
――验证,只恢复到sequence 为3的日志所记录的data block
SQL> alter database open resetlogs;
Database altered.
SQL> select * from scott.tb02;
ID
----------
1
2
3
4
5
5 rows selected.
oracle视频教程请关注:http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html