RMAN> run
2> {
3> set until time "to_date('2015-08-02:21:19:56','YYYY-MM-DD HH24:MI:SS')";
4> restore database;
5> recover database;
6> }
这样后台就会自动去完成还原和恢复的工作,恢复的部分日志如下:
starting media recovery
archive log thread 1 sequence 9 is already on disk as file /u02/oracle/flash_recovery_area/TEST10G/archivelog/2015_08_02/o1_mf_1_9_bvw5nrd2_.arc
archive log thread 1 sequence 10 is already on disk as file /u02/oracle/flash_recovery_area/TEST10G/archivelog/2015_08_02/o1_mf_1_10_bvw60std_.arc
archive log filename=/u02/oracle/flash_recovery_area/TEST10G/archivelog/2015_08_02/o1_mf_1_9_bvw5nrd2_.arc thread=1 sequence=9
archive log filename=/u02/oracle/flash_recovery_area/TEST10G/archivelog/2015_08_02/o1_mf_1_10_bvw60std_.arc thread=1 sequence=10
media recovery complete, elapsed time: 00:00:09
Finished recover at 02-AUG-15
就这样就轻松完成了时间点的恢复,使用resetlogs的方式打开数据库。
RMAN> alter database open resetlogs;
database opened
我们简单验证一下用户是否已经恢复回来。可以看到一切都在预料之中。
SQL> conn newtest/newtest
Connected.
SQL> select count(*)from t;
COUNT(*)
----------
6338
:
第二个例子是一个相对来说暴力的破坏,我们删除了所有的数据文件,日志文件,控制文件。然后尝试恢复。
先是破坏,我们到数据文件的目录下,删除全部文件
$ rm *
然后使用rman把数据库启动到nomount阶段,开始尝试恢复控制文件。
[oracle@oel1 TEST10G]$ rman target /
Recovery Manager: Release 10.2.0.3.0 - Production on Sun Aug 2 21:33:24 2015
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database (not started)
RMAN> startup nomount
Oracle instance started
Total System Global Area 314572800 bytes
Fixed Size 1261564 bytes
Variable Size 163577860 bytes
Database Buffers 142606336 bytes
Redo Buffers 7127040 bytes
这个时候查看rman的配置会发现,原有的配置都会丢失,因为我们删除了所有的数据。
RMAN> show all;
这个时候如果还原控制文件,指定autobackup就会报错,因为配置丢失,压根找不到备份的配置。
RMAN> restore controlfile from autobackup;
Starting restore at 02-AUG-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=34 devtype=DISK
recovery area destination: /u02/oracle/flash_recovery_area
database name (or database unique name) used for search: TEST10G
channel ORA_DISK_1: no autobackups found in the recovery area
autobackup search outside recovery area not attempted because DBID was not set
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 08/02/2015 21:33:49
RMAN-06172: no autobackup found or specified handle is not a valid copy or piece
这个时候,我们可以手工指定需要还原参照的控制文件备份即可。
比如我们在备份目录下看到最新的控制文件备份,直接应用还原。
RMAN> restore controlfile from '/u02/oracle/flash_recovery_area/TEST10G/ctl_c-1135735312-20150802-0b';
Starting restore at 02-AUG-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=38 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
output filename=/u02/oracle/oradata/TEST10G/control01.ctl
output filename=/u02/oracle/oradata/TEST10G/control02.ctl
Finished restore at 02-AUG-15
然后数据库启动到Mount阶段,开始还原和恢复数据库,
RMAN> run{
2> restore database;
3> recover database;
4> }
还原还是很平滑的过程,关键就在于恢复的过程,最后肯定会抛出一些问题来,类似下面的形式。
unable to find archive log
archive log thread=1 sequence=1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 08/02/2015 21:37:15
RMAN-06054: media recovery requesting unknown log: thread 1 seq 1 lowscn 1151365
这个时候我们就需要做不完全恢复,我们来采用基于sequence的恢复。
RMAN> run{
2> set until sequence 1;
3> recover database;
4> }
然后使用resetlogs的方式就可以打开数据库了。
RMAN> alter database open resetlogs;
database opened
这种方式也还是相对比较简单的过程。