己亥清爽系列说明:清爽系列是作为恢复系列的基础篇,基于FS(File System)文件系统的手工还原恢复,也叫基于用户管理的还原恢复,来自于博客园AskScuti。
实验说明:物理删除非关键系统数据文件,模拟介质损坏或丢失,且在无备份的情况下,如何进行手工完全还原恢复操作。注:控制文件、在线日志和归档日志都完整的情况下。
基于版本:Oracle 11gR2 11.2.0.4 AskScuti
概念说明:请严格区分什么叫还原(Restore),什么叫恢复(Recover)。
还原(Restore):如果是基于用户管理(手工)的还原恢复,需要用户主动在系统层面进行拷贝粘贴,这个操作过程称之为还原;如果是基于恢复管理器(RMAN)的恢复,则通过Restore命令进行还原(自动进行),后者不在基础篇讨论。
恢复(Recover):在完成还原动作之后,数据回到了还原点,但从这个还原点到宕机时间点之间的数据,就要利用归档日志和在线日志进行前滚,直至应用到宕机前最后一次commit提交的状态(完全恢复),或应用到指定的某个时间点(不完全恢复)。
目录
1. 备份(略)
2. 实验
2.1 查询确认当前数据
2.2 物理删除数据文件
2.3 继续插入数据并提交
2.4 切换日志或重启
2.5 先启库再修复
2.5.1 将错误文件脱机并启动数据库
2.5.2 重建数据文件
2.5.3 恢复数据文件
2.5.4 将数据文件联机
2.5.5 验证数据
2.6 先修复再启库
2.6.1 重建数据文件
2.6.2 恢复数据文件
2.6.3 打开数据库
2.6.4 验证数据
1. 备份(略)
不是说好了无备份恢复吗?是的,只是怕你搞叉劈了,所以你还是备一下吧。点此处查看如何进行简单的手工冷备。这个实验和之前的第2篇实验对比着看,总结有什么不同?
2. 实验
2.1 查询确认当前数据
实验数据接第2篇实验。
SQL> delete from henry; 58 rows deleted. SQL> commit; Commit complete. SQL> select count(*) from henry; COUNT(*) ---------- 0 SQL> insert into henry values(1); 1 row created. SQL> insert into henry values(2); 1 row created. SQL> insert into henry values(3); 1 row created. SQL> commit; Commit complete. SQL> select count(*) from henry; COUNT(*) ---------- 3
2.2 物理删除数据文件
SQL> !rm -rf /u01/app/oracle/oradata/PROD1/henry01.dbf SQL> !ls /u01/app/oracle/oradata/PROD1/ control01.ctl example01.dbf redo01.log redo02.log redo03.log sysaux01.dbf system01.dbf temp01.dbf undotbs01.dbf users01.dbf
2.3 继续插入数据并提交
SQL> insert into henry values(4); 1 row created. SQL> insert into henry values(5); 1 row created. SQL> insert into henry values(6); 1 row created. SQL> commit; Commit complete. SQL> insert into henry values(7); 1 row created.
2.4 切换日志或重启
SQL> alter system switch logfile; System altered. SQL> / System altered. SQL> / alter system switch logfile * ERROR at line 1: ORA-03113: end-of-file on communication channel Process ID: 3157 Session ID: 1 Serial number: 5
这里可以选择触发完全检查点报错,也可以多次切换日志报错,也可以重启数据库报错。这里涉及到一个在线日志的理论,你可能会问,为什么切换日志会报错?这里先记着,后面博文单独介绍,完成后链接更新在此处。
2.5 先启库再修复
2.5.1 将错误文件脱机并启动数据库
SQL> startup ORACLE instance started. Total System Global Area 417546240 bytes Fixed Size 2228944 bytes Variable Size 293604656 bytes Database Buffers 117440512 bytes Redo Buffers 4272128 bytes Database mounted. ORA-01157: cannot identify/lock data file 6 - see DBWR trace file ORA-01110: data file 6: ‘/u01/app/oracle/oradata/PROD1/henry01.dbf‘ SQL> alter database datafile 6 offline; Database altered. SQL> alter database open; Database altered.
2.5.2 重建数据文件
因为该数据文件没有备份,但是控制文件和日志文件、归档文件完整,通过控制文件重建数据文件,通过归档日志和在线日志,将数据前滚出来。
SQL> alter database create datafile 6; Database altered. SQL> !ls /u01/app/oracle/oradata/PROD1/ control01.ctl example01.dbf henry01.dbf redo01.log redo02.log redo03.log sysaux01.dbf system01.dbf temp01.dbf undotbs01.dbf users01.dbf
2.5.3 恢复数据文件
SQL> recover datafile 6; ORA-00279: change 1288523 generated at 05/17/2019 17:31:53 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_15_gfx0kl q8_.arc ORA-00280: change 1288523 for thread 1 is in sequence #15 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} auto ORA-00279: change 1309022 generated at 05/17/2019 17:43:14 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_16_gfx1mx m6_.arc ORA-00280: change 1309022 for thread 1 is in sequence #16 ORA-00279: change 1329816 generated at 05/17/2019 18:01:33 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_17_gfxflk 6g_.arc ORA-00280: change 1329816 for thread 1 is in sequence #17 ORA-00279: change 1353859 generated at 05/17/2019 21:25:35 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_18_gfxg44 dn_.arc ORA-00280: change 1353859 for thread 1 is in sequence #18 ORA-00279: change 1354479 generated at 05/17/2019 21:34:59 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_19_gfxg46 1o_.arc ORA-00280: change 1354479 for thread 1 is in sequence #19 ORA-00279: change 1354482 generated at 05/17/2019 21:35:01 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_20_gfxg48 21_.arc ORA-00280: change 1354482 for thread 1 is in sequence #20 ORA-00279: change 1354485 generated at 05/17/2019 21:35:03 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_21_gfxg49 94_.arc ORA-00280: change 1354485 for thread 1 is in sequence #21 ORA-00279: change 1354488 generated at 05/17/2019 21:35:05 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_22_gfxg4t g3_.arc ORA-00280: change 1354488 for thread 1 is in sequence #22 ORA-00279: change 1374493 generated at 05/17/2019 21:35:22 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_23_gfxg8r m0_.arc ORA-00280: change 1374493 for thread 1 is in sequence #23 ORA-00279: change 1374793 generated at 05/17/2019 21:37:28 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_24_gfxg8s pl_.arc ORA-00280: change 1374793 for thread 1 is in sequence #24 ORA-00279: change 1374796 generated at 05/17/2019 21:37:29 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_25_gfxgf9 s2_.arc ORA-00280: change 1374796 for thread 1 is in sequence #25 ORA-00279: change 1394799 generated at 05/17/2019 21:39:53 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_26_gfxj43 y1_.arc ORA-00280: change 1394799 for thread 1 is in sequence #26 Log applied. Media recovery complete.
The recovery process
因为我们归档完整,所以直接 AUTO 即可,也可以手工指定具体的归档文件,如果恢复到最后一个归档,提示没有,那么说明数据库要的这个文件应该属于在线日志,因为在线日志里面有需要恢复的数据。
2.5.4 将数据文件联机
SQL> select file#,name,status from v$datafile; FILE# NAME STATUS ---------- ------------------------------------------------------- ---------- 1 /u01/app/oracle/oradata/PROD1/system01.dbf SYSTEM 2 /u01/app/oracle/oradata/PROD1/sysaux01.dbf ONLINE 3 /u01/app/oracle/oradata/PROD1/undotbs01.dbf ONLINE 4 /u01/app/oracle/oradata/PROD1/users01.dbf ONLINE 5 /u01/app/oracle/oradata/PROD1/example01.dbf ONLINE 6 /u01/app/oracle/oradata/PROD1/henry01.dbf OFFLINE 6 rows selected. SQL> alter database datafile 6 online; Database altered. SQL> select file#,name,status from v$datafile; FILE# NAME STATUS ---------- ------------------------------------------------------- ---------- 1 /u01/app/oracle/oradata/PROD1/system01.dbf SYSTEM 2 /u01/app/oracle/oradata/PROD1/sysaux01.dbf ONLINE 3 /u01/app/oracle/oradata/PROD1/undotbs01.dbf ONLINE 4 /u01/app/oracle/oradata/PROD1/users01.dbf ONLINE 5 /u01/app/oracle/oradata/PROD1/example01.dbf ONLINE 6 /u01/app/oracle/oradata/PROD1/henry01.dbf ONLINE 6 rows selected.
2.5.5 验证数据
SQL> select count(*) from henry; COUNT(*) ---------- 6
因为2.3小节在插入数据的时候,7 没有被提交,所以回滚掉,只有6行数据。
2.6 先修复再启库
2.6.1 重建数据文件
SQL> !rm -rf /u01/app/oracle/oradata/PROD1/henry01.dbf SQL> !ls /u01/app/oracle/oradata/PROD1/ control01.ctl example01.dbf redo01.log redo02.log redo03.log sysaux01.dbf system01.dbf temp01.dbf undotbs01.dbf users01.dbf SQL> startup force ORACLE instance started. Total System Global Area 417546240 bytes Fixed Size 2228944 bytes Variable Size 293604656 bytes Database Buffers 117440512 bytes Redo Buffers 4272128 bytes Database mounted. ORA-01157: cannot identify/lock data file 6 - see DBWR trace file ORA-01110: data file 6: ‘/u01/app/oracle/oradata/PROD1/henry01.dbf‘ SQL> alter database create datafile 6; Database altered.
2.6.2 恢复数据文件
2.5章节的恢复,使用的是 AUTO,本小节使用手工指定文件,观察有何差异?
SQL> recover datafile 6; ORA-00279: change 1288523 generated at 05/17/2019 17:31:53 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_15_gfx0klq8_.arc ORA-00280: change 1288523 for thread 1 is in sequence #15 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_15_gfx0klq8_.arc ORA-00279: change 1309022 generated at 05/17/2019 17:43:14 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_16_gfx1mxm6_.arc ORA-00280: change 1309022 for thread 1 is in sequence #16 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_16_gfx1mxm6_.arc ORA-00279: change 1329816 generated at 05/17/2019 18:01:33 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_17_gfxflk6g_.arc ORA-00280: change 1329816 for thread 1 is in sequence #17 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_17_gfxflk6g_.arc ORA-00279: change 1353859 generated at 05/17/2019 21:25:35 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_18_gfxg44dn_.arc ORA-00280: change 1353859 for thread 1 is in sequence #18 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_18_gfxg44dn_.arc ORA-00279: change 1354479 generated at 05/17/2019 21:34:59 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_19_gfxg461o_.arc ORA-00280: change 1354479 for thread 1 is in sequence #19 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_19_gfxg461o_.arc ORA-00279: change 1354482 generated at 05/17/2019 21:35:01 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_20_gfxg4821_.arc ORA-00280: change 1354482 for thread 1 is in sequence #20 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_20_gfxg4821_.arc ORA-00279: change 1354485 generated at 05/17/2019 21:35:03 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_21_gfxg4994_.arc ORA-00280: change 1354485 for thread 1 is in sequence #21 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_21_gfxg4994_.arc ORA-00279: change 1354488 generated at 05/17/2019 21:35:05 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_22_gfxg4tg3_.arc ORA-00280: change 1354488 for thread 1 is in sequence #22 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_22_gfxg4tg3_.arc ORA-00279: change 1374493 generated at 05/17/2019 21:35:22 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_23_gfxg8rm0_.arc ORA-00280: change 1374493 for thread 1 is in sequence #23 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} ORA-00279: change 1374793 generated at 05/17/2019 21:37:28 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_24_gfxg8spl_.arc ORA-00280: change 1374793 for thread 1 is in sequence #24 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_24_gfxg8spl_.arc ORA-00279: change 1374796 generated at 05/17/2019 21:37:29 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_25_gfxgf9s2_.arc ORA-00280: change 1374796 for thread 1 is in sequence #25 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_25_gfxgf9s2_.arc ORA-00279: change 1394799 generated at 05/17/2019 21:39:53 needed for thread 1 ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_26_gfxj43y1_.arc ORA-00280: change 1394799 for thread 1 is in sequence #26 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} /u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_05_17/o1_mf_1_26_gfxj43y1_.arc Log applied. Media recovery complete.
The recovery process
2.6.3 打开数据库
SQL> alter database open; Database altered.
2.6.4 验证数据
SQL> select count(*) from henry; COUNT(*) ---------- 6
原文地址:https://www.cnblogs.com/askscuti/p/jhqs03.html