rman 还原归档日志(restore archivelog)

听说过还原(restore)数据库,表空间及数据库文件,使用归档日志恢复(recover)数据库,表空间,数据库文件。
咦,还有还原归档日志这一说法呢?没错,可能我们忽略了还原归档日志这一个过程,原因是还原归档日志通常情况下是oracle在recover时自动完成的。
大多数情况下我们是先还原数据库,恢复数据库,打开数据库。实际上在恢复数据库之前有一个动作,那就是还原归档日志,也就是将日志文件还原到缺省的归档位置,
如果我们在备份归档日志时使用了delete [all] input子句的话。

本文对此给出了单独还原归档日志以及恢复归档日志的示例以及restore archivelog的一些用法,仅仅是为了更好来的理解还原与恢复的过程,
因为大多数情形下,数据文件被还原到缺省路径。如果是还原到非缺省路径,那就需要手动restore archivelog。

 

1、理解还原与恢复
     还原(restore): 还原指将数据文件(可能受损)用之前的备份来替代或者复制到新的路径,这个是大多数情形和通常的说法。
     恢复(recover): 将备份之后的归档日志apply到数据库,也就根据归档日志的事务将数据库刷新到特定或最新状态(通常在还原之后操作)。对于归
           档日志中那些已提交的事务进行前滚,未提交的事务进行回滚。

     还原归档日志: 还原归档日志是位于还原数据库与恢复数据库之间的这么一个过程。它会将那些在备份归档日志时使用delete [all] input方式
           删除的归档日志还原到缺省的归档位置。在还原数据库之后,如果要做recover,也就是作介质恢复那就需要用到归档日志。

           那还原之后进行recover需要的归档日志在哪里呢?

           归档日志在指定的归档路径那里,那到底有没有呢?如果有,还原时出现提示,归档日志已经在指定位置。
           如果没有,但是备份的归档备份集那里有,也行啊。备份集里包含备份片,也就是打包了归档日志。那既然打包就要解包,解包到缺省路径
           或指定路径。这就是还原归档日志。

 

2、示例演示还原归档日志

--演示环境
--为了较好的模拟还原归档日志,我们仅仅使用了一个特定的数据文件进行copy方式备份,然后备份归档日志(备份时删除归档日志)
--接下来破坏数据文件,还原数据文件,还原归档日志文件,恢复日志文件。

[[email protected] ~]$ cat /etc/issue
Enterprise Linux Enterprise Linux Server release 5.5 (Carthage)
Kernel \r on an \m

[[email protected] ~]$ sqlplus -V

SQL*Plus: Release 11.2.0.1.0 Production

a、备份数据文件及归档日志
RMAN> list backup of archivelog all;   --->列出当前数据库已经备份的归档日志

specification does not match any backup in the repository

RMAN> list backupset;                  --->列出当前数据库已存在的备份集

specification does not match any backup in the repository

SQL> select username,default_tablespace from dba_users where username=‘SCOTT‘;  -->查看用户scott所在的表空间及数据文件

USERNAME                       DEFAULT_TABLESPACE
------------------------------ ------------------------------
SCOTT                          USERS

SQL> select name,file# from v$datafile where tablespace_name=‘USERS‘; 

NAME                                                              FILE#
------------------------------------------------------------ ----------
/u01/database/sybo3/oradata/users01.dbf                               4

SQL> conn scott/tiger;
Connected.
SQL> select name,sequence#,status,COMPLETION_TIME from v$archived_log where status=‘A‘;  -->当前系统无任何归档日志

no rows selected

SQL> host;

RMAN> copy datafile 4 to ‘/u01/database/sybo3/fra/SYBO3/backupset/2013_07_26/users01.dbf‘;  -->使用rman copy方式备份数据文件

RMAN> list copy;

using target database control file instead of recovery catalog
specification does not match any control file copy in the repository
specification does not match any archived log in the repository
List of Datafile Copies
=======================

Key     File S Completion Time     Ckp SCN    Ckp Time
------- ---- - ------------------- ---------- -------------------
3       4    A 2013/07/26 20:10:31 961662     2013/07/26 20:10:31
        Name: /u01/database/sybo3/fra/SYBO3/backupset/2013_07_26/users01.dbf
        Tag: TAG20130726T201031

-->准备测试表用于验证还原恢复是否成功
SQL> create table t1 (seq varchar2(10),who varchar2(20));

SQL> insert into t1 select ‘First‘,‘Robin‘ from dual;

SQL> commit;

SQL> alter system archive log current;   -->产生归档日志

SQL> select name,sequence#,status,COMPLETION_TIME from v$archived_log where status=‘A‘;

NAME                                                                              SEQUENCE# S COMPLETION_TIME
-------------------------------------------------------------------------------- ---------- - -----------------
/u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_27_8z4sy5ft_.arc             27 A 20130726 20:12:53

SQL> insert into t1 select ‘Second‘,‘Robinson‘ from dual;

SQL> commit;

SQL> alter system archive log current;   -->再次产生归档日志

SQL> select name,sequence#,status,COMPLETION_TIME from v$archived_log where status=‘A‘;

NAME                                                                              SEQUENCE# S COMPLETION_TIME
-------------------------------------------------------------------------------- ---------- - -----------------
/u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_27_8z4sy5ft_.arc             27 A 20130726 20:12:53
/u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_28_8z4t1q0s_.arc             28 A 20130726 20:14:47

-->下面备份归档日志并删除已备份的归当日志
RMAN> backup archivelog all delete input;

Starting backup at 2013/07/26 20:16:39
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=21 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set   --->备份集里包含的归档日志
input archived log thread=1 sequence=27 RECID=23 STAMP=821823173
input archived log thread=1 sequence=28 RECID=24 STAMP=821823287
input archived log thread=1 sequence=29 RECID=25 STAMP=821823400
channel ORA_DISK_1: starting piece 1 at 2013/07/26 20:16:40
channel ORA_DISK_1: finished piece 1 at 2013/07/26 20:16:41
piece handle=/u01/database/sybo3/fra/SYBO3/backupset/2013_07_26/o1_mf_annnn_TAG20130726T201640_8z4t58tn_.bkp tag=TAG20130726T201640 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)   --->这里提示删除
archived log file name=/u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_27_8z4sy5ft_.arc RECID=23 STAMP=821823173
archived log file name=/u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_28_8z4t1q0s_.arc RECID=24 STAMP=821823287
archived log file name=/u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_29_8z4t585k_.arc RECID=25 STAMP=821823400
Finished backup at 2013/07/26 20:16:41

b、模拟破坏数据文件
SQL> insert into t1 select ‘Last‘,‘End of test‘ from dual;

SQL> commit;

SQL> ho cat /dev/null>/u01/database/sybo3/oradata/users01.dbf   --->破坏数据文件

SQL> select * from t1;     --->此时buffer cache依旧可以查询到数据

SEQ        WHO
---------- --------------------
First      Robin
Second     Robinson
Last       End of test

SQL> alter system checkpoint;  --->实施检查点进程

System altered.

SQL> select * from t1;         --->此时数据文件不可访问
select * from t1
              *
ERROR at line 1:
ORA-00376: file 4 cannot be read at this time
ORA-01110: data file 4: ‘/u01/database/sybo3/oradata/users01.dbf‘

SQL> select * from v$recover_file;
select * from v$recover_file
              *
ERROR at line 1:
ORA-01135: file 4 accessed for DML/query is offline
ORA-01110: data file 4: ‘/u01/database/sybo3/oradata/users01.dbf‘

c、还原与恢复受损的数据文件
SQL> select TABLESPACE_NAME,STATUS from dba_tablespaces where tablespace_name=‘USERS‘; --->tablespace 依旧是Online

TABLESPACE_NAME                STATUS
------------------------------ ---------
USERS                          ONLINE

SQL> alter tablespace users offline immediate;   --->offline受损的tablespace

Tablespace altered.

SQL> select tablespace_name,status from dba_tablespaces where tablespace_name=‘USERS‘;  --->此时状态为offline

TABLESPACE_NAME                STATUS
------------------------------ ---------
USERS                          OFFLINE

RMAN> restore datafile 4;   --->此时使用restore datafile 方式提示失败

Starting restore at 2013/07/26 20:30:20
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 07/26/2013 20:30:20
ORA-01135: file 4 accessed for DML/query is offline
ORA-01110: data file 4: ‘/u01/database/sybo3/oradata/users01.dbf‘
RMAN-06010: error while looking up datafile: 4

RMAN> restore tablespace users; --->此时使用restore tablespace 方式提示失败,看来,对于copy方式的备份,必须要copy回去
                                      --->后来看了一下语法,restore (datafile 4) FROM DATAFILECOPY方式可以搞定,括号不能省略
Starting restore at 2013/07/26 20:31:12
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 07/26/2013 20:31:12
ORA-01135: file 4 accessed for DML/query is offline
ORA-01110: data file 4: ‘/u01/database/sybo3/oradata/users01.dbf‘
RMAN-06019: could not translate tablespace name "USERS"

-->下面直接使用copy方式进行还原
SQL> ho cp /u01/database/sybo3/fra/SYBO3/backupset/2013_07_26/users01.dbf /u01/database/sybo3/oradata/users01.dbf

-->接下来我们还原归档日志,制定了from sequence子句,实际上,如果我们没有指定restore archivelog,在recover时也会自动完成还原归档日志
RMAN> restore archivelog from sequence 27; 

Starting restore at 2013/07/26 20:36:55
using channel ORA_DISK_1

channel ORA_DISK_1: starting archived log restore to default destination   --->这个地方是关键提示,还原到缺省位置
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=27
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=28
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=29
channel ORA_DISK_1: reading from backup piece /u01/database/sybo3/fra/SYBO3/backupset/2013_07_26/o1_mf_annnn_TAG20130726T201640_8z4t58tn_.bkp
channel ORA_DISK_1: piece handle=/u01/database/sybo3/fra/SYBO3/backupset/2013_07_26/o1_mf_annnn_TAG20130726T201640_8z4t58tn_.bkp tag=TAG20130726T201640
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2013/07/26 20:36:57

--Author : Robinson
--Blog   : http://blog.csdn.net/robinson_0612

-->此时在缺省的路径下可以看到已经被还原的归档日志文件 

SQL> ho ls -hltr /u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/*
-rw-r----- 1 oracle oinstall  13K Jul 26 20:36 /u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_29_8z4vc85w_.arc
-rw-r----- 1 oracle oinstall 4.5K Jul 26 20:36 /u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_28_8z4vc85z_.arc
-rw-r----- 1 oracle oinstall 4.0M Jul 26 20:36 /u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_27_8z4vc85o_.arc
-->进行介质恢复

RMAN> recover datafile 4;
Starting recover at 2013/07/26 20:39:56
using channel ORA_DISK_1
starting media recovery   ---->下面提示归档日志已经存在,是因为我们之前做了restore archivelog
archived log for thread 1 with sequence 27 is already on disk as file /u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_27_8z4vc85o_.arc
archived log for thread 1 with sequence 28 is already on disk as file /u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_28_8z4vc85z_.arc
archived log for thread 1 with sequence 29 is already on disk as file /u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_29_8z4vc85w_.arc
archived log file name=/u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_27_8z4vc85o_.arc thread=1 sequence=27
media recovery complete, elapsed time: 00:00:00
Finished recover at 2013/07/26 20:39:56

-->online tablespace
SQL> alter tablespace users online;
Tablespace altered.

-->验证结过成功
SQL> select * from t1;
SEQ        WHO
---------- --------------------
First      Robin
Second     Robinson
Last       End of test

3、restore archivelog 的其它用法
     restore archivelog all;   还原全部归档日志文件
     restore archivelog from logseq 27 ;  还原log sequence为27之后的所有归档日志
     restore archivelog from logseq 27 until logseq 29; 还原log sequence为27到29这几个归档日志
     restore archivelog from time ‘sysdate-7‘; 还原七天以内的归档日志
     restore archivelog until logseq 29; 还原到seqence 为29的日志文件为止

     set archivelog destination to ‘/u01/database/sybo5/arch‘;设定还原日志文件到新路径,如
     run{
     set archivelog destination to ‘/u01/database/sybo5/arch‘;
     restore archivelog low logseq 27;}

     关于resoter archive的更多用法: http://docs.oracle.com/cd/B19306_01/backup.102/b14194/rcmsynta008.htm

原文地址:https://www.cnblogs.com/chendian0/p/10971466.html

时间: 2024-10-13 05:50:35

rman 还原归档日志(restore archivelog)的相关文章

RMAN备份归档日志ORA-19575

RMAN备份归档日志ORA-19575 一.问题描述 1)环境oracle 10g; 2)报错现象RMAN进行备份归档报错失败ORA-19575 二.问题处理 1)根据客户说明的现象,百度了一波(详见参考链接) 2)操作系统mv修改名称存在问题的归档日志后,crosscheck检查归档日志,delete删除无效的归档日志后,再次进行备份,问题已解决. 三.参考链接 https://smarttechways.com/2012/11/01/ora-19575-expected-blocks-in-

通过RMAN删除归档日志不释放问题

我的生产环境中归档日志满了,通过如下脚本删除后,空间并没有释放,看有网友有相关的解决思路,可以跟大家一起分享一下: RMAN> crosscheck archivelog all; RMAN> delete expried archivelog all; 关于rm删除文件空间不释放的问题可以写成一个FAQ了 一般说来不会出现rm掉不释放空间的情况出现这样的情况一般是由于有进程在向文件中写数据或有进程正在访问文件而此时rm文件则会出现不释放空间的情况 理解这样的问题需要理解rm的操作内含一个文件

RMAN删除归档日志不释放问题

今天同事问到一个问题,他那边的一套Oracle 11g数据库使用RMAN没办法删除旧的归档,导致磁盘使用率很高. [email protected]:[/opt/oracle/archive/db] ls -ltr |moretotal 3059881082 -rw-r-----   1 oracle     oinstall   725320704 May 20  2016 1_1_91233774.dbf -rw-rw----   1 oracle     oinstall   175693

restore archivelog 常用用法

         restore archivelog all;   还原全部归档日志文件      restore archivelog from logseq 2213 ;  还原log sequence为2213之后的所有归档日志      restore archivelog from logseq 2213 until logseq 2222; 还原log sequence为2213到2222这几个归档日志       restore archivelog from time 'sys

Oracle数据库从RMAN备份集片段还原指定单个归档日志进行日志挖掘分析

起因:业务已知在之前某个时间点范围内发生了可疑异常操作,希望通过日志挖掘来审查SQL动作 现状:生产库在线归档已备份后删除,RMAN归档备份已经刷出超期的备份集文件 需求:通过RMAN还原归档到线上以进行日志挖掘 定位归档日志涉及范围: select * from v$archived_log l where to_date('2018-11-12 16:18:51','yyyy-mm-dd hh24:mi:ss') between L.FIRST_TIME and L.NEXT_TIME; 假

RMAN数据库恢复之恢复归档日志文件

恢复归档日志文件如果只是为了在恢复数据文件之后应用归档文件,那并不需要手动对归档文件进行恢复,RMAN会在RECOVER时自动对适当的归档进行恢复.单独恢复归档文件一般是有特别的需求,如创建了Data Guard环境.Standby端丢失了部分归档文件,需要从Primary端重新获取.1.恢复全部归档日志文件RMAN> RESTORE ARCHIVELOG ALL; 2.恢复归档序号为20至30之间的归档文件RMAN> RESTOER ARCHIVELOG SEQUENCE BETWEEN 2

11g RMAN Restore archivelog用法

I.备份所有归档日志文件 RMAN> BACKUP FORMAT '/u01/backup/arch_%U_%T' skip inaccessible filesperset 5 ARCHIVELOG ALL DELETE INPUT; II.使用RMAN方式清除 RMAN清除方式会自动清除磁盘上的归档日志文件,同时会释放控制文件中对应的归档日志的归档信息. 可以基于不同的条件来清除归档日志,如基于SCN,基于SEQUENCE,基于TIME等方式. 对于上述的三种方式又可以配合from, unt

使用RMAN备份时应如何处置归档日志文件

昨天去某客户部署RMAN备份,在跑shell脚本的时候,提示找不到归档日志,因为客户那里之前只对数据库做EXPDP逻辑导出备份,并且每天都自动删除前一天的归档,每个归档的生成量大概在200M左右,因为考虑磁盘空间比较紧张,不得已而为之. 在我的脚本中,是采用backup database format 'xxx' plus archivelog format 'xxx'的方式进行备份的,在执行RMAN脚本时,由于是先对归档日志进行备份,再对数据库进行备份的,在脚本的输出日志中,提示找不到35xx

归档日志的一些操作,设置,检查无效文件

有关归档的一些操作       ps: --这个符号是解释 有颜色字体标示是需要注意的地方     [[email protected] ~]# su – oracle   --设置一下ORACLE_SID [[email protected] ~]$ export ORACLE_SID=denver   --查看一下denver实例是否启动 [[email protected] ~]$ ps -ef|grep oracle root    27264  6887  0 04:23 tty1