完全恢复与不完全恢复是数据库的两种恢复方式,顾名思义,他们的区别就是恢复后数据没有没丢失,不完全恢复是指恢复后有部分数据丢失,而完全恢复没有。
完整恢复是由于Oracle应用了归档日志和联机重做日志中所有的修改,将数据块恢复到最接近当前时间的时间点。
不完全恢复是利用备份产生一个非当前版本的数据库。换句话说,恢复过程中不会应用备份产生后生成的所有的重做日志。
下面我们基于时间点和SCN号的不完全恢复测试,truncate表后进行不完全恢复并验证恢复情况。
一、基于时间点的不完全恢复
-
-
SQL> select count(*) from test;
-
-
COUNT(*)
-
----------
-
86954
-
-
SQL> select sysdate from dual;
-
-
SYSDATE
-
-------------------
-
2016-08-09 00:49:02
-
-
SQL> truncate table test;
-
-
Table truncated.
-
-
SQL> exit
-
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
-
With the Partitioning, OLAP, Data Mining and Real Application Testing options
-
[oracle@mhxy164 mhxy]$ rman target /
-
-
Recovery Manager: Release 11.2.0.4.0 - Production on Tue Aug 9 00:49:20 2016
-
-
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
-
-
connected to target database: MHXY (DBID=4239099671)
-
-
RMAN> run{
-
2> shutdown immediate;
-
3> startup mount;
-
4> set until time '2016-08-09 00:49:02';
-
5> restore database;
-
6> recover database;
-
7> alter database open resetlogs;
-
8> }
-
-
using target database control file instead of recovery catalog
-
database closed
-
database dismounted
-
Oracle instance shut down
-
-
connected to target database (not started)
-
Oracle instance started
-
database mounted
-
-
Total System Global Area 776646656 bytes
-
-
Fixed Size 2257272 bytes
-
Variable Size 507514504 bytes
-
Database Buffers 260046848 bytes
-
Redo Buffers 6828032 bytes
-
-
executing command: SET until clause
-
-
Starting restore at 2016-08-09 00:50:57
-
allocated channel: ORA_DISK_1
-
channel ORA_DISK_1: SID=133 device type=DISK
-
-
creating datafile file number=6 name=/oracle/database/oradata/mhxy/tg.dbf
-
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 /oracle/database/oradata/mhxy/system01.dbf
-
channel ORA_DISK_1: restoring datafile 00002 to /oracle/database/oradata/mhxy/sysaux01.dbf
-
channel ORA_DISK_1: restoring datafile 00003 to /oracle/database/oradata/mhxy/undotbs01.dbf
-
channel ORA_DISK_1: restoring datafile 00004 to /oracle/database/oradata/mhxy/users01.dbf
-
channel ORA_DISK_1: restoring datafile 00005 to /oracle/database/oradata/mhxy/example01.dbf
-
channel ORA_DISK_1: reading from backup piece /oracle/database/fast_recovery_area/MHXY/backupset/2016_08_08/o1_mf_nnndf_TAG20160808T224812_ctk6xf58_.bkp
-
channel ORA_DISK_1: piece handle=/oracle/database/fast_recovery_area/MHXY/backupset/2016_08_08/o1_mf_nnndf_TAG20160808T224812_ctk6xf58_.bkp tag=TAG20160808T224812
-
channel ORA_DISK_1: restored backup piece 1
-
channel ORA_DISK_1: restore complete, elapsed time: 00:01:25
-
Finished restore at 2016-08-09 00:52:25
-
-
Starting recover at 2016-08-09 00:52:25
-
using channel ORA_DISK_1
-
-
starting media recovery
-
-
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
-
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
-
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
-
archived log file name=/oracle/database/fast_recovery_area/MHXY/archivelog/2016_08_08/o1_mf_1_13_ctk7hzhd_.arc thread=1 sequence=13
-
media recovery complete, elapsed time: 00:00:04
-
Finished recover at 2016-08-09 00:52:30
-
-
database opened
-
-
RMAN> exit
-
-
Recovery Manager complete.
-
[oracle@mhxy164 mhxy]$ sqlplus / as sysdba
-
-
SQL*Plus: Release 11.2.0.4.0 Production on Tue Aug 9 00:52:57 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 test;
-
-
COUNT(*)
-
----------
-
86954
二、基于SCN号的不完全恢复
-
[oracle@mhxy164 mhxy]$ sqlplus / as sysdba
-
-
SQL*Plus: Release 11.2.0.4.0 Production on Tue Aug 9 00:58:55 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> select dbms_flashback.get_system_change_number from dual;
-
-
GET_SYSTEM_CHANGE_NUMBER
-
------------------------
-
1180680
-
-
SQL> truncate table test1;
-
-
Table truncated.
-
-
SQL> select count(*) from test1;
-
-
COUNT(*)
-
----------
-
0
-
-
SQL> exit
-
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
-
With the Partitioning, OLAP, Data Mining and Real Application Testing options
-
[oracle@mhxy164 mhxy]$ rman target /
-
-
Recovery Manager: Release 11.2.0.4.0 - Production on Tue Aug 9 01:00:05 2016
-
-
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
-
-
connected to target database: MHXY (DBID=4239099671)
-
-
RMAN> run{
-
2> shutdown immediate;
-
3> startup mount
-
4> set until scn 1180680;
-
5> restore database;
-
6> recover database;
-
7> alter database open resetlogs;
-
8> }
-
-
using target database control file instead of recovery catalog
-
database closed
-
database dismounted
-
Oracle instance shut down
-
-
connected to target database (not started)
-
Oracle instance started
-
database mounted
-
-
Total System Global Area 776646656 bytes
-
-
Fixed Size 2257272 bytes
-
Variable Size 507514504 bytes
-
Database Buffers 260046848 bytes
-
Redo Buffers 6828032 bytes
-
-
executing command: SET until clause
-
-
Starting restore at 2016-08-09 01:01:01
-
allocated channel: ORA_DISK_1
-
channel ORA_DISK_1: SID=133 device type=DISK
-
-
creating datafile file number=6 name=/oracle/database/oradata/mhxy/tg.dbf
-
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 /oracle/database/oradata/mhxy/system01.dbf
-
channel ORA_DISK_1: restoring datafile 00002 to /oracle/database/oradata/mhxy/sysaux01.dbf
-
channel ORA_DISK_1: restoring datafile 00003 to /oracle/database/oradata/mhxy/undotbs01.dbf
-
channel ORA_DISK_1: restoring datafile 00004 to /oracle/database/oradata/mhxy/users01.dbf
-
channel ORA_DISK_1: restoring datafile 00005 to /oracle/database/oradata/mhxy/example01.dbf
-
channel ORA_DISK_1: reading from backup piece /oracle/database/fast_recovery_area/MHXY/backupset/2016_08_08/o1_mf_nnndf_TAG20160808T224812_ctk6xf58_.bkp
-
channel ORA_DISK_1: piece handle=/oracle/database/fast_recovery_area/MHXY/backupset/2016_08_08/o1_mf_nnndf_TAG20160808T224812_ctk6xf58_.bkp tag=TAG20160808T224812
-
channel ORA_DISK_1: restored backup piece 1
-
channel ORA_DISK_1: restore complete, elapsed time: 00:00:55
-
Finished restore at 2016-08-09 01:01:58
-
-
Starting recover at 2016-08-09 01:01:58
-
using channel ORA_DISK_1
-
-
starting media recovery
-
-
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
-
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
-
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
-
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
-
archived log file name=/oracle/database/fast_recovery_area/MHXY/archivelog/2016_08_08/o1_mf_1_13_ctk7hzhd_.arc thread=1 sequence=13
-
archived log file name=/oracle/database/fast_recovery_area/MHXY/archivelog/2016_08_08/o1_mf_1_14_ctk7j32v_.arc thread=1 sequence=14
-
archived log file name=/oracle/database/fast_recovery_area/MHXY/archivelog/2016_08_08/o1_mf_1_15_ctk81l1y_.arc thread=1 sequence=15
-
archived log file name=/oracle/database/fast_recovery_area/MHXY/archivelog/2016_08_09/o1_mf_1_16_ctkg6gcb_.arc thread=1 sequence=16
-
media recovery complete, elapsed time: 00:00:05
-
Finished recover at 2016-08-09 01:02:05
-
-
database opened
-
-
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博客 ” ,链接:https://blog.itpub.net/27039319/viewspace-2123184/
,如需转载,请注明出处,否则将追究法律责任。