条件:
1、归档模式下;
2、拥有全备份
3、拥有自上次全备份以来的所有日志文件--归档日志和当前在线日志
一、事先对数据库做个冷备份
我放到了$ORACLE_BASE/oradata/bak/目录下
二、对数据文件进行更新
SQL> create tablespace test datafile '/oracle/app/oracle/oradata/orcl/test.dbf' size 5m;
Tablespace created.
SQL> create table test tablespace test as select * from dba_users;
Table created.
SQL> alter system switch logfile;
System altered.
SQL> conn lijie/lijieoo1;
Connected.
SQL> create table lijie as select * from all_tables;
Table created.
SQL> select count(*) from lijie;
COUNT(*)
----------
1585
SQL> alter system switch logfile;
System altered.
SQL> shutdown abort;
三、模拟数据文件全部丢失
[oracle@localhost orcl]$ mkdir bak_new
[oracle@localhost orcl]$ mv test.dbf bak_new/ -- 移动新添加的数据文件到 bak_new 目录
[oracle@localhost orcl]$ mkdir bak_new_all
[oracle@localhost orcl]$ ls
archive control01.ctl control02.ctl.mv example01.dbf redo01.log redo02.log redo04.rdo temp01.dbf undo01.dbf users01.dbf
bak_new control01.ctl.mv control03.ctl lijie.dbf redo02_2.log redo02.log.mv sysaux01.dbf temp_tablespace1.dbf undo02.dbf
bak_new_all control02.ctl control03.ctl.mv lijie_temp1.dbf redo02_3.log redo03.log system01.dbf temp_tablespace1.dbf.mv undotbs01.dbf
[oracle@localhost orcl]$ mv *.* bak_new_all/ --移动再实现备份中已存在的文件到bak_new_all目录
[oracle@localhost orcl]$ ls
archive bak_new bak_new_all
[oracle@localhost orcl]$
[oracle@localhost orcl]$ mv *.* $ORACLE_BASE/oradata/orcl/ --把事先已备份的数据文件给还原回原位
四、恢复
SQL> startup mount;
ORA-32004: obsolete and/or deprecated parameter(s) specified
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 1218316 bytes
Variable Size 79694068 bytes
Database Buffers 83886080 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 1540020 generated at 03/19/2010 07:17:13 needed for thread 1
ORA-00289: suggestion :
/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2010_03_19/o1_mf_1_2_%u_.
arc
ORA-00280: change 1540020 for thread 1 is in sequence #2
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00283: recovery session canceled due to errors
ORA-01244: unnamed datafile(s) added to control file by media recovery
ORA-01110: data file 11: '/oracle/app/oracle/oradata/orcl/test.dbf'
ORA-01112: media recovery not started
SQL> alter database create datafile '/oracle/app/oracle/10.2.0.1/db_1/dbs/UNNAMED00011' as '/oracle/app/oracle/oradata/orcl/test01.dbf';
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 1540272 generated at 03/19/2010 07:37:37 needed for thread 1
ORA-00289: suggestion :
/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2010_03_19/o1_mf_1_4_%u_.
arc
ORA-00280: change 1540272 for thread 1 is in sequence #4
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/oracle/app/oracle/oradata/orcl/bak_new_all/redo04.rdo
ORA-00310: archived log contains sequence 3; sequence 4 required
ORA-00334: archived log:
'/oracle/app/oracle/oradata/orcl/bak_new_all/redo04.rdo'
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 1540272 generated at 03/19/2010 07:37:37 needed for thread 1
ORA-00289: suggestion :
/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2010_03_19/o1_mf_1_4_%u_.
arc
ORA-00280: change 1540272 for thread 1 is in sequence #4
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/oracle/app/oracle/oradata/orcl/bak_new_all/redo02_2.log
Log applied.
Media recovery complete.
SQL> alter database open resetlogs;
Database altered.
SQL> conn lijie/lijieoo1;
Connected.
SQL> select count(*) from lijie; --数据恢复成功
COUNT(*)
----------
1585