rman 还原归档日志(restore archivelog)

rman 还原归档日志(restore archivelog),第1张

概述听说过还原(restore)数据库,表空间及数据库文件,使用归档日志恢复(recover)数据库,表空间,数据库文件。咦,还有还原归档日志这一说法呢?没错,可能我们忽略了还原归档日志这一个过程,原因是还原归档日志通常情况下是oracle在recover时自动完成的。大多数情况下我们是先还原数据库,恢复数据库,打开数据库。实际上在恢复数据库之前有一个动作,那就是还原归档日志,也就是将日志文件
听说过还原(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/issueEnterprise 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 catalogspecification does not match any control file copy in the repositoryspecification does not match any archived log in the repositoryList 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,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,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:39current log archivedusing target database control file instead of recovery catalogallocated channel: ORA_disK_1channel ORA_disK_1: SID=21 device type=disKchannel ORA_disK_1: starting archived log backup setchannel ORA_disK_1: specifying archived log(s) in backup set   --->备份集里包含的归档日志input archived log thread=1 sequence=27 RECID=23 STAMP=821823173input archived log thread=1 sequence=28 RECID=24 STAMP=821823287input archived log thread=1 sequence=29 RECID=25 STAMP=821823400channel ORA_disK_1: starting pIEce 1 at 2013/07/26 20:16:40channel ORA_disK_1: finished pIEce 1 at 2013/07/26 20:16:41pIEce handle=/u01/database/sybo3/fra/SYBO3/backupset/2013_07_26/o1_mf_annnn_TAG20130726T201640_8z4t58tn_.bkp tag=TAG20130726T201640 comment=NONEchannel ORA_disK_1: backup set complete,elapsed time: 00:00:01channel 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=821823173archived log file name=/u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_28_8z4t1q0s_.arc RECID=24 STAMP=821823287archived log file name=/u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_29_8z4t585k_.arc RECID=25 STAMP=821823400Finished 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      RobinSecond     RobinsonLast       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 timeORA-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 offlineORA-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:20using channel ORA_disK_1RMAN-00571: ===========================================================RMAN-00569: =============== ERROR MESSAGE STACK FolLOWS ===============RMAN-00571: ===========================================================RMAN-03002: failure of restore command at 07/26/2013 20:30:20ORA-01135: file 4 accessed for DML/query is offlineORA-01110: data file 4: /u01/database/sybo3/oradata/users01.dbfRMAN-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:12using channel ORA_disK_1RMAN-00571: ===========================================================RMAN-00569: =============== ERROR MESSAGE STACK FolLOWS ===============RMAN-00571: ===========================================================RMAN-03002: failure of restore command at 07/26/2013 20:31:12ORA-01135: file 4 accessed for DML/query is offlineORA-01110: data file 4: /u01/database/sybo3/oradata/users01.dbfRMAN-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:55using channel ORA_disK_1 channel ORA_disK_1: starting archived log restore to default destination   --->这个地方是关键提示,还原到缺省位置channel ORA_disK_1: restoring archived logarchived log thread=1 sequence=27channel ORA_disK_1: restoring archived logarchived log thread=1 sequence=28channel ORA_disK_1: restoring archived logarchived log thread=1 sequence=29channel ORA_disK_1: reading from backup pIEce /u01/database/sybo3/fra/SYBO3/backupset/2013_07_26/o1_mf_annnn_TAG20130726T201640_8z4t58tn_.bkpchannel ORA_disK_1: pIEce handle=/u01/database/sybo3/fra/SYBO3/backupset/2013_07_26/o1_mf_annnn_TAG20130726T201640_8z4t58tn_.bkp tag=TAG20130726T201640channel ORA_disK_1: restored backup pIEce 1channel ORA_disK_1: restore complete,elapsed time: 00:00:01Finished 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:56using channel ORA_disK_1starting media recovery   ---->下面提示归档日志已经存在,是因为我们之前做了restore archivelogarchived 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_.arcarchived 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_.arcarchived 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_.arcarchived log file name=/u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_27_8z4vc85o_.arc thread=1 sequence=27media recovery complete,elapsed time: 00:00:00Finished recover at 2013/07/26 20:39:56-->online tablespacesql> alter tablespace users online;tablespace altered.-->验证结过成功sql> select * from t1;SEQ        WHO---------- --------------------First      RobinSecond     RobinsonLast       End of test3、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
总结

以上是内存溢出为你收集整理的rman 还原归档日志(restore archivelog)全部内容,希望文章能够帮你解决rman 还原归档日志(restore archivelog)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/1165165.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存