mysql表按时间点恢复_数据库恢复至某个时间点

实例详解:

数据库恢复到某个时间点

[oracle@lyo1 ~]$ 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

SYS@VDEDU>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

[oracle@lyo1 ~]$ 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

[oracle@lyo1 ~]$ 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值