场景案例1:
数据文件手工备份 – 创建了表空间 – 备份了控制文件 – 当前控制文件损坏,新创建的表空间数据文件损坏,归档模式,日志都可用(手工备份中没有该表空间的备份)
案例环境部署:
SYS@prod>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
手工备份数据文件:
[oracle@service3 prod]$ cp *.dbf /u01/backup/
SYS@prod>startup;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 490736720 bytes
Database Buffers 335544320 bytes
Redo Buffers 6565888 bytes
Database mounted.
Database opened.
创建一个表空间:
SYS@prod>create tablespace test datafile ‘/u01/app/oracle/oradata/prod/test.dbf’ size 50M;
在表空间上建表:
SYS@prod>create table test tablespace test as select * from hr.employees;
备份控制文件:
SYS@prod>alter database backup controlfile to ‘/u01/backup/con.ctl’;
开始破坏数据文件,控制文件:
[oracle@service3 prod]$ cp /etc/passwd control01.ctl
[oracle@service3 prod]$ cp /etc/passwd test.dbf
[oracle@service3 prod]$ cp /etc/passwd /u01/app/oracle/fast_recovery_area/prod/control02.ctl
SYS@prod>alter system switch logfile;
alter system switch logfile
*
ERROR at line 1:
ORA-03113: end-of-file on communication channel
Process ID: 5790
Session ID: 125 Serial number: 9
开始恢复:
使用备份的控制文件恢复:
[oracle@service3 prod]$ cp /u01/backup/con.ctl control01.ctl
[oracle@service3 prod]$ cp control01.ctl /u01/app/oracle/fast_recovery_area/prod/control02.ctl
SYS@prod>startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 490736720 bytes
Database Buffers 335544320 bytes
Redo Buffers 6565888 bytes
Database mounted.
SYS@prod>alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 6 – see DBWR trace file
ORA-01110: data file 6: ‘/u01/app/oracle/oradata/prod/test.dbf’
创建一个空的数据文件让控制文件识别该数据文件已存在:
SYS@prod>alter database create datafile 6 as ‘/u01/app/oracle/oradata/prod/test.dbf’;
Database altered.
使用备份的控制文件进行recover时,
需要加上using backup controlfile。
SYS@prod>recover database using backup controlfile;
ORA-00279: change 1196472 generated at 05/12/2020 22:24:02 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/fast_recovery_area/PROD/archivelog/2020_05_12/o1_mf_1_28_%u_.arc
ORA-00280: change 1196472 for thread 1 is in sequence #28
Specify log: {=suggested | filename | AUTO | CANCEL}
auto
ORA-00308: cannot open archived log
‘/u01/app/oracle/fast_recovery_area/PROD/archivelog/2020_05_12/o1_mf_1_28_%u_.ar
c’
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
查看一下28号日志文件的情况:
SYS@prod>select group#,sequence#,status from v$log;
GROUP# SEQUENCE# STATUS
1 28 CURRENT3 27 INACTIVE2 26 INACTIVE
再执行一下recover 指定当前日志文件名:
SYS@prod>recover database using backup controlfile;
ORA-00279: change 1196472 generated at 05/12/2020 22:24:02 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/fast_recovery_area/PROD/archivelog/2020_05_12/o1_mf_1_28_%u_.arc
ORA-00280: change 1196472 for thread 1 is in sequence #28
Specify log: {=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/oradata/prod/redo01.log
Log applied.
Media recovery complete.
SYS@prod>alter database open resetlogs;
进行恢复校验:
SYS@prod>select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME STATUS
SYSTEM ONLINE
SYSAUX ONLINE
UNDOTBS1 ONLINE
TEMP ONLINE
USERS ONLINE
EXAMPLE ONLINE
TEST ONLINE
SYS@prod>select count(*) from test;
107
恢复成功。