第一.备份所有归档日志文件
RMAN> backup archivelog all delete input;
第二.restore archivelog 的各种选项
- restore archivelog all 恢复全部归档日志文件
RMAN> restore archivelog all;
- 只恢复 5到8这四个归档日志文件
RMAN> restore archivelog from logseq 5 until logseq 8;
- 恢复从第5个归档日志起
RMAN> restore archivelog from logseq 5;
- 恢复7天内的归档日志
RMAN> restore archivelog from time 'sysdate-7';
- sequence between 写法
RMAN> restore archivelog sequence between 1 and 3;
- 恢复到哪个日志文件为止
RMAN> restore archivelog until logseq 3;
- 从第五个日志开始恢复
RMAN> restore archivelog low logseq 5;
- 到第5个日志为止
RMAN> restore archivelog high logseq 5;
如果想改变恢复到另外路径下 则可用下面语句
set archivelog destination to 'd:\backup';
RMAN> run
2> {allocate channel ci type disk;
3> set archivelog destination to 'd:\backup';
4> restore archivelog all;
5> release channel ci;
6> }
Oracle数据库使用RMAN备份的时候,会把归档日志压成备份集(backup set),而有时候我们为了恢复数据的需要可能需要从这些备份集中解析出归档日志(archive log),这时可以用restore这个命令。
该命令的参数可以用SCN、SEQUENCE、TIME等,也可以附加preview参数先查看计划,该参数和list backup of archivelog是等效的。
1、根据时间查看需要的备份集:
ERPDB1@/orabak>rman target /
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命令来操作。
网友评论