**误删SYSTEM数据文件,(介质恢复) **
1、概念
实例恢复:其他是数据文件、控制文件和在线日志均没有损坏,局限性很明显。
介质恢复:在文件有物理损坏的情况下,将其还原、恢复,最后使得数据库正常打开。
介质恢复的条件:
归档模式
有可用的备份将数据文件恢复出来
有可用的归档日志(序列号必须完整连续)
2、删除数据文件
再次之前需要将数据文件备份,这里我使用的备份方法是简单的rman copy。
[oracle@rac1 ~]$ rman target /
......
RMAN> copy datafile 1 to '/home/oracle/backup/system.dbf';
Starting backup at 01-SEP-19
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=34 instance=rac1 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=+DATA/rac11g/datafile/system.dbf
output file name=/home/oracle/system.dbf tag=TAG20190901T230907 RECID=4 STAMP=1017875370
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
Finished backup at 01-SEP-19
删除数据文件
rm -rf +DATA/rac11g/datafile/SYSTEM.256.1016202643
**启动数据库报错ora-01157、ora-01110
SYS@rac1>startup
ORACLE instance started.
Total System Global Area 1970864128 bytes
Fixed Size 2254544 bytes
Variable Size 855640368 bytes
Database Buffers 1107296256 bytes
Redo Buffers 5672960 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '+DATA/rac11g/datafile/system.256.1016202643'
3、进行介质恢复
查看数据库状态
SYS@rac1>select status from v$instance;
STATUS
------------
MOUNTED
将备份集catalog到RMAN备份记录中去
RMAN> catalog start with '/home/oracle/backup/';
searching for all files that match the pattern /home/oracle/backup/
List of Files Unknown to the Database
=====================================
File Name: /home/oracle/backup/system.dbf
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /home/oracle/backup/system.dbf
从备份中还原数据文件
RMAN> restore datafile 1;
Starting restore at 01-SEP-19
using channel ORA_DISK_1
channel ORA_DISK_1: restoring datafile 00001
input datafile copy RECID=3 STAMP=1017872039 file name=/home/oracle/backup/system.dbf
destination for restore of datafile 00001: +DATA/rac11g/datafile/system.dbf
channel ORA_DISK_1: copied datafile copy of datafile 00001
output file name=+DATA/rac11g/datafile/system.dbf RECID=0 STAMP=0
Finished restore at 01-SEP-19
恢复数据文件(应用日志)
RMAN> recover datafile 1;
Starting recover at 01-SEP-19
using channel ORA_DISK_1
starting media recovery
archived log for thread 1 with sequence 49 is already on disk as file +FRA/rac11g/archivelog/2019_09_01/thread_1_seq_49.352.1017863403
archived log for thread 1 with sequence 50 is already on disk as file +FRA/rac11g/archivelog/2019_09_01/thread_1_seq_50.353.1017863405
archived log for thread 1 with sequence 51 is already on disk as file +FRA/rac11g/archivelog/2019_09_01/thread_1_seq_51.354.1017863405
archived log for thread 1 with sequence 52 is already on disk as file +FRA/rac11g/archivelog/2019_09_01/thread_1_seq_52.355.1017863405
archived log for thread 1 with sequence 53 is already on disk as file +FRA/rac11g/archivelog/2019_09_01/thread_1_seq_53.356.1017863405
archived log for thread 1 with sequence 54 is already on disk as file +FRA/rac11g/archivelog/2019_09_01/thread_1_seq_54.357.1017863405
archived log for thread 2 with sequence 48 is already on disk as file +FRA/rac11g/archivelog/2019_09_01/thread_2_seq_48.358.1017863407
archived log for thread 2 with sequence 49 is already on disk as file +FRA/rac11g/archivelog/2019_09_01/thread_2_seq_49.359.1017863491
archived log for thread 2 with sequence 50 is already on disk as file +FRA/rac11g/archivelog/2019_09_01/thread_2_seq_50.360.1017870643
archived log file name=+FRA/rac11g/archivelog/2019_09_01/thread_1_seq_49.352.1017863403 thread=1 sequence=49
archived log file name=+FRA/rac11g/archivelog/2019_09_01/thread_2_seq_48.358.1017863407 thread=2 sequence=48
archived log file name=+FRA/rac11g/archivelog/2019_09_01/thread_1_seq_50.353.1017863405 thread=1 sequence=50
archived log file name=+FRA/rac11g/archivelog/2019_09_01/thread_1_seq_51.354.1017863405 thread=1 sequence=51
archived log file name=+FRA/rac11g/archivelog/2019_09_01/thread_1_seq_52.355.1017863405 thread=1 sequence=52
archived log file name=+FRA/rac11g/archivelog/2019_09_01/thread_1_seq_53.356.1017863405 thread=1 sequence=53
media recovery complete, elapsed time: 00:00:00
Finished recover at 01-SEP-19
到这里成功完成数据文件的恢复,然后我们来试试能不能打开数据库。
SYS@rac1>alter database open;
Database altered.
没有报错,成功完成利用备份和归档日志的介质恢复。