听说过还原(restore)数据库,表空间及数据库文件,使用归档日志恢复(recover)数据库,表空间,数据库文件。咦,还有还原归档日志这一说法呢?没错,可能我们忽略了还原归档日志这一个过程,原因是还原归档日志通常情况下是oracle在recover时自动完成的。大多数情况下我们是先还原数据库,恢复数据库,打开数据库。实际上在恢复数据库之前有一个动作,那就是还原归档日志,也就是将日志文件还原到缺省的归档位置,如果我们在备份归档日志时使用了delete [all] input子句的话。本文对此给出了单独还原归档日志以及恢复归档日志的示例以及restore archivelog的一些用法,仅仅是为了更好来的理解还原与恢复的过程,因为大多数情形下,数据文件被还原到缺省路径。如果是还原到非缺省路径,那就需要手动restore archivelog。
1、理解还原与恢复
还原(restore): 还原指将数据文件(可能受损)用之前的备份来替代或者复制到新的路径,这个是大多数情形和通常的说法。
恢复(recover): 将备份之后的归档日志apply到数据库,也就根据归档日志的事务将数据库刷新到特定或最新状态(通常在还原之后操作)。对于归
档日志中那些已提交的事务进行前滚,未提交的事务进行回滚。
还原归档日志: 还原归档日志是位于还原数据库与恢复数据库之间的这么一个过程。它会将那些在备份归档日志时使用delete [all] input方式
删除的归档日志还原到缺省的归档位置。在还原数据库之后,如果要做recover,也就是作介质恢复那就需要用到归档日志。那还原之后进行
recover需要的归档日志在哪里呢?归档日志在指定的归档路径那里,那到底有没有呢?如果有,还原时出现提示,归档日志已经在指定位置。
如果没有,但是备份的归档备份集那里有,也行啊。备份集里包含备份片,也就是打包了归档日志。那既然打包就要解包,解包到缺省路径
或指定路径。这就是还原归档日志。
2、示例演示还原归档日志
-
-
-
-
[oracle@linux3 ~]$ cat /etc/issue
-
Enterprise Linux Enterprise Linux Server release 5.5 (Carthage)
-
Kernel \r on an \m
-
-
[oracle@linux3 ~]$ 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';
-
-
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> 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;
-
-
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_NAME STATUS
-
-
USERS ONLINE
-
-
SQL> alter tablespace users offline immediate;
-
-
Tablespace altered.
-
-
SQL> select tablespace_name,status from dba_tablespaces where tablespace_name='USERS';
-
-
TABLESPACE_NAME STATUS
-
-
USERS OFFLINE
-
-
RMAN> restore datafile 4;
-
-
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;
-
-
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"
-
-
-
SQL> ho cp /u01/database/sybo3/fra/SYBO3/backupset/2013_07_26/users01.dbf /u01/database/sybo3/oradata/users01.dbf
-
-
-
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
-
-
-
-
-
-
SQL> ho ls -hltr /u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/*
-
-rw-r
-
-rw-r
-
-rw-r
-
-
-
RMAN> recover datafile 4;
-
-
Starting recover at 2013/07/26 20:39:56
-
using channel ORA_DISK_1
-
-
starting media recovery
-
-
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
-
-
-
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
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23490154/viewspace-1062384/
,如需转载,请注明出处,否则将追究法律责任。