基于SCN和时间点的不完全恢复

完全恢复与不完全恢复是数据库的两种恢复方式,顾名思义,他们的区别就是恢复后数据没有没丢失,不完全恢复是指恢复后有部分数据丢失,而完全恢复没有。
完整恢复是由于Oracle应用了归档日志和联机重做日志中所有的修改,
将数据块恢复到最接近当前时间的时间点。
不完全恢复是利用备份产生一个非当前版本的数据库。换句话说,恢复过程中不会应用备份产生后生成的所有的重做日志

下面我们基于时间点和SCN号的不完全恢复测试,truncate表后进行不完全恢复并验证恢复情况。
一、基于时间点的不完全恢复

点击(此处)折叠或打开


  1. SQL> select count(*) from test;

  2.   COUNT(*)
  3. ----------
  4.      86954

  5. SQL> select sysdate from dual;

  6. SYSDATE
  7. -------------------
  8. 2016-08-09 00:49:02

  9. SQL> truncate table test;

  10. Table truncated.

  11. SQL> exit
  12. Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
  13. With the Partitioning, OLAP, Data Mining and Real Application Testing options
  14. [oracle@mhxy164 mhxy]$ rman target /

  15. Recovery Manager: Release 11.2.0.4.0 - Production on Tue Aug 9 00:49:20 2016

  16. Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

  17. connected to target database: MHXY (DBID=4239099671)

  18. RMAN> run{
  19. 2> shutdown immediate;
  20. 3> startup mount;
  21. 4> set until time '2016-08-09 00:49:02';
  22. 5> restore database;
  23. 6> recover database;
  24. 7> alter database open resetlogs;
  25. 8> }

  26. using target database control file instead of recovery catalog
  27. database closed
  28. database dismounted
  29. Oracle instance shut down

  30. connected to target database (not started)
  31. Oracle instance started
  32. database mounted

  33. Total System Global Area 776646656 bytes

  34. Fixed Size 2257272 bytes
  35. Variable Size 507514504 bytes
  36. Database Buffers 260046848 bytes
  37. Redo Buffers 6828032 bytes

  38. executing command: SET until clause

  39. Starting restore at 2016-08-09 00:50:57
  40. allocated channel: ORA_DISK_1
  41. channel ORA_DISK_1: SID=133 device type=DISK

  42. creating datafile file number=6 name=/oracle/database/oradata/mhxy/tg.dbf
  43. channel ORA_DISK_1: starting datafile backup set restore
  44. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  45. channel ORA_DISK_1: restoring datafile 00001 to /oracle/database/oradata/mhxy/system01.dbf
  46. channel ORA_DISK_1: restoring datafile 00002 to /oracle/database/oradata/mhxy/sysaux01.dbf
  47. channel ORA_DISK_1: restoring datafile 00003 to /oracle/database/oradata/mhxy/undotbs01.dbf
  48. channel ORA_DISK_1: restoring datafile 00004 to /oracle/database/oradata/mhxy/users01.dbf
  49. channel ORA_DISK_1: restoring datafile 00005 to /oracle/database/oradata/mhxy/example01.dbf
  50. channel ORA_DISK_1: reading from backup piece /oracle/database/fast_recovery_area/MHXY/backupset/2016_08_08/o1_mf_nnndf_TAG20160808T224812_ctk6xf58_.bkp
  51. channel ORA_DISK_1: piece handle=/oracle/database/fast_recovery_area/MHXY/backupset/2016_08_08/o1_mf_nnndf_TAG20160808T224812_ctk6xf58_.bkp tag=TAG20160808T224812
  52. channel ORA_DISK_1: restored backup piece 1
  53. channel ORA_DISK_1: restore complete, elapsed time: 00:01:25
  54. Finished restore at 2016-08-09 00:52:25

  55. Starting recover at 2016-08-09 00:52:25
  56. using channel ORA_DISK_1

  57. starting media recovery

  58. archived log for thread 1 with sequence 13 is already on disk as file /oracle/database/fast_recovery_area/MHXY/archivelog/2016_08_08/o1_mf_1_13_ctk7hzhd_.arc
  59. archived log for thread 1 with sequence 14 is already on disk as file /oracle/database/fast_recovery_area/MHXY/archivelog/2016_08_08/o1_mf_1_14_ctk7j32v_.arc
  60. archived log for thread 1 with sequence 15 is already on disk as file /oracle/database/fast_recovery_area/MHXY/archivelog/2016_08_08/o1_mf_1_15_ctk81l1y_.arc
  61. archived log file name=/oracle/database/fast_recovery_area/MHXY/archivelog/2016_08_08/o1_mf_1_13_ctk7hzhd_.arc thread=1 sequence=13
  62. media recovery complete, elapsed time: 00:00:04
  63. Finished recover at 2016-08-09 00:52:30

  64. database opened

  65. RMAN> exit

  66. Recovery Manager complete.
  67. [oracle@mhxy164 mhxy]$ sqlplus / as sysdba

  68. SQL*Plus: Release 11.2.0.4.0 Production on Tue Aug 9 00:52:57 2016

  69. Copyright (c) 1982, 2013, Oracle. All rights reserved.

  70. Connected to:
  71. Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
  72. With the Partitioning, OLAP, Data Mining and Real Application Testing options

  73. SQL> select count(*) from test;

  74.   COUNT(*)
  75. ----------
  76.      86954
二、基于SCN号的不完全恢复

点击(此处)折叠或打开

  1. [oracle@mhxy164 mhxy]$ sqlplus / as sysdba

  2. SQL*Plus: Release 11.2.0.4.0 Production on Tue Aug 9 00:58:55 2016

  3. Copyright (c) 1982, 2013, Oracle. All rights reserved.


  4. Connected to:
  5. Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
  6. With the Partitioning, OLAP, Data Mining and Real Application Testing options

  7. SQL> select count(*) from test1;

  8.   COUNT(*)
  9. ----------
  10.      86956

  11. SQL> select dbms_flashback.get_system_change_number from dual;

  12. GET_SYSTEM_CHANGE_NUMBER
  13. ------------------------
  14.                  1180680

  15. SQL> truncate table test1;

  16. Table truncated.

  17. SQL> select count(*) from test1;

  18.   COUNT(*)
  19. ----------
  20.          0

  21. SQL> exit
  22. Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
  23. With the Partitioning, OLAP, Data Mining and Real Application Testing options
  24. [oracle@mhxy164 mhxy]$ rman target /

  25. Recovery Manager: Release 11.2.0.4.0 - Production on Tue Aug 9 01:00:05 2016

  26. Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

  27. connected to target database: MHXY (DBID=4239099671)

  28. RMAN> run{
  29. 2> shutdown immediate;
  30. 3> startup mount
  31. 4> set until scn 1180680;
  32. 5> restore database;
  33. 6> recover database;
  34. 7> alter database open resetlogs;
  35. 8> }

  36. using target database control file instead of recovery catalog
  37. database closed
  38. database dismounted
  39. Oracle instance shut down

  40. connected to target database (not started)
  41. Oracle instance started
  42. database mounted

  43. Total System Global Area 776646656 bytes

  44. Fixed Size 2257272 bytes
  45. Variable Size 507514504 bytes
  46. Database Buffers 260046848 bytes
  47. Redo Buffers 6828032 bytes

  48. executing command: SET until clause

  49. Starting restore at 2016-08-09 01:01:01
  50. allocated channel: ORA_DISK_1
  51. channel ORA_DISK_1: SID=133 device type=DISK

  52. creating datafile file number=6 name=/oracle/database/oradata/mhxy/tg.dbf
  53. channel ORA_DISK_1: starting datafile backup set restore
  54. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  55. channel ORA_DISK_1: restoring datafile 00001 to /oracle/database/oradata/mhxy/system01.dbf
  56. channel ORA_DISK_1: restoring datafile 00002 to /oracle/database/oradata/mhxy/sysaux01.dbf
  57. channel ORA_DISK_1: restoring datafile 00003 to /oracle/database/oradata/mhxy/undotbs01.dbf
  58. channel ORA_DISK_1: restoring datafile 00004 to /oracle/database/oradata/mhxy/users01.dbf
  59. channel ORA_DISK_1: restoring datafile 00005 to /oracle/database/oradata/mhxy/example01.dbf
  60. channel ORA_DISK_1: reading from backup piece /oracle/database/fast_recovery_area/MHXY/backupset/2016_08_08/o1_mf_nnndf_TAG20160808T224812_ctk6xf58_.bkp
  61. channel ORA_DISK_1: piece handle=/oracle/database/fast_recovery_area/MHXY/backupset/2016_08_08/o1_mf_nnndf_TAG20160808T224812_ctk6xf58_.bkp tag=TAG20160808T224812
  62. channel ORA_DISK_1: restored backup piece 1
  63. channel ORA_DISK_1: restore complete, elapsed time: 00:00:55
  64. Finished restore at 2016-08-09 01:01:58

  65. Starting recover at 2016-08-09 01:01:58
  66. using channel ORA_DISK_1

  67. starting media recovery

  68. archived log for thread 1 with sequence 13 is already on disk as file /oracle/database/fast_recovery_area/MHXY/archivelog/2016_08_08/o1_mf_1_13_ctk7hzhd_.arc
  69. archived log for thread 1 with sequence 14 is already on disk as file /oracle/database/fast_recovery_area/MHXY/archivelog/2016_08_08/o1_mf_1_14_ctk7j32v_.arc
  70. archived log for thread 1 with sequence 15 is already on disk as file /oracle/database/fast_recovery_area/MHXY/archivelog/2016_08_08/o1_mf_1_15_ctk81l1y_.arc
  71. archived log for thread 1 with sequence 16 is already on disk as file /oracle/database/fast_recovery_area/MHXY/archivelog/2016_08_09/o1_mf_1_16_ctkg6gcb_.arc
  72. archived log file name=/oracle/database/fast_recovery_area/MHXY/archivelog/2016_08_08/o1_mf_1_13_ctk7hzhd_.arc thread=1 sequence=13
  73. archived log file name=/oracle/database/fast_recovery_area/MHXY/archivelog/2016_08_08/o1_mf_1_14_ctk7j32v_.arc thread=1 sequence=14
  74. archived log file name=/oracle/database/fast_recovery_area/MHXY/archivelog/2016_08_08/o1_mf_1_15_ctk81l1y_.arc thread=1 sequence=15
  75. archived log file name=/oracle/database/fast_recovery_area/MHXY/archivelog/2016_08_09/o1_mf_1_16_ctkg6gcb_.arc thread=1 sequence=16
  76. media recovery complete, elapsed time: 00:00:05
  77. Finished recover at 2016-08-09 01:02:05

  78. database opened

  79. RMAN> exit

    Recovery Manager complete.
    [oracle@mhxy164 mhxy]$ sqlplus / as sysdba

    SQL*Plus: Release 11.2.0.4.0 Production on Tue Aug 9 01:45:21 2016

    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> select count(*) from test1;

      COUNT(*)
    ----------
        86956
    SQL> 





来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27039319/viewspace-2123184/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27039319/viewspace-2123184/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值