数据库恢复至某个时间点
Posted 张欣橙
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据库恢复至某个时间点相关的知识,希望对你有一定的参考价值。
实例详解:
数据库恢复到某个时间点
[[email protected] ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Wed Jul 18 01:16:04 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> conn scott/oracle
Connected.
创建一个表t1
SQL> create table t1 (x int);
Table created.
插入一行数据并提交
SQL> insert into t1 values (1);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from t1;
X
----------
1
连接到SYS
SQL> conn / as sysdba
Connected.
将当期时间转换为SCN
SQL> select timestamp_to_scn(sysdate) from v$database;
TIMESTAMP_TO_SCN(SYSDATE)
-------------------------
1149633
将指定时间转换为SCN
[email protected]>select timestamp_to_scn(to_date(‘2018-07-19 10:59:26‘)) from v$database;
TIMESTAMP_TO_SCN(TO_DATE(‘2018-07-1910:59:26‘))
-----------------------------------------------
1129373
SQL> conn scott/oracle
Connected.
插入一行数据
SQL> insert into t1 values (2);
1 row created.
SQL> commit;
Commit complete.
此时t1为两行数据
SQL> select * from t1;
X
----------
1
2
SQL> conn / as sysdba
Connected.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
关闭数据库启动到mount模式
SQL> startup mount;
ORACLE instance started.
Total System Global Area 1503199232 bytes
Fixed Size 2253424 bytes
Variable Size 922750352 bytes
Database Buffers 570425344 bytes
Redo Buffers 7770112 bytes
Database mounted.
SQL> quit
启动RMAN
[[email protected] ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Jul 18 01:19:03 2018
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: VDEDU (DBID=4265126356, not open)
使数据库恢复到刚才的时间点
RMAN> run{
2> set until scn = 1149633;
3> restore database;
4> recover database;
5> alter database open resetlogs;
6> }
executing command: SET until clause
Starting restore at 2018-07-18 01:21:20
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/VDEDU/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/VDEDU/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/VDEDU/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/VDEDU/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/VDEDU/example01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/VDEDU/backupset/2018_07_18/o1_mf_nnndf_TAG20180718T011528_fnxm7jk1_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/VDEDU/backupset/2018_07_18/o1_mf_nnndf_TAG20180718T011528_fnxm7jk1_.bkp tag=TAG20180718T011528
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 2018-07-18 01:21:56
Starting recover at 2018-07-18 01:21:56
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 2018-07-18 01:21:56
database opened
RMAN> quit
[[email protected] ~]$ sqlplus scott/oracle
SQL*Plus: Release 11.2.0.4.0 Production on Wed Jul 18 01:22:08 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
查询表t1,发现又变回了一行数据
SQL> select * from t1;
X
----------
1
以上是关于数据库恢复至某个时间点的主要内容,如果未能解决你的问题,请参考以下文章