ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 用restore archivelog从备份集中恢复归档日志

用restore archivelog从备份集中恢复归档日志

Linux操作系统 作者:东方友诚 时间:2015-10-10 10:26:15 0 删除 编辑

Oracle数据库使用RMAN备份的时候,会把归档日志压成备份集(backup set),而有时候我们为了恢复数据的需要可能需要从这些备份集中解析出归档日志(archive log),这时可以用restore这个命令。

该命令的参数可以用SCN、SEQUENCE、TIME等,也可以附加preview参数先查看计划,该参数和list backup of archivelog是等效的。

1、根据时间查看需要的备份集:

ERPDB1@/orabak>rman target /

Recovery Manager: Release 10.2.0.3.0 - Production on Mon Jun 29 16:20:40 2009

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

connected to target database: ERPDB (DBID=2400249746)

RMAN> list backup of archivelog time between "to_date('2009-06-24 08:00:00','yyyy-mm-dd hh24:mi:ss')" and "to_date('2009-06-24 13:00','yyyy-mm-dd hh24:mi:ss')";

以下是示例,并非原来的文件列表:

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
18021   104.97M    DISK        00:00:25     02-APR-10
BP Key: 21243   Status: AVAILABLE  Compressed: YES  Tag: TAG20100402T213015
Piece Name: /orabak/arch/CNDERPDB_arch_20100402_715296294_18088_1

List of Archived Logs in backup set 18021
Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
---- ------- ---------- --------- ---------- ---------
1    130930  12425302024 02-APR-10 12425464067 02-APR-10
1    130931  12425464067 02-APR-10 12425612482 02-APR-10
1    130932  12425612482 02-APR-10 12425741312 02-APR-10
1    130933  12425741312 02-APR-10 12425903002 02-APR-10
1    130934  12425903002 02-APR-10 12426033120 02-APR-10
1    130935  12426033120 02-APR-10 12426231614 02-APR-10
1    130936  12426231614 02-APR-10 12426258334 02-APR-10

或者用preview查看:

RMAN> restore archivelog time between "to_date('2009-06-24 08:00:00','yyyy-mm-dd hh24:mi:ss')" and "to_date('2009-06-24 13:00','yyyy-mm-dd hh24:mi:ss')" preview;

也可以先指定时间格式,然后就可以不用to_date函数了:

RMAN> SQL 'ALTER SESSION SET NLS_DATE_FORMAT="YYYY-MM-DD:HH24:MI:SS"';
RMAN> restore archivelog time between '2009-06-24 09:00:00' and '2009-06-24 12:00:00' preview;

2、把备份集文件COPY到默认的归档路径中

我这里是/orabak/arch,从第一步文件列表的Piece Name也可以看出来归档的路径。

否则在restore过程中会报以下错误:

channel ORA_DISK_1: reading from backup piece /orabak/arch/ERPDB_arch_20090624_690383375_14453_1
ORA-19870: error reading backup piece /orabak/arch/ERPDB_arch_20090624_690383375_14453_1
ORA-19505: failed to identify file "/orabak/arch/ERPDB_arch_20090624_690383375_14453_1"
ORA-27037: unable to obtain file status
IBM AIX RISC System/6000 Error: 2: No such file or directory
Additional information: 3

3、执行restore命令,一般如果是临时需要这些文件,可以指定归档日志恢复到其他的目录,这时必须用run命令:

RMAN> run {
2> set archivelog destination to '/orabak/testarch';
3> SQL 'ALTER SESSION SET NLS_DATE_FORMAT="YYYY-MM-DD:HH24:MI:SS"';
4> restore archivelog time between '2009-06-24 09:00:00' and '2009-06-24 12:10:00';
5> }
executing command: SET ARCHIVELOG DESTINATION
using target database control file instead of recovery catalog

sql statement: ALTER SESSION SET NLS_DATE_FORMAT="YYYY-MM-DD:HH24:MI:SS"

Starting restore at 29-JUN-09
allocated channel: ORA_DISK_1
......
Finished restore at 29-JUN-09

如果我们明确要恢复哪些归档日志,可以用SEQUENCE BETWEEN integer1 AND integer2命令来操作。

相关文档:

http://download.oracle.com/docs/cd/B19306_01/backup.102/b14194/rcmsynta008.htm#i78730

http://download.oracle.com/docs/cd/B19306_01/backup.102/b14194/rcmsynta051.htm#sthref796

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

下一篇: 08 Advance Queue
请登录后发表评论 登录
全部评论

注册时间:2014-11-24

  • 博文量
    144
  • 访问量
    256576