您的位置:首页 > 数据库 > Oracle

Oracle用户管理的不完全恢复:根据时间进行恢复

2013-01-29 14:42 501 查看
需要进行不完全恢复的场景:

  a.因归档日志丢失而导致完全恢复失败。

  b.所有未归档的重做日志文件和数据文件均丢失。

  c.用户错误

    1.某个重要的表被删除。  2.在表中提交了无效数据。

  d.当前控制文件丢失,必须使用备份控制文件才能打开数据库。

模拟场景:

1.1干净关闭数据库

SQL> conn /as sysdba
Connected.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>


1.2 对数据库冷备

bash-3.00$ ls -l
total 2215712
-rw-r-----   1 oracle   oinstall 7389184 Jan 25 21:18 control01.ctl
-rw-r-----   1 oracle   oinstall 7389184 Jan 25 21:18 control02.ctl
-rw-r-----   1 oracle   oinstall 7389184 Jan 25 21:18 control03.ctl
-rw-r-----   1 oracle   oinstall 104865792 Jan 25 21:18 example01.dbf
-rw-r-----   1 oracle   oinstall 52429312 Jan 25 20:31 redo01.log
-rw-r-----   1 oracle   oinstall 52429312 Jan 25 21:18 redo02.log
-rw-r-----   1 oracle   oinstall 52429312 Jan 25 20:31 redo03.log
-rw-r-----   1 oracle   oinstall 10493952 Jan 25 21:18 sun01_1.dbf
-rw-r-----   1 oracle   oinstall 10493952 Jan 25 21:18 sun02_1.dbf
-rw-r-----   1 oracle   oinstall 5251072 Jan 25 21:18 sun03_1.dbf
-rw-r-----   1 oracle   oinstall 262152192 Jan 25 21:18 sysaux01.dbf
-rw-r-----   1 oracle   oinstall 503324672 Jan 25 21:18 system01.dbf
-rw-r-----   1 oracle   oinstall 20979712 Jan 23 04:03 temp01.dbf
-rw-r-----   1 oracle   oinstall 31465472 Jan 25 21:18 undotbs01.dbf
-rw-r-----   1 oracle   oinstall 5251072 Jan 25 21:18 users01.dbf
bash-3.00$ cp * /u01/backup/cold
bash-3.00$


1.3 在t表中插入数据

SQL> conn user1/user1
Connected.

SQL> select * from t;

ID NAME
---------- ----------------
1 oracle
2 oracle
0 oracle
3 oracle
4 oracle
5 oracle

6 rows selected.

SQL> insert into t values(6,'oracle');

1 row created.

SQL> commit;

Commit complete.

SQL>


1.4查看当前时间

SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,'YY
-------------------
2013-01-25 21:30:35

SQL>


1.5 模拟失误现场

SQL> drop table t;

Table dropped.

SQL>


恢复
2.1 关机

SQL> shutdown abort
ORACLE instance shut down.
SQL>


2.2还原以前备份的数据文件

bash-3.00$ pwd
/u01/oradata/sunbak
bash-3.00$ ls -l
total 2215712
-rw-r-----   1 oracle   oinstall 7389184 Jan 25 21:33 control01.ctl
-rw-r-----   1 oracle   oinstall 7389184 Jan 25 21:33 control02.ctl
-rw-r-----   1 oracle   oinstall 7389184 Jan 25 21:33 control03.ctl
-rw-r-----   1 oracle   oinstall 104865792 Jan 25 21:21 example01.dbf
-rw-r-----   1 oracle   oinstall 52429312 Jan 25 21:21 redo01.log
-rw-r-----   1 oracle   oinstall 52429312 Jan 25 21:33 redo02.log
-rw-r-----   1 oracle   oinstall 52429312 Jan 25 21:21 redo03.log
-rw-r-----   1 oracle   oinstall 10493952 Jan 25 21:30 sun01_1.dbf
-rw-r-----   1 oracle   oinstall 10493952 Jan 25 21:21 sun02_1.dbf
-rw-r-----   1 oracle   oinstall 5251072 Jan 25 21:21 sun03_1.dbf
-rw-r-----   1 oracle   oinstall 262152192 Jan 25 21:33 sysaux01.dbf
-rw-r-----   1 oracle   oinstall 503324672 Jan 25 21:33 system01.dbf
-rw-r-----   1 oracle   oinstall 20979712 Jan 23 04:03 temp01.dbf
-rw-r-----   1 oracle   oinstall 31465472 Jan 25 21:33 undotbs01.dbf
-rw-r-----   1 oracle   oinstall 5251072 Jan 25 21:21 users01.dbf
bash-3.00$ rm -f *.dbf
bash-3.00$ cd /u01/backup/cold/
bash-3.00$ cp *.dbf  /u01/oradata/sunbak/
bash-3.00$


2.3将数据库开到mount

SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.

Total System Global Area  289406976 bytes
Fixed Size                  1279820 bytes
Variable Size              92276916 bytes
Database Buffers          192937984 bytes
Redo Buffers                2912256 bytes
Database mounted.
SQL>


2.4对比控制文件与数据文件的SCN

#最新的控制文件
SQL> select file#,checkpoint_change# from v$datafile;

FILE# CHECKPOINT_CHANGE#
---------- ------------------
1             690924
2             690924
3             690924
4             690924
5             690924
6             690924
7             690924
8             690924

8 rows selected.

SQL>
#备份的数据文件
SQL> select file#,checkpoint_change# from v$datafile_header;

FILE# CHECKPOINT_CHANGE#
---------- ------------------
1             690923
2             690923
3             690923
4             690923
5             690923
6             690923
7             690923
8             690923

8 rows selected.

SQL>


2.5 恢复

1 SQL> recover database until time '2013-01-25:21:30:35';
Media recovery complete.
SQL>
4 SQL> alter database open resetlogs;

Database altered.

SQL>


3.查看t表

SQL> select * from user1.t order by 1;

ID NAME
---------- ----------------
0 oracle
1 oracle
2 oracle
3 oracle
4 oracle
5 oracle
6 oracle

7 rows selected.

SQL>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: