Oracle恢复实验(一)
环境:Oracle10g、Red Hat 4,Oracle运行在归档模式。
模拟场景:user01.dbf数据文件损坏,关闭数据库条件下恢复。
具体步骤:
1、先做个全库冷备份,备份控制文件、数据文件、参数文件
SQL> select name from v$controlfile
2 union
3 select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/home/oracle/oracle/product/oradata/orcl/control01.ctl
/home/oracle/oracle/product/oradata/orcl/control02.ctl
/home/oracle/oracle/product/oradata/orcl/control03.ctl
/home/oracle/oracle/product/oradata/orcl/sysaux01.dbf
/home/oracle/oracle/product/oradata/orcl/system01.dbf
/home/oracle/oracle/product/oradata/orcl/undotbs01.dbf
/home/oracle/oracle/product/oradata/orcl/users01.dbf
7 rows selected.
也就是关库,备份上面几个文件,并且备份参数文件,口令文件可备可不备。
2、用scott用户登录,建个表,插入些数据。提交,检查一下数据行数。
SQL> conn scott/oracle
Connected.
SQL> create table recover_test tablespace users as select * from emp;
Table created.
SQL> insert into recover_test (select * from emp);
14 rows created.
SQL> insert into recover_test select * from recover_test;
56 rows created.
SQL> /
112 rows created.
SQL> /
224 rows created.
SQL> commit;
Commit complete.
SQL> select count (*) from recover_test;
COUNT(*)
----------
448
3、多做几次日志切换,这样有且于了解Oracle恢复的原理。
SQL> conn /as sysdba
Connected.
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
4、主机断电,删除user01.dbf,模拟数据文件损坏
SQL> shutdown abort
ORACLE instance shut down.
SQL> !rm -f /home/oracle/oracle/product/oradata/orcl/user01.dbf
5、尝试打开数据库
SQL> startup
ORACLE instance started.
Total System Global Area 130023424 bytes
Fixed Size 1218100 bytes
Variable Size 62917068 bytes
Database Buffers 62914560 bytes
Redo Buffers 2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/home/oracle/oracle/product/oradata/orcl/users01.dbf'
此时提示数据文件找不到。警告日志中可以看到更加详细的信息。
6、恢复数据文件,尝试打开数据库
SQL> !cp /disk2/bak/users01.dbf /home/oracle/oracle/product/oradata/orcl/
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 4 needs media recovery
ORA-01110: data file 4: '/home/oracle/oracle/product/oradata/orcl/users01.dbf'
此时由于数据库不一致,提示需要介质恢复。检查一下scn情况。
select 'scnOfDatafile',name,checkpoint_change# from v$datafile
union
select 'scnOfDatafileHeader',name,checkpoint_change# from v$datafile_header;
'SCNOFDATAFILE' NAME &nbs
相关新闻>>
- 发表评论
-
- 最新评论 更多>>