RMAN 命令行闪回数据库常用方法:
1) 基于时间(与在 SQLPLUS 下基于时间的闪回非常相似,只是格式稍有变化,就不重复测试了)
RMAN> FLASHBACK DATABASE TO TIME = "TO_DATE('2012-08-03
14:51:13','YYYY-MM-DDHH24:MI:SS')";
2) 基于 SCN(与在 SQLPLUS 下基于 SCN 的闪回非常相似,只是格式稍有变化,就不重复测试了)
RMAN> FLASHBACK DATABASE TO SCN=23565;
3) 基于:归档序号
RMAN> FLASHBACK DATABASE TO SEQUENCE=223 THREAD=1;
测试基于归档序号闪回数据库
1) 查看当前的日志序号为1
YS@ORA11GR2>archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 1
Next log sequence to archive 1
Current log sequence 1
2) 在 SCOTT 下创建测试表及插入一条记录,此时所产生的日志数据都存在序列号为1 的日志文件中
SYS@ORA11GR2>conn scott/tiger
Connected.
SCOTT@ORA11GR2>create table fbdb_rman_seq as select * from fbdb_scn where 1=2;
Table created.
SCOTT@ORA11GR2>insert into fbdb_rman_seq select 1 as id,dbms_flashback.get_system_change_number as scn,sysdate as dd from dual;
1 row created.
SCOTT@ORA11GR2>commit;
Commit complete.
SCOTT@ORA11GR2>select * from fbdb_rman_seq;
ID SCN DD
---------- ---------- ---------
1 1879882 01-OCT-16
3) 手工归档当前日志,归档后,当前日志的序号为 2
SYS@ORA11GR2>alter system switch logfile;(或者alter system archive log current)
System altered.
SYS@ORA11GR2>archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 1
Next log sequence to archive 2
Current log sequence 2
4) 再次向 scott.fbdb_rman_seq 插入一条记录,此时的日志信息都存在序号为 2 的日志文件中
SYS@ORA11GR2>insert into scott.fbdb_rman_seq select 2 as id,dbms_flashback.get_system_change_number as scn,sysdate as dd from dual;
1 row created.
SYS@ORA11GR2>commit;
Commit complete.
SYS@ORA11GR2>select * from scott.fbdb_rman_seq;
ID SCN DD
---------- ---------- ---------
1 1879882 01-OCT-16
2 1880119 01-OCT-16
--既然测试,就稍微狠点儿,把表彻底删除
SYS@ORA11GR2>drop table scott.fbdb_rman_seq;
Table dropped.
5) 恢复操作:登陆 RMAN 将数据库启动到 mount 模式下(在 SQLPLUS 下执行这步也是一样的)
[oracle@wang admin]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Sat Oct 1 09:02:45 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORA11GR2 (DBID=237843809)
RMAN> shutdown immediate;
using target database control file instead of recovery catalog
database closed
database dismounted
Oracle instance shut down
RMAN> startup mount;
connected to target database (not started)
Oracle instance started
database mounted
Total System Global Area 730714112 bytes
Fixed Size 2256832 bytes
Variable Size 452984896 bytes
Database Buffers 272629760 bytes
Redo Buffers 2842624 bytes
6) 在 RMAN 命令行下执行闪回,基于序号为 1的归档, 1 号线程
RMAN> flashback database to sequence =1 thread=1;
Starting flashback at 01-OCT-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished flashback at 01-OCT-16
7) 以 resetlogs 方式打开数据库
RMAN> alter database open resetlogs;
database opened
8) 回到 SQLPLUS 验证测试表fbdb_rman_seq
SYS@ORA11GR2>select * from scott.fbdb_rman_seq;
ID SCN DD
---------- ---------- ---------
1 1879882 01-OCT-16
注意事项
1) 当闪回数据库操作完成后,打开数据库:
- 在只读模式下验证是否使用了正确的目标时间或 SCN。
- 使用 RESETLOGS 选项以允 DML 操作。
2) 与“闪回”相反的是“恢复”。
3) 在下列情况下,您不能使用闪回数据库:
- 已恢复或重建控制文件。
- 表空间被删除。
- 数据文件已被减小尺寸。
4) 使用 TO BEFORE RESETLOGS 子句闪回到最后一次 RESETLOGS 操作。