Oracle 学习之RMAN(十四)恢复实战--基于时间点恢复
admin
2023-05-08 16:42:07
0

1. 我们先做一个全备

RMAN> backup database ;

Starting backup at 2015/07/09 13:40:47
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=28 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/devdb/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/devdb/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/devdb/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/devdb/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/devdb/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2015/07/09 13:40:48
channel ORA_DISK_1: finished piece 1 at 2015/07/09 13:42:34
piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T134048_bsw2c0xq_.bkp tag=TAG20150709T134048 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:46
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 2015/07/09 13:42:35
channel ORA_DISK_1: finished piece 1 at 2015/07/09 13:42:36
piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_ncsnf_TAG20150709T134048_bsw2gcly_.bkp tag=TAG20150709T134048 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2015/07/09 13:42:36

2. 创建一个表,往里面插入一些数据。记录下时间,等待一会再将表truncate。

SQL> alter user scott account unlock;

User altered.

SQL> alter user scott identified by tiger;

User altered.

SQL> conn scott/tiger
Connected.
SQL> select sysdate from dual;

SYSDATE
-------------------
2015/07/09 13:44:30

SQL> create table t1 as select * from emp;

Table created.

SQL> select sysdate from dual;

SYSDATE
-------------------
2015/07/09 13:45:32

SQL> truncate table t1;

Table truncated.

在2015/07/09 13:45:32以前,表t1中有14条数据。之后做了truncate。我们现在来看看能不能将数据库恢复到2015/07/09 13:45:32这一时刻。也就是t1被truncate掉之前。

3. 关闭数据库,再启动到mount状态

SQL> conn / as sysdba
Connected.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  839282688 bytes
Fixed Size		    2233000 bytes
Variable Size		  494931288 bytes
Database Buffers	  339738624 bytes
Redo Buffers		    2379776 bytes
Database mounted.


4. 恢复数据库

RMAN> RUN {
  ALLOCATE CHANNEL c1 TYPE DISK;
  ALLOCATE CHANNEL c2 TYPE DISK;
  SET UNTIL TIME = '2015/07/09 13:45:32';
  RESTORE DATABASE;
  RECOVER DATABASE;
  ALTER DATABASE OPEN RESETLOGS;
 }2> 3> 4> 5> 6> 7> 8> 

using target database control file instead of recovery catalog
allocated channel: c1
channel c1: SID=20 device type=DISK

allocated channel: c2
channel c2: SID=21 device type=DISK

executing command: SET until clause

Starting restore at 2015/07/09 13:50:59

channel c1: starting datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
channel c1: restoring datafile 00001 to /u01/app/oracle/oradata/devdb/system01.dbf
channel c1: restoring datafile 00002 to /u01/app/oracle/oradata/devdb/sysaux01.dbf
channel c1: restoring datafile 00003 to /u01/app/oracle/oradata/devdb/undotbs01.dbf
channel c1: restoring datafile 00004 to /u01/app/oracle/oradata/devdb/users01.dbf
channel c1: restoring datafile 00005 to /u01/app/oracle/oradata/devdb/example01.dbf
channel c1: reading from backup piece /u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T134048_bsw2c0xq_.bkp
channel c1: piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T134048_bsw2c0xq_.bkp tag=TAG20150709T134048
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:01:15
Finished restore at 2015/07/09 13:52:14

Starting recover at 2015/07/09 13:52:15

starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished recover at 2015/07/09 13:52:16

database opened
released channel: c1
released channel: c2


5. 验证数据是否存在。

SQL> conn scott/tiger 
Connected.
SQL> select count(*) from t1;

  COUNT(*)
----------
	14

SQL>

可见数据已经找回。

基于时间点的恢复,是不完全恢复的一种,我们还可以基于SCN和日志sequence恢复。

UNTIL SEQUENCE or UNTIL SCN


相关内容

热门资讯

特稿|拉长合作清单 贡献建设性... 新华社北京5月13日电 题:拉长合作清单 贡献建设性力量——美国商学界人士瞩望美中经贸关系互利共赢新...
中国量子计算新突破!“九章四号... 记者从中国科学技术大学获悉,由该校潘建伟院士领衔的科研团队联合国内多家科研机构、大学,近期成功研制出...
跳河救人的外卖小哥找到了! 外... 5月12日下午5时许,漯河市郾城区孟庙镇幸福渠河堤旁,57岁的甘女士蹲在河边打水,准备回家给鱼换水,...
今年以来,越来越多美国交流团来... 4月,数十名美国犹他州青少年来豫参加2026年YES项目交流活动。图为美国青少年在郑州体验书法项目。...
“打工机器人”亮相郑州街头 机器人服务员“小盖”在郑州街边的一零售店工作。 王磊 摄机器人当服务员,在街头卖咖啡——这不是科幻电...
打响“河南服务”品牌丨盾构机有... 【开栏的话】为深入贯彻落实全省服务业大会精神,本报即日起开设“打响‘河南服务&rsquo...
一季度我国数字产业收入9.5万... 【大河财立方消息】5月14日,工信部发布的数据显示,一季度,我国数字产业实现良好开局,行业利润大幅改...
一体推进整治形式主义为基层减负... 形式主义实质是主观主义、功利主义,根源是政绩观错位、责任心缺失。当前,各地以深化“六个纠治”为抓手,...
5月上旬汽油柴油价格环比继续下... 【大河财立方消息】 5月14日,国家统计局发布2026年5月上旬流通领域重要生产资料市场价格变动情况...
河南信阳凌晨通报:常某朋(男,... 2026年5月13日21时43分许,我市浉河区发生一起道路交通事故。经查,常某朋(男,40岁)驾驶私...