Oracle用户管理的不完全恢复:根据时间进行恢复
需要进行不完全恢复的场景:
a.因归档日志丢失而导致完全恢复失败。
b.所有未归档的重做日志文件和数据文件均丢失。
c.用户错误
1.某个重要的表被删除。 2.在表中提交了无效数据。
d.当前控制文件丢失,必须使用备份控制文件才能打开数据库。
模拟场景:
1.1干净关闭数据库
1 SQL> conn /as sysdba 2 Connected. 3 SQL> shutdown immediate 4 Database closed. 5 Database dismounted. 6 ORACLE instance shut down. 7 SQL>
1.2 对数据库冷备
1 bash-3.00$ ls -l 2 total 2215712 3 -rw-r----- 1 oracle oinstall 7389184 Jan 25 21:18 control01.ctl 4 -rw-r----- 1 oracle oinstall 7389184 Jan 25 21:18 control02.ctl 5 -rw-r----- 1 oracle oinstall 7389184 Jan 25 21:18 control03.ctl 6 -rw-r----- 1 oracle oinstall 104865792 Jan 25 21:18 example01.dbf 7 -rw-r----- 1 oracle oinstall 52429312 Jan 25 20:31 redo01.log 8 -rw-r----- 1 oracle oinstall 52429312 Jan 25 21:18 redo02.log 9 -rw-r----- 1 oracle oinstall 52429312 Jan 25 20:31 redo03.log 10 -rw-r----- 1 oracle oinstall 10493952 Jan 25 21:18 sun01_1.dbf 11 -rw-r----- 1 oracle oinstall 10493952 Jan 25 21:18 sun02_1.dbf 12 -rw-r----- 1 oracle oinstall 5251072 Jan 25 21:18 sun03_1.dbf 13 -rw-r----- 1 oracle oinstall 262152192 Jan 25 21:18 sysaux01.dbf 14 -rw-r----- 1 oracle oinstall 503324672 Jan 25 21:18 system01.dbf 15 -rw-r----- 1 oracle oinstall 20979712 Jan 23 04:03 temp01.dbf 16 -rw-r----- 1 oracle oinstall 31465472 Jan 25 21:18 undotbs01.dbf 17 -rw-r----- 1 oracle oinstall 5251072 Jan 25 21:18 users01.dbf 18 bash-3.00$ cp * /u01/backup/cold 19 bash-3.00$
1.3 在t表中插入数据
1 SQL> conn user1/user1 2 Connected. 3 4 SQL> select * from t; 5 6 ID NAME 7 ---------- ---------------- 8 1 oracle 9 2 oracle 10 0 oracle 11 3 oracle 12 4 oracle 13 5 oracle 14 15 6 rows selected. 16 17 SQL> insert into t values(6,'oracle'); 18 19 1 row created. 20 21 SQL> commit; 22 23 Commit complete. 24 25 SQL>
1.4查看当前时间
1 SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual; 2 3 TO_CHAR(SYSDATE,'YY 4 ------------------- 5 2013-01-25 21:30:35 6 7 SQL>
1.5 模拟失误现场
1 SQL> drop table t; 2 3 Table dropped. 4 5 SQL>
恢复
2.1 关机
1 SQL> shutdown abort 2 ORACLE instance shut down. 3 SQL>
2.2还原以前备份的数据文件
1 bash-3.00$ pwd 2 /u01/oradata/sunbak 3 bash-3.00$ ls -l 4 total 2215712 5 -rw-r----- 1 oracle oinstall 7389184 Jan 25 21:33 control01.ctl 6 -rw-r----- 1 oracle oinstall 7389184 Jan 25 21:33 control02.ctl 7 -rw-r----- 1 oracle oinstall 7389184 Jan 25 21:33 control03.ctl 8 -rw-r----- 1 oracle oinstall 104865792 Jan 25 21:21 example01.dbf 9 -rw-r----- 1 oracle oinstall 52429312 Jan 25 21:21 redo01.log 10 -rw-r----- 1 oracle oinstall 52429312 Jan 25 21:33 redo02.log 11 -rw-r----- 1 oracle oinstall 52429312 Jan 25 21:21 redo03.log 12 -rw-r----- 1 oracle oinstall 10493952 Jan 25 21:30 sun01_1.dbf 13 -rw-r----- 1 oracle oinstall 10493952 Jan 25 21:21 sun02_1.dbf 14 -rw-r----- 1 oracle oinstall 5251072 Jan 25 21:21 sun03_1.dbf 15 -rw-r----- 1 oracle oinstall 262152192 Jan 25 21:33 sysaux01.dbf 16 -rw-r----- 1 oracle oinstall 503324672 Jan 25 21:33 system01.dbf 17 -rw-r----- 1 oracle oinstall 20979712 Jan 23 04:03 temp01.dbf 18 -rw-r----- 1 oracle oinstall 31465472 Jan 25 21:33 undotbs01.dbf 19 -rw-r----- 1 oracle oinstall 5251072 Jan 25 21:21 users01.dbf 20 bash-3.00$ rm -f *.dbf 21 bash-3.00$ cd /u01/backup/cold/ 22 bash-3.00$ cp *.dbf /u01/oradata/sunbak/ 23 bash-3.00$
2.3将数据库开到mount
1 SQL> conn /as sysdba 2 Connected to an idle instance. 3 SQL> startup mount 4 ORACLE instance started. 5 6 Total System Global Area 289406976 bytes 7 Fixed Size 1279820 bytes 8 Variable Size 92276916 bytes 9 Database Buffers 192937984 bytes 10 Redo Buffers 2912256 bytes 11 Database mounted. 12 SQL>
2.4对比控制文件与数据文件的SCN
1 #最新的控制文件 2 SQL> select file#,checkpoint_change# from v$datafile; 3 4 FILE# CHECKPOINT_CHANGE# 5 ---------- ------------------ 6 1 690924 7 2 690924 8 3 690924 9 4 690924 10 5 690924 11 6 690924 12 7 690924 13 8 690924 14 15 8 rows selected. 16 17 SQL> 18 #备份的数据文件 19 SQL> select file#,checkpoint_change# from v$datafile_header; 20 21 FILE# CHECKPOINT_CHANGE# 22 ---------- ------------------ 23 1 690923 24 2 690923 25 3 690923 26 4 690923 27 5 690923 28 6 690923 29 7 690923 30 8 690923 31 32 8 rows selected. 33 34 SQL>
2.5 恢复
1 SQL> recover database until time '2013-01-25:21:30:35'; 2 Media recovery complete. 3 SQL> 4 SQL> alter database open resetlogs; 5 6 Database altered. 7 8 SQL>
3.查看t表
1 SQL> select * from user1.t order by 1; 2 3 ID NAME 4 ---------- ---------------- 5 0 oracle 6 1 oracle 7 2 oracle 8 3 oracle 9 4 oracle 10 5 oracle 11 6 oracle 12 13 7 rows selected. 14 15 SQL>