rman 还原归档日志(restore archivelog)
发布时间:2021-02-26 22:44:55 所属栏目:站长百科 来源:网络整理
导读:传闻过还原( 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/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,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: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 (编辑:湖南网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |