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
SYS@PROD1>archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/backup
Oldest online log sequence 1
Next log sequence to archive 1
Current log sequence 1
2.在SCOTT下创建测试表及插入一条记录,此时所产生的日志数据都存在序列号为1的日志文件中
SCOTT@PROD1>create table fbdb_rman_seq as select * from fbdb_scn where 1=2;
Table created.
SCOTT@PROD1>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@PROD1>commit;
Commit complete.
SCOTT@PROD1>select * from fbdb_rman_seq;
ID SCN DD
---------- ---------- -------------------
1 1252223 2016-12-31 18:21:15
3.手工归档当前日志,归档后,当前日志的序号为2
SYS@PROD1>archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/backup
Oldest online log sequence 1
Next log sequence to archive 1
Current log sequence 1
SYS@PROD1>alter system switch logfile; (或者alter system archive log current)
System altered.
SYS@PROD1>archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/backup
Oldest online log sequence 1
Next log sequence to archive 2
Current log sequence 2
4.再次向scott.fbdb_rman_seq插入一条记录,此时的日志信息都存在序号为2的日志文件中
SYS@PROD1>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@PROD1>commit;
Commit complete.
SYS@PROD1>select * from scott.fbdb_rman_seq;
ID SCN DD
---------- ---------- -------------------
2 1252322 2016-12-31 18:24:23
1 1252223 2016-12-31 18:21:15
既然测试,就稍微狠点儿,把表彻底删除
SYS@PROD1>drop table scott.fbdb_rman_seq;
Table dropped.
5.恢复操作:登陆RMAN将数据库启动到mount模式下(在SQLPLUS下执行这步也是一样的)
SYS@PROD1>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@PROD1>startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 520096848 bytes
Database Buffers 310378496 bytes
Redo Buffers 2371584 bytes
Database mounted.
[oracle@host01 ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Sat Dec 31 18:30:03 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD1 (DBID=2148633869, not open)
6.在RMAN命令行下执行闪回,基于序号为1的归档,1号线程
RMAN> flashback database to sequence =1 thread=1;
Starting flashback at 31-DEC-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=21 device type=DISK
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished flashback at 31-DEC-16
7.以resetlogs方式打开数据库
SYS@PROD1>alter database open resetlogs;
Database altered.
8.回到SQLPLUS验证测试表fbdb_rman_seq
SYS@PROD1>select * from scott.fbdb_rman_seq;
ID SCN DD
---------- ---------- -------------------
1 1252223 2016-12-31 18:21:15
注意事项
1)当闪回数据库操作完成后,打开数据库:
在只读模式下验证是否使用了正确的目标时间或 SCN。
使用RESETLOGS选项以允DML操作。
2)与"闪回"相反的是"恢复"。
3)在下列情况下,您不能使用闪回数据库:
已恢复或重建控制文件。
表空间被删除。
数据文件已被减小尺寸。
4)使用TO BEFORE RESETLOGS 子句闪回到最后一次RESETLOGS操作。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31400681/viewspace-2131733/
,如需转载,请注明出处,否则将追究法律责任。