Rman恢复-Restore和Recovery的区别

Restore和Recovery的区别

Restoration: A corrupted data file is overwritten from a backup of the data file .The data file is at a prior point of time than the current database.

Recovery: Recovery applies the changes to the individual blocks,using archive and redo information,to move the database forward to the current point in time.

从原理上解释,Restore是使用备份文件,将数据库还原到过去的某个状态。

Recovery是使用redo日志和归档日志将数据库向前恢复,一步步的恢复到现在这个时点。

举个例子
某生产环境的数据库,每天凌晨一点会作一次备份。某天下午两点时数据库文件损害,同时数据库宕机。
接着DBA开始恢复数据库。

1.首先,使用最近一次的备份文件还原数据库到当天凌晨一点的状态。但是凌晨一点到下午两点的数据丢失了。
2.接着,使用redo日志和归档日志,把当天凌晨一点开始的数据库操作重做一遍,直到下午两点数据库宕机前。
这样数据库就一点都不差的被恢复起来了。

操作步骤

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#设置表空间为offline
RMAN> SQL 'alter tablespace tab01 offline immediate';
sql statement: alter tablespace tab01 offline immediate
#Restore还原物理文件
RMAN> restore tablespace tab01;
Starting restore at 30-DEC-16
using channel ORA_DISK_1
skipping datafile 5; already restored to file /home/oracle/app/oracle/oradata/mmpdb3/tab01.dbf
restore not done; all files read only, offline, or already restored
Finished restore at 30-DEC-16
#Recover恢复数据
RMAN> recover tablespace tab01;
Starting recover at 30-DEC-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00005: /home/oracle/app/oracle/oradata/mmpdb3/tab01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/dbbak/rman/mmpdb3_level_1_database_MMPDB3_20161229_328
channel ORA_DISK_1: piece handle=/home/oracle/dbbak/rman/mmpdb3_level_1_database_MMPDB3_20161229_328 tag=TAG20161229T230036
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 30-DEC-16
#设置表空间为online
RMAN> SQL 'alter tablespace tab01 online';
sql statement: alter tablespace tab01 online