Oracle RMAN 恢复数据库到不同主机(二)

时间:2022-03-29 06:26:30

我们在recover database时报一个错误:

       RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 149 and starting SCN of 3507749

       这里是提醒恢复到一个未知的scn号。我们在备份时只有148号归档,149号还是online redo,所以没有copy过来,如果我们不指定recover的结束时间,最后就会提示我们上面的信息:RMAN-06054.  所以在alter database mount之后,通过set until scn或者set until time命令设置恢复到的scn号或时间,就可以避免这个错误。如:

 

RMAN> run{
      set until sequence 149;
      recover database;
      }

executing command: SET until clause

Starting recover at 2016-05-12 23:27:34
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 2016-05-12 23:27:34

 

L、恢复完成之后,还有一个十分重要的工作要做,那就是恢复redo log files.如果源库的目录结构与新库的目录结构相同的话,在open resetlogs 时,会重新创建online redo log。但是现在redo log file文件的位置变了,open resetlogs时报如下错误:

RMAN> alter database open resetlogs;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of sql statement command at 05/12/2016 23:37:46
ORA-00344: unable to re-create online log '/u01/app/oracle/oradata/scp/redo01.log'
ORA-27040: file create error, unable to create file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 1

 由于源库和目标库的路径不相同,oracle试图在原来旧的位置去创建redo log file,但是却发现目标库上不存在这个路径了.解决方法仍然是将旧文件的路径重置为新的路径,但是我们怎么知道源库redo log file文件的位置呢?因为数据库已经mount上了,直接执行查询:

RMAN> select group#,type,member from v$logfile;

group# type MEMBER -------------------------------------------------------------------------------- 3 online /u01/app/oracle/oradata/scp/redo03.log 2 online /u01/app/oracle/oradata/scp/redo02.log 1 online /u01/app/oracle/oradata/scp/redo01.log

接下来我们将这些redo log file指定到新的文件位置:

RMAN>  run{
    ALTER DATABASE RENAME file '/u01/app/oracle/oradata/scp/redo01.log' TO '/home/OracleData/scp/redo01.log';
    ALTER DATABASE RENAME file '/u01/app/oracle/oradata/scp/redo02.log' TO '/home/OracleData/scp/redo02.log';
    ALTER DATABASE RENAME file '/u01/app/oracle/oradata/scp/redo03.log' TO '/home/OracleData/scp/redo03.log';
    }

Statement processed
Statement processed
Statement processed

 这个时候我们以resetlogs方式打开数据库,oracle报ora-00392的错误,

RMAN> alter database open resetlogs;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of sql statement command at 05/13/2016 00:07:37
ORA-00392: log 2 of thread 1 is being cleared, operation not allowed
ORA-00312: online log 2 thread 1: '/home/OracleData/scp/redo02.log'

我们这个时候来查询一下redo log file的状态:

RMAN>  select group#,sequence#,bytes,members,status from v$log;

    GROUP#  SEQUENCE#      BYTES    MEMBERS STATUS          
---------- ---------- ---------- ---------- ----------------
         1          0   52428800          1 CLEARING        
         3          0   52428800          1 CLEARING        
         2          0   52428800          1 CLEARING_CURRENT

以下是oracle的官方文档:

(1)CLEARING ---- Log is being re-created as an empty log after an ALTER DATABASE CLEAR LOGFILE statement.After the log is cleared, the status changes to UNUSED.

(2)CLEARING_CURRENT ----Current log is being cleared of a closed thread. The log can stay in this status  if there is some failure in the switch such as an I/O error writing the new log header.

解决办法:

RMAN> alter database clear logfile group 2;

Statement processed

RMAN>  select group#,sequence#,bytes,members,status from v$log;

    GROUP#  SEQUENCE#      BYTES    MEMBERS STATUS          
---------- ---------- ---------- ---------- ----------------
         1          0   52428800          1 CLEARING        
         3          0   52428800          1 CLEARING        
         2          0   52428800          1 CURRENT         

M、最后用open resetlogs方式打开数据库,并执行一些日志切换。

RMAN> alter database open resetlogs;

Statement processed

RMAN> alter system switch logfile;

Statement processed

RMAN> alter system switch logfile;

Statement processed

RMAN>  select group#,sequence#,bytes,members,status from v$log;

    GROUP#  SEQUENCE#      BYTES    MEMBERS STATUS          
---------- ---------- ---------- ---------- ----------------
         1          1   52428800          1 ACTIVE          
         2          2   52428800          1 ACTIVE          
         3          3   52428800          1 CURRENT 

N、这还没有完,我们需要创建spfile文件、临时表空间和密码文件:

RMAN> alter tablespace temp add tempfile '/home/OracleData/scp/temp01.dbf' size 29m reuse autoextend on next 640k maxsize 32767m; 
Statement processed

RMAN> create spfile from pfile; RMAN
> host; [oracle@scpdb rmanbak]$ orapwd file='$ORACLE_HOME/dbs/orapwscp' password='abc123!@#' entries=3

关于密码文件,要注意文件名格式 orapw$ORACLE_SID (注意不需要后缀名),具体请参照Oracle官方文档:
https://docs.oracle.com/cd/B28359_01/server.111/b28310/dba007.htm

 

至此,利用rman恢复数据库到不同主机的操作就全部完成了,记得马上做一次RMAN的全备!!!