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


相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...