ITPub博客

首页 > 数据库 > Oracle > 备份与恢复--跨越resetlogs的恢复

备份与恢复--跨越resetlogs的恢复

原创 Oracle 作者:jolly10 时间:2009-01-21 11:34:57 0 删除 编辑

在10g之前,一般情况下是无法利用RESETLOGS操作之前的备份进行数据库的恢复的。特定条件下10g前的恢复可参考:

http://yangtingkun.itpub.net/post/468/59092,恢复过程已比较复杂。

10g中oracle提供了跨越resetlogs恢复的可能,下面就这项新功能做了下测试.

[@more@]

先进行一次全备份。

[oracle@rhel131 ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Mon Jan 19 00:47:58 2009

Copyright (c) 1982, 2005, Oracle. All rights reserved.

connected to target database: ORCL (DBID=1203373630)


RMAN> backup database plus archivelog delete all input;


Starting backup at 19-JAN-09
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=153 devtype=DISK
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=4 recid=17 stamp=676019363
input archive log thread=1 sequence=5 recid=15 stamp=676019363
input archive log thread=1 sequence=6 recid=16 stamp=676019363
input archive log thread=1 sequence=7 recid=14 stamp=676019362
input archive log thread=1 sequence=8 recid=6 stamp=676019362
input archive log thread=1 sequence=9 recid=9 stamp=676019362
input archive log thread=1 sequence=10 recid=7 stamp=676019362
input archive log thread=1 sequence=11 recid=8 stamp=676019362
input archive log thread=1 sequence=12 recid=5 stamp=676019362
input archive log thread=1 sequence=13 recid=10 stamp=676019362
input archive log thread=1 sequence=14 recid=3 stamp=676019109
input archive log thread=1 sequence=15 recid=19 stamp=676021318
input archive log thread=1 sequence=16 recid=21 stamp=676021399
input archive log thread=1 sequence=17 recid=23 stamp=676021444
input archive log thread=1 sequence=18 recid=24 stamp=676022544
input archive log thread=1 sequence=19 recid=25 stamp=676022553
input archive log thread=1 sequence=20 recid=26 stamp=676022926
input archive log thread=1 sequence=21 recid=27 stamp=676022950
input archive log thread=1 sequence=22 recid=28 stamp=676022956
input archive log thread=1 sequence=23 recid=29 stamp=676514956
channel ORA_DISK_1: starting piece 1 at 19-JAN-09
channel ORA_DISK_1: finished piece 1 at 19-JAN-09
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2009_01_19/o1_mf_annnn_TAG20090119T004917_4q6qdj47_.bkp

tag=TAG20090119T004917 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:17
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_12/o1_mf_1_4_4poo2f69_.arc recid=17

stamp=676019363
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_12/o1_mf_1_5_4poo2hrt_.arc recid=15

stamp=676019363
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_12/o1_mf_1_6_4pohjz08_.arc recid=16

stamp=676019363
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_12/o1_mf_1_6_4poo3yk0_.arc recid=13

stamp=676019362
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_12/o1_mf_1_7_4pok10bf_.arc recid=14

stamp=676019362
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_13/o1_mf_1_7_4pqk7z7q_.arc recid=11

stamp=676019362
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_13/o1_mf_1_8_4pqkt8d6_.arc recid=6

stamp=676019362
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_13/o1_mf_1_8_4pqk8lmn_.arc recid=4

stamp=676019362
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_13/o1_mf_1_9_4pqk9l4t_.arc recid=9

stamp=676019362
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_13/o1_mf_1_9_4pqkt8g7_.arc recid=12

stamp=676019362
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_13/o1_mf_1_10_4pqktcw0_.arc recid=7

stamp=676019362
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_13/o1_mf_1_11_4pqlzz7c_.arc recid=8

stamp=676019362
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_13/o1_mf_1_12_4pqm18gj_.arc recid=5

stamp=676019362
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_13/o1_mf_1_12_4pqm516c_.arc recid=1

stamp=676019105
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_13/o1_mf_1_13_4pqm1mpq_.arc recid=10

stamp=676019362
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_13/o1_mf_1_13_4pqm5185_.arc recid=2

stamp=676019105
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_13/o1_mf_1_14_4pqm54v0_.arc recid=3

stamp=676019109
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_13/o1_mf_1_15_4pqob6s1_.arc recid=19

stamp=676021318
archive log filename=/u01/app/oracle/admin/orcl/archive/1_15_675592897.dbf recid=18 stamp=676021318
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_13/o1_mf_1_16_4pqodq87_.arc recid=21

stamp=676021399
archive log filename=/u01/app/oracle/admin/orcl/archive/1_16_675592897.dbf recid=20 stamp=676021399
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_01_13/o1_mf_1_17_4pqog4wq_.arc recid=23

stamp=676021444
archive log filename=/u01/app/oracle/admin/orcl/archive/1_17_675592897.dbf recid=22 stamp=676021444
archive log filename=/u01/app/oracle/admin/orcl/archive/1_18_675592897.dbf recid=24 stamp=676022544
archive log filename=/u01/app/oracle/admin/orcl/archive/1_19_675592897.dbf recid=25 stamp=676022553
archive log filename=/u01/app/oracle/admin/orcl/archive/1_20_675592897.dbf recid=26 stamp=676022926
archive log filename=/u01/app/oracle/admin/orcl/archive/1_21_675592897.dbf recid=27 stamp=676022950
archive log filename=/u01/app/oracle/admin/orcl/archive/1_22_675592897.dbf recid=28 stamp=676022956
archive log filename=/u01/app/oracle/admin/orcl/archive/1_23_675592897.dbf recid=29 stamp=676514956
Finished backup at 19-JAN-09

Starting backup at 19-JAN-09
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/orcl/jglu01.dbf
input datafile fno=00007 name=/u01/app/oracle/oradata/orcl/jglu02.dbf
input datafile fno=00008 name=/u01/app/oracle/oradata/orcl/test02.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: starting piece 1 at 19-JAN-09
channel ORA_DISK_1: finished piece 1 at 19-JAN-09
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2009_01_19/o1_mf_nnndf_TAG20090119T004936_4q6qf0z6_.bkp

tag=TAG20090119T004936 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:05
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 19-JAN-09
channel ORA_DISK_1: finished piece 1 at 19-JAN-09
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2009_01_19/o1_mf_ncsnf_TAG20090119T004936_4q6qh3rs_.bkp

tag=TAG20090119T004936 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 19-JAN-09

Starting backup at 19-JAN-09
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=24 recid=30 stamp=676515045
channel ORA_DISK_1: starting piece 1 at 19-JAN-09
channel ORA_DISK_1: finished piece 1 at 19-JAN-09
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2009_01_19/o1_mf_annnn_TAG20090119T005045_4q6qh6dg_.bkp

tag=TAG20090119T005045 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u01/app/oracle/admin/orcl/archive/1_24_675592897.dbf recid=30 stamp=676515045
Finished backup at 19-JAN-09

进行数据库的更改

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

COUNT(*)
----------
40688


SQL> delete jglu.test1 where rownum<3000;

2999 rows deleted.

SQL> commit;

Commit complete.

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

COUNT(*)
----------
37689

SQL> alter system switch logfile;

System altered.

SQL> delete jglu.test1 where rownum<3000;

2999 rows deleted.

SQL> commit;

Commit complete.

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

COUNT(*)
----------
34690

SQL> alter system switch logfile;

System altered.

SQL> delete jglu.test1;

34690 rows deleted.

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.


日志序列的情况如下:


SQL> select * from v$log_history;

RECID STAMP THREAD# SEQUENCE# FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# RESETLOGS_CHANGE# RESETLOGS
---------- ---------- ---------- ---------- ------------- --------- ------------ ----------------- ---------
1 676019108 1 14 675401 13-JAN-09 675553 446075 08-JAN-09
2 676021318 1 15 675553 13-JAN-09 679329 446075 08-JAN-09
3 676021399 1 16 679329 13-JAN-09 679362 446075 08-JAN-09
4 676021444 1 17 679362 13-JAN-09 679384 446075 08-JAN-09
5 676022544 1 18 679384 13-JAN-09 680227 446075 08-JAN-09
6 676022552 1 19 680227 13-JAN-09 680231 446075 08-JAN-09
7 676022926 1 20 680231 13-JAN-09 681617 446075 08-JAN-09
8 676022950 1 21 681617 13-JAN-09 681626 446075 08-JAN-09
9 676022956 1 22 681626 13-JAN-09 681629 446075 08-JAN-09
10 676514956 1 23 681629 13-JAN-09 687430 446075 08-JAN-09
11 676515045 1 24 687430 19-JAN-09 687474 446075 08-JAN-09
12 676515504 1 25 687474 19-JAN-09 687821 446075 08-JAN-09
13 676515523 1 26 687821 19-JAN-09 687875 446075 08-JAN-09
14 676515543 1 27 687875 19-JAN-09 688388 446075 08-JAN-09

14 rows selected.

下面模拟用户错误,不应该将表的资料删除掉,只恢复到第25的归档日志
需要关闭数据库,执行不完全恢复,用resetlog打开数据库

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

这里需要注意,如果需要恢复25的归档日志,until sequence需要指定到第26

RMAN> run {
2> set until sequence 26 thread 1;
3> restore database;
4> recover database;
5> }

executing command: SET until clause
using target database control file instead of recovery catalog

Starting restore at 19-JAN-09
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/orcl/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/orcl/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/orcl/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/orcl/jglu01.dbf
restoring datafile 00007 to /u01/app/oracle/oradata/orcl/jglu02.dbf
restoring datafile 00008 to /u01/app/oracle/oradata/orcl/test02.dbf
channel ORA_DISK_1: reading from backup piece

/u01/app/oracle/flash_recovery_area/ORCL/backupset/2009_01_19/o1_mf_nnndf_TAG20090119T004936_4q6qf0z6_.bkp
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2009_01_19/o1_mf_nnndf_TAG20090119T004936_4q6qf0z6_.bkp

tag=TAG20090119T004936
channel ORA_DISK_1: restore complete, elapsed time: 00:00:56
Finished restore at 19-JAN-09

Starting recover at 19-JAN-09
using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 25 is already on disk as file /u01/app/oracle/admin/orcl/archive/1_25_675592897.dbf
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=24
channel ORA_DISK_1: reading from backup piece

/u01/app/oracle/flash_recovery_area/ORCL/backupset/2009_01_19/o1_mf_annnn_TAG20090119T005045_4q6qh6dg_.bkp
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2009_01_19/o1_mf_annnn_TAG20090119T005045_4q6qh6dg_.bkp

tag=TAG20090119T005045
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/u01/app/oracle/admin/orcl/archive/1_24_675592897.dbf thread=1 sequence=24
archive log filename=/u01/app/oracle/admin/orcl/archive/1_25_675592897.dbf thread=1 sequence=25
media recovery complete, elapsed time: 00:00:03
Finished recover at 19-JAN-09

[oracle@rhel131 ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Jan 19 01:05:45 2009

Copyright (c) 1982, 2005, Oracle. All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/admin/orcl/archive
Oldest online log sequence 0
Next log sequence to archive 1
Current log sequence 1
SQL> select count(*) from jglu.test1;

COUNT(*)
----------
37689

已恢复到第25个归档日志的状态,下面继续修改此表。


SQL> insert into jglu.test1 select * from dba_objects where rownum<100;

99 rows created.

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.

SQL> truncate table jglu.test1;

Table truncated.

SQL> alter system switch logfile;

System altered.

SQL> insert into jglu.test1 select * from dba_objects where rownum<200;

199 rows created.

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.

看看现在归档日志的状态,注意RESETLOGS_CHANGE#的变化

SQL> select * From v$log_history;

RECID STAMP THREAD# SEQUENCE# FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# RESETLOGS_CHANGE# RESETLOGS
---------- ---------- ---------- ---------- ------------- --------- ------------ ----------------- ---------
1 676019108 1 14 675401 13-JAN-09 675553 446075 08-JAN-09
2 676021318 1 15 675553 13-JAN-09 679329 446075 08-JAN-09
3 676021399 1 16 679329 13-JAN-09 679362 446075 08-JAN-09
4 676021444 1 17 679362 13-JAN-09 679384 446075 08-JAN-09
5 676022544 1 18 679384 13-JAN-09 680227 446075 08-JAN-09
6 676022552 1 19 680227 13-JAN-09 680231 446075 08-JAN-09
7 676022926 1 20 680231 13-JAN-09 681617 446075 08-JAN-09
8 676022950 1 21 681617 13-JAN-09 681626 446075 08-JAN-09
9 676022956 1 22 681626 13-JAN-09 681629 446075 08-JAN-09
10 676514956 1 23 681629 13-JAN-09 687430 446075 08-JAN-09
11 676515045 1 24 687430 19-JAN-09 687474 446075 08-JAN-09
12 676515504 1 25 687474 19-JAN-09 687821 446075 08-JAN-09
13 676515523 1 26 687821 19-JAN-09 687875 446075 08-JAN-09
14 676515543 1 27 687875 19-JAN-09 688388 446075 08-JAN-09
15 676516091 1 1 687822 19-JAN-09 690045 687822 19-JAN-09
16 676516104 1 2 690045 19-JAN-09 690161 687822 19-JAN-09
17 676516133 1 3 690161 19-JAN-09 690180 687822 19-JAN-09

17 rows selected.


如果此时数据文件损坏或其它情况需要恢复,能否用resetlog之前的备份进行恢复?答案是:10g是可以的

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> host rm /u01/app/oracle/oradata/orcl/*.dbf

SQL> exit

[oracle@rhel131 ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Mon Jan 19 01:12:07 2009

Copyright (c) 1982, 2005, Oracle. All rights reserved.

connected to target database (not started)

RMAN> startup mount;

Oracle instance started
database mounted

Total System Global Area 335544320 bytes

Fixed Size 1219280 bytes
Variable Size 75498800 bytes
Database Buffers 255852544 bytes
Redo Buffers 2973696 bytes


RMAN> run {
2> restore database;
3> recover database;
4> }

Starting restore at 19-JAN-09
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/orcl/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/orcl/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/orcl/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/orcl/jglu01.dbf
restoring datafile 00007 to /u01/app/oracle/oradata/orcl/jglu02.dbf
restoring datafile 00008 to /u01/app/oracle/oradata/orcl/test02.dbf
channel ORA_DISK_1: reading from backup piece

/u01/app/oracle/flash_recovery_area/ORCL/backupset/2009_01_19/o1_mf_nnndf_TAG20090119T004936_4q6qf0z6_.bkp


channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2009_01_19/o1_mf_nnndf_TAG20090119T004936_4q6qf0z6_.bkp

tag=TAG20090119T004936
channel ORA_DISK_1: restore complete, elapsed time: 00:00:56
Finished restore at 19-JAN-09

Starting recover at 19-JAN-09
using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 24 is already on disk as file /u01/app/oracle/admin/orcl/archive/1_24_675592897.dbf
archive log thread 1 sequence 25 is already on disk as file /u01/app/oracle/admin/orcl/archive/1_25_675592897.dbf
archive log thread 1 sequence 1 is already on disk as file /u01/app/oracle/admin/orcl/archive/1_1_676515900.dbf
archive log thread 1 sequence 2 is already on disk as file /u01/app/oracle/admin/orcl/archive/1_2_676515900.dbf
archive log thread 1 sequence 3 is already on disk as file /u01/app/oracle/admin/orcl/archive/1_3_676515900.dbf
archive log filename=/u01/app/oracle/admin/orcl/archive/1_24_675592897.dbf thread=1 sequence=24
archive log filename=/u01/app/oracle/admin/orcl/archive/1_25_675592897.dbf thread=1 sequence=25
archive log filename=/u01/app/oracle/admin/orcl/archive/1_1_676515900.dbf thread=1 sequence=1
media recovery complete, elapsed time: 00:00:05
Finished recover at 19-JAN-09

RMAN> alter database open;

using target database control file instead of recovery catalog
database opened

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

COUNT(*)
----------
199

已恢复到最后同步的状态。

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

请登录后发表评论 登录
全部评论

注册时间:2008-02-20

  • 博文量
    263
  • 访问量
    826732