阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

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

186次阅读
没有评论

共计 26146 个字符,预计需要花费 66 分钟才能阅读完成。

一、RMAN 备份的内容

RMAN 做数据库全备时包含了 数据文件、归档日志、控制文件和参数文件和备份日志,如下:

arch_20160223_08qukp2t_1_1  arch_20160223_0bqukp92_1_1  ctl_c-3234695588-20160223-01  rmanbak-20160223-0852.log  scp_20160223_09qukp2u_1_1  scp_20160223_0aqukp2u_1_1

二、测试环境

OS:CentOS release 6.4 (Final)

Database:Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

原平台与当前平台环境一致,但是 oracle 数据库目录结构不一致。

三、开始恢复

1、确认原数据库的 DBID(通过 RMAN 的备份日志,或者通过 RMAN 备份的控制文件名来识别),同时确认一下原数据库的实例名;

2、将 RMAN 备份的内容拷贝到目标数据库上;

3、设置好环境变量:

[oracle@dg1 ~]$ export NLS_DATA_FORMAT=’YYYY-MM-DD HH24:MI:SS’
[oracle@dg1 ~]$ export ORACLE_SID=scp
[oracle@dg1 ~]$ rman target /

Recovery Manager: Release 12.1.0.2.0 – Production on Fri May 6 22:18:52 2016

4、装载数据库并进行恢复

    A、装载数据库

RMAN> set dbid=3234695588;

executing command: SET DBID

RMAN> startup nomount;

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file ‘/u01/app/oracle/product/12.1.0.2/dbs/initscp.ora’

starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started

B、先恢复 spfile 文件(或者是 pfile 文件,可以修改各项参数),因为在 spfile 文件中包含了控制文件的位置

RMAN> restore spfile to pfile ‘$ORACLE_HOME/dbs/initscp.ora’ from ‘/home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01’;

OR:

RMAN> restore spfile to ‘$ORACLE_HOME/dbs/spfilescp.ora’ from ‘/home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01’;

C、根据 pfile 文件中的相关参数去修改本地系统目录,或者修改这个 pfile 文件来匹配本地系统中的路径和目录,我们选择后者

需要修改:oracle_base、*.audit_file_dest、*.control_files、*.db_recovery_file_dest、*.db_recovery_file_dest_size、*.diagnostic_dest、*.log_archive_dest_1、

memory_target、undo_tablespace 等。并在当前系统中创建好相关的目录和权限。

[oracle@dg1 dbs]$ vim initscp.ora

scp.__data_transfer_cache_size=0
scp.__db_cache_size=822083584
scp.__java_pool_size=16777216
scp.__large_pool_size=33554432
scp.__oracle_base=’/u01/app/oracle’#ORACLE_BASE set from environment
scp.__pga_aggregate_target=654311424
scp.__sga_target=1241513984
scp.__shared_io_pool_size=50331648
scp.__shared_pool_size=301989888
scp.__streams_pool_size=0
*.audit_file_dest=’/u01/app/oracle/admin/scp/adump’
*.audit_trail=’db’
*.compatible=’12.1.0.2.0′
*.control_files=’/u01/app/oracle/oradata/scp/control01.ctl’,’/u01/app/oracle/fast_recovery_area/scp/control02.ctl’
*.db_block_size=8192
*.db_domain=”
*.db_name=’scp’
*.db_recovery_file_dest=’/u01/app/oracle/fast_recovery_area’
*.db_recovery_file_dest_size=4560m
*.diagnostic_dest=’/u01/app/oracle’
*.dispatchers='(PROTOCOL=TCP) (SERVICE=scpXDB)’
*.log_archive_dest_1=’LOCATION=/OracleArch’
*.memory_target=1800m
*.open_cursors=300
*.processes=300
*.remote_login_passwordfile=’EXCLUSIVE’
*.undo_tablespace=’UNDOTBS1′

D、从修改后的 pfile 文件启动数据库,进行控制文件的恢复

RMAN> shutdown abort;
RMAN> startup nomount pfile=’$ORACLE_HOME/dbs/initscp.ora’;
RMAN> restore controlfile from ‘/home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01’;

Starting restore at 06-MAY-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=243 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/home/OracleData/scp/control01.ctl
output file name=/home/OracleArch/fast_recovery_area/control02.ctl
Finished restore at 06-MAY-16

————————————– 推荐阅读 ————————————–

RMAN 备份时遭遇 ORA-19571  http://www.linuxidc.com/Linux/2015-07/120409.htm

RMAN 配置归档日志删除策略 http://www.linuxidc.com/Linux/2013-11/92670.htm

Oracle 基础教程之通过 RMAN 复制数据库 http://www.linuxidc.com/Linux/2013-07/87072.htm

RMAN 备份策略制定参考内容 http://www.linuxidc.com/Linux/2013-03/81695.htm

RMAN 备份学习笔记 http://www.linuxidc.com/Linux/2013-03/81892.htm

Oracle 数据库备份加密 RMAN 加密 http://www.linuxidc.com/Linux/2013-03/80729.htm

RMAN 备份时遇到 ORA-19588  http://www.linuxidc.com/Linux/2015-07/120410.htm

————————————– 分割线 ————————————–

E、控制文件恢复后就可以 mount 数据库了

RMAN> alter database mount;

Statement processed
released channel: ORA_DISK_1

F、至此,控制文件已经恢复,数据库已经 mount,所有的 RMAN 配置参数均已设置,您应该验证路径以确保它们适用于该主机。

RMAN> show all;

RMAN configuration parameters for database with db_unique_name SCP are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘/orabackup/RmanBackupSet/20160223/ctl_%F’;
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM ‘AES128’; # default
CONFIGURE COMPRESSION ALGORITHM ‘BASIC’ AS OF RELEASE ‘DEFAULT’ OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE RMAN OUTPUT TO KEEP FOR 7 DAYS; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘/u01/app/oracle/product/12.1.0.2/dbs/snapcf_scp.f’; # default

G、为了能让 RMAN 找到恢复文件的位置,我们有两种途径可以实现:一是修改 RMAN 配置以符合当前备份文件所在位置,其次是将 RMAN 备份文件拷贝到配置文件中设定的位置(需要参考 RMAN 的备份日志)。在第一个方法中,为了让 RMAN 知道备份文件位置 /home/OracleBack/rmanbak,我们使用 catalog 命令:

RMAN> catalog start with ‘/home/OracleBack/rmanbak’;

Starting implicit crosscheck backup at 06-MAY-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=243 device type=DISK
Crosschecked 4 objects
Finished implicit crosscheck backup at 06-MAY-16

Starting implicit crosscheck copy at 06-MAY-16
using channel ORA_DISK_1
Finished implicit crosscheck copy at 06-MAY-16

searching for all files in the recovery area
cataloging files…
no files cataloged

searching for all files that match the pattern /home/OracleBack/rmanbak

List of Files Unknown to the Database
=====================================
File Name: /home/OracleBack/rmanbak/scp_20160223_09qukp2u_1_1
File Name: /home/OracleBack/rmanbak/arch_20160223_0bqukp92_1_1
File Name: /home/OracleBack/rmanbak/scp_20160223_0aqukp2u_1_1
File Name: /home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01
File Name: /home/OracleBack/rmanbak/arch_20160223_08qukp2t_1_1

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files…
cataloging done

List of Cataloged Files
=======================
File Name: /home/OracleBack/rmanbak/scp_20160223_09qukp2u_1_1
File Name: /home/OracleBack/rmanbak/arch_20160223_0bqukp92_1_1
File Name: /home/OracleBack/rmanbak/scp_20160223_0aqukp2u_1_1
File Name: /home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01
File Name: /home/OracleBack/rmanbak/arch_20160223_08qukp2t_1_1

H、对备份集做交叉检查,否则还原数据库时可能会报错

RMAN> crosscheck backup;

using channel ORA_DISK_1
crosschecked backup piece: found to be ‘EXPIRED’
backup piece handle=/orabackup/RmanBackupSet/20160223/arch_20160223_08qukp2t_1_1 RECID=8 STAMP=904553565
crosschecked backup piece: found to be ‘AVAILABLE’
backup piece handle=/home/OracleBack/rmanbak/arch_20160223_08qukp2t_1_1 RECID=16 STAMP=911172456
crosschecked backup piece: found to be ‘EXPIRED’
backup piece handle=/orabackup/RmanBackupSet/20160223/scp_20160223_0aqukp2u_1_1 RECID=9 STAMP=904553567
crosschecked backup piece: found to be ‘AVAILABLE’
backup piece handle=/home/OracleBack/rmanbak/scp_20160223_0aqukp2u_1_1 RECID=14 STAMP=911172456
crosschecked backup piece: found to be ‘EXPIRED’
backup piece handle=/orabackup/RmanBackupSet/20160223/scp_20160223_09qukp2u_1_1 RECID=10 STAMP=904553567
crosschecked backup piece: found to be ‘AVAILABLE’
backup piece handle=/home/OracleBack/rmanbak/scp_20160223_09qukp2u_1_1 RECID=12 STAMP=911172456
crosschecked backup piece: found to be ‘EXPIRED’
backup piece handle=/orabackup/RmanBackupSet/20160223/arch_20160223_0bqukp92_1_1 RECID=11 STAMP=904553762
crosschecked backup piece: found to be ‘AVAILABLE’
backup piece handle=/home/OracleBack/rmanbak/arch_20160223_0bqukp92_1_1 RECID=13 STAMP=911172456
crosschecked backup piece: found to be ‘AVAILABLE’
backup piece handle=/home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01 RECID=15 STAMP=911172456
Crosschecked 9 objects

I、通过控制文件获得表空间及数据文件列表

RMAN> report schema;

RMAN-06139: WARNING: control file is not current for REPORT SCHEMA
Report of database schema for database with db_unique_name SCP

List of Permanent Datafiles
===========================
File Size(MB) Tablespace          RB segs Datafile Name
—- ——– ——————– ——- ————————
1    0        SYSTEM              ***    /u01/app/oracle/oradata/scp/system01.dbf
2    0        ZYTK_AC              ***    /u01/app/oracle/oradata/scp/zytk_ac01.dbf
3    0        SYSAUX              ***    /u01/app/oracle/oradata/scp/sysaux01.dbf
4    0        UNDOTBS1            ***    /u01/app/oracle/oradata/scp/undotbs01.dbf
5    0        EXAMPLE              ***    /u01/app/oracle/oradata/scp/example01.dbf
6    0        USERS                ***    /u01/app/oracle/oradata/scp/users01.dbf
7    0        ZYTK_AC              ***    /u01/app/oracle/oradata/scp/zytk_ac02.dbf
8    0        ZYTK_ID              ***    /u01/app/oracle/oradata/scp/zytk_id01.dbf
9    0        ZYTK_ID              ***    /u01/app/oracle/oradata/scp/zytk_id02.dbf
10  0        ZYTK_OP              ***    /u01/app/oracle/oradata/scp/zytk_op01.dbf
11  0        ZYTK_OP              ***    /u01/app/oracle/oradata/scp/zytk_op02.dbf
12  0        ZYTK_TEST01          ***    /u01/app/oracle/oradata/scp/zytk_test01.dbf

List of Temporary Files
=======================
File Size(MB) Tablespace          Maxsize(MB) Tempfile Name
—- ——– ——————– ———– ——————–
1    60      TEMP                32767      /u01/app/oracle/oradata/scp/temp01.dbf

注意:restore 的时候不会对 temp 表空间进行 restore。所以等 restore 之后,我们需要手工创建 temp 表空间。

J、为了将数据文件恢复到不同于原来的目录结构中,必须编写脚本,重新命名数据文件的位置,最后进行全库的恢复。

(如果数据文件路径和原来的相同则直接还原数据库)

run{
set newname for datafile 1 to ‘/home/OracleData/scp/system01.dbf’;
set newname for datafile 2 to ‘/home/OracleData/scp/zytk_ac01.dbf’;
set newname for datafile 3 to ‘/home/OracleData/scp/sysaux01.dbf’;
set newname for datafile 4 to ‘/home/OracleData/scp/undotbs01.dbf’;
set newname for datafile 5 to ‘/home/OracleData/scp/example01.dbf’;
set newname for datafile 6 to ‘/home/OracleData/scp/users01.dbf’;
set newname for datafile 7 to ‘/home/OracleData/scp/zytk_ac02.dbf’;
set newname for datafile 8 to ‘/home/OracleData/scp/zytk_id01.dbf’;
set newname for datafile 9 to ‘/home/OracleData/scp/zytk_id02.dbf’;
set newname for datafile 10 to ‘/home/OracleData/scp/zytk_op01.dbf’;
set newname for datafile 11 to ‘/home/OracleData/scp/zytk_op02.dbf’;
set newname for datafile 12 to ‘/home/OracleData/scp/zytk_test01.dbf’;
restore database;
switch datafile all; 
}

对 switch datafile all 命令的说明:

– 对于 nocatalog 模式下,rman 备份的信息是保存在控制文件里的,包括数据文件的路径信息。这里的  switch datafile all  的作用,就是更新控制文件里的信息。如果不更新控制文件的话,则进行 recover 操作时还在原来的位置找文件。

K、还原数据库以后,进行 recover 操作

RMAN> recover database;

Starting recover at 06-MAY-16
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=148
channel ORA_DISK_1: reading from backup piece /home/OracleBack/rmanbak/arch_20160223_0bqukp92_1_1
channel ORA_DISK_1: piece handle=/home/OracleBack/rmanbak/arch_20160223_0bqukp92_1_1 tag=ZYTK_DB_FULL
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/home/OracleArch/ArchiveLog/1_148_899483175.dbf thread=1 sequence=148
unable to find archived log
archived log thread=1 sequence=149
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 05/06/2016 23:53:58
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 149 and starting SCN of 3507749

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2016-05/131325p2.htm

我们在 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/pwdscp.ora’ password=’abc123!@#’ entries=3

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

更多 Oracle 相关信息见 Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-05/131325.htm

一、RMAN 备份的内容

RMAN 做数据库全备时包含了 数据文件、归档日志、控制文件和参数文件和备份日志,如下:

arch_20160223_08qukp2t_1_1  arch_20160223_0bqukp92_1_1  ctl_c-3234695588-20160223-01  rmanbak-20160223-0852.log  scp_20160223_09qukp2u_1_1  scp_20160223_0aqukp2u_1_1

二、测试环境

OS:CentOS release 6.4 (Final)

Database:Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

原平台与当前平台环境一致,但是 oracle 数据库目录结构不一致。

三、开始恢复

1、确认原数据库的 DBID(通过 RMAN 的备份日志,或者通过 RMAN 备份的控制文件名来识别),同时确认一下原数据库的实例名;

2、将 RMAN 备份的内容拷贝到目标数据库上;

3、设置好环境变量:

[oracle@dg1 ~]$ export NLS_DATA_FORMAT=’YYYY-MM-DD HH24:MI:SS’
[oracle@dg1 ~]$ export ORACLE_SID=scp
[oracle@dg1 ~]$ rman target /

Recovery Manager: Release 12.1.0.2.0 – Production on Fri May 6 22:18:52 2016

4、装载数据库并进行恢复

    A、装载数据库

RMAN> set dbid=3234695588;

executing command: SET DBID

RMAN> startup nomount;

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file ‘/u01/app/oracle/product/12.1.0.2/dbs/initscp.ora’

starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started

B、先恢复 spfile 文件(或者是 pfile 文件,可以修改各项参数),因为在 spfile 文件中包含了控制文件的位置

RMAN> restore spfile to pfile ‘$ORACLE_HOME/dbs/initscp.ora’ from ‘/home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01’;

OR:

RMAN> restore spfile to ‘$ORACLE_HOME/dbs/spfilescp.ora’ from ‘/home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01’;

C、根据 pfile 文件中的相关参数去修改本地系统目录,或者修改这个 pfile 文件来匹配本地系统中的路径和目录,我们选择后者

需要修改:oracle_base、*.audit_file_dest、*.control_files、*.db_recovery_file_dest、*.db_recovery_file_dest_size、*.diagnostic_dest、*.log_archive_dest_1、

memory_target、undo_tablespace 等。并在当前系统中创建好相关的目录和权限。

[oracle@dg1 dbs]$ vim initscp.ora

scp.__data_transfer_cache_size=0
scp.__db_cache_size=822083584
scp.__java_pool_size=16777216
scp.__large_pool_size=33554432
scp.__oracle_base=’/u01/app/oracle’#ORACLE_BASE set from environment
scp.__pga_aggregate_target=654311424
scp.__sga_target=1241513984
scp.__shared_io_pool_size=50331648
scp.__shared_pool_size=301989888
scp.__streams_pool_size=0
*.audit_file_dest=’/u01/app/oracle/admin/scp/adump’
*.audit_trail=’db’
*.compatible=’12.1.0.2.0′
*.control_files=’/u01/app/oracle/oradata/scp/control01.ctl’,’/u01/app/oracle/fast_recovery_area/scp/control02.ctl’
*.db_block_size=8192
*.db_domain=”
*.db_name=’scp’
*.db_recovery_file_dest=’/u01/app/oracle/fast_recovery_area’
*.db_recovery_file_dest_size=4560m
*.diagnostic_dest=’/u01/app/oracle’
*.dispatchers='(PROTOCOL=TCP) (SERVICE=scpXDB)’
*.log_archive_dest_1=’LOCATION=/OracleArch’
*.memory_target=1800m
*.open_cursors=300
*.processes=300
*.remote_login_passwordfile=’EXCLUSIVE’
*.undo_tablespace=’UNDOTBS1′

D、从修改后的 pfile 文件启动数据库,进行控制文件的恢复

RMAN> shutdown abort;
RMAN> startup nomount pfile=’$ORACLE_HOME/dbs/initscp.ora’;
RMAN> restore controlfile from ‘/home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01’;

Starting restore at 06-MAY-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=243 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/home/OracleData/scp/control01.ctl
output file name=/home/OracleArch/fast_recovery_area/control02.ctl
Finished restore at 06-MAY-16

————————————– 推荐阅读 ————————————–

RMAN 备份时遭遇 ORA-19571  http://www.linuxidc.com/Linux/2015-07/120409.htm

RMAN 配置归档日志删除策略 http://www.linuxidc.com/Linux/2013-11/92670.htm

Oracle 基础教程之通过 RMAN 复制数据库 http://www.linuxidc.com/Linux/2013-07/87072.htm

RMAN 备份策略制定参考内容 http://www.linuxidc.com/Linux/2013-03/81695.htm

RMAN 备份学习笔记 http://www.linuxidc.com/Linux/2013-03/81892.htm

Oracle 数据库备份加密 RMAN 加密 http://www.linuxidc.com/Linux/2013-03/80729.htm

RMAN 备份时遇到 ORA-19588  http://www.linuxidc.com/Linux/2015-07/120410.htm

————————————– 分割线 ————————————–

E、控制文件恢复后就可以 mount 数据库了

RMAN> alter database mount;

Statement processed
released channel: ORA_DISK_1

F、至此,控制文件已经恢复,数据库已经 mount,所有的 RMAN 配置参数均已设置,您应该验证路径以确保它们适用于该主机。

RMAN> show all;

RMAN configuration parameters for database with db_unique_name SCP are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘/orabackup/RmanBackupSet/20160223/ctl_%F’;
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM ‘AES128’; # default
CONFIGURE COMPRESSION ALGORITHM ‘BASIC’ AS OF RELEASE ‘DEFAULT’ OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE RMAN OUTPUT TO KEEP FOR 7 DAYS; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘/u01/app/oracle/product/12.1.0.2/dbs/snapcf_scp.f’; # default

G、为了能让 RMAN 找到恢复文件的位置,我们有两种途径可以实现:一是修改 RMAN 配置以符合当前备份文件所在位置,其次是将 RMAN 备份文件拷贝到配置文件中设定的位置(需要参考 RMAN 的备份日志)。在第一个方法中,为了让 RMAN 知道备份文件位置 /home/OracleBack/rmanbak,我们使用 catalog 命令:

RMAN> catalog start with ‘/home/OracleBack/rmanbak’;

Starting implicit crosscheck backup at 06-MAY-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=243 device type=DISK
Crosschecked 4 objects
Finished implicit crosscheck backup at 06-MAY-16

Starting implicit crosscheck copy at 06-MAY-16
using channel ORA_DISK_1
Finished implicit crosscheck copy at 06-MAY-16

searching for all files in the recovery area
cataloging files…
no files cataloged

searching for all files that match the pattern /home/OracleBack/rmanbak

List of Files Unknown to the Database
=====================================
File Name: /home/OracleBack/rmanbak/scp_20160223_09qukp2u_1_1
File Name: /home/OracleBack/rmanbak/arch_20160223_0bqukp92_1_1
File Name: /home/OracleBack/rmanbak/scp_20160223_0aqukp2u_1_1
File Name: /home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01
File Name: /home/OracleBack/rmanbak/arch_20160223_08qukp2t_1_1

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files…
cataloging done

List of Cataloged Files
=======================
File Name: /home/OracleBack/rmanbak/scp_20160223_09qukp2u_1_1
File Name: /home/OracleBack/rmanbak/arch_20160223_0bqukp92_1_1
File Name: /home/OracleBack/rmanbak/scp_20160223_0aqukp2u_1_1
File Name: /home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01
File Name: /home/OracleBack/rmanbak/arch_20160223_08qukp2t_1_1

H、对备份集做交叉检查,否则还原数据库时可能会报错

RMAN> crosscheck backup;

using channel ORA_DISK_1
crosschecked backup piece: found to be ‘EXPIRED’
backup piece handle=/orabackup/RmanBackupSet/20160223/arch_20160223_08qukp2t_1_1 RECID=8 STAMP=904553565
crosschecked backup piece: found to be ‘AVAILABLE’
backup piece handle=/home/OracleBack/rmanbak/arch_20160223_08qukp2t_1_1 RECID=16 STAMP=911172456
crosschecked backup piece: found to be ‘EXPIRED’
backup piece handle=/orabackup/RmanBackupSet/20160223/scp_20160223_0aqukp2u_1_1 RECID=9 STAMP=904553567
crosschecked backup piece: found to be ‘AVAILABLE’
backup piece handle=/home/OracleBack/rmanbak/scp_20160223_0aqukp2u_1_1 RECID=14 STAMP=911172456
crosschecked backup piece: found to be ‘EXPIRED’
backup piece handle=/orabackup/RmanBackupSet/20160223/scp_20160223_09qukp2u_1_1 RECID=10 STAMP=904553567
crosschecked backup piece: found to be ‘AVAILABLE’
backup piece handle=/home/OracleBack/rmanbak/scp_20160223_09qukp2u_1_1 RECID=12 STAMP=911172456
crosschecked backup piece: found to be ‘EXPIRED’
backup piece handle=/orabackup/RmanBackupSet/20160223/arch_20160223_0bqukp92_1_1 RECID=11 STAMP=904553762
crosschecked backup piece: found to be ‘AVAILABLE’
backup piece handle=/home/OracleBack/rmanbak/arch_20160223_0bqukp92_1_1 RECID=13 STAMP=911172456
crosschecked backup piece: found to be ‘AVAILABLE’
backup piece handle=/home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01 RECID=15 STAMP=911172456
Crosschecked 9 objects

I、通过控制文件获得表空间及数据文件列表

RMAN> report schema;

RMAN-06139: WARNING: control file is not current for REPORT SCHEMA
Report of database schema for database with db_unique_name SCP

List of Permanent Datafiles
===========================
File Size(MB) Tablespace          RB segs Datafile Name
—- ——– ——————– ——- ————————
1    0        SYSTEM              ***    /u01/app/oracle/oradata/scp/system01.dbf
2    0        ZYTK_AC              ***    /u01/app/oracle/oradata/scp/zytk_ac01.dbf
3    0        SYSAUX              ***    /u01/app/oracle/oradata/scp/sysaux01.dbf
4    0        UNDOTBS1            ***    /u01/app/oracle/oradata/scp/undotbs01.dbf
5    0        EXAMPLE              ***    /u01/app/oracle/oradata/scp/example01.dbf
6    0        USERS                ***    /u01/app/oracle/oradata/scp/users01.dbf
7    0        ZYTK_AC              ***    /u01/app/oracle/oradata/scp/zytk_ac02.dbf
8    0        ZYTK_ID              ***    /u01/app/oracle/oradata/scp/zytk_id01.dbf
9    0        ZYTK_ID              ***    /u01/app/oracle/oradata/scp/zytk_id02.dbf
10  0        ZYTK_OP              ***    /u01/app/oracle/oradata/scp/zytk_op01.dbf
11  0        ZYTK_OP              ***    /u01/app/oracle/oradata/scp/zytk_op02.dbf
12  0        ZYTK_TEST01          ***    /u01/app/oracle/oradata/scp/zytk_test01.dbf

List of Temporary Files
=======================
File Size(MB) Tablespace          Maxsize(MB) Tempfile Name
—- ——– ——————– ———– ——————–
1    60      TEMP                32767      /u01/app/oracle/oradata/scp/temp01.dbf

注意:restore 的时候不会对 temp 表空间进行 restore。所以等 restore 之后,我们需要手工创建 temp 表空间。

J、为了将数据文件恢复到不同于原来的目录结构中,必须编写脚本,重新命名数据文件的位置,最后进行全库的恢复。

(如果数据文件路径和原来的相同则直接还原数据库)

run{
set newname for datafile 1 to ‘/home/OracleData/scp/system01.dbf’;
set newname for datafile 2 to ‘/home/OracleData/scp/zytk_ac01.dbf’;
set newname for datafile 3 to ‘/home/OracleData/scp/sysaux01.dbf’;
set newname for datafile 4 to ‘/home/OracleData/scp/undotbs01.dbf’;
set newname for datafile 5 to ‘/home/OracleData/scp/example01.dbf’;
set newname for datafile 6 to ‘/home/OracleData/scp/users01.dbf’;
set newname for datafile 7 to ‘/home/OracleData/scp/zytk_ac02.dbf’;
set newname for datafile 8 to ‘/home/OracleData/scp/zytk_id01.dbf’;
set newname for datafile 9 to ‘/home/OracleData/scp/zytk_id02.dbf’;
set newname for datafile 10 to ‘/home/OracleData/scp/zytk_op01.dbf’;
set newname for datafile 11 to ‘/home/OracleData/scp/zytk_op02.dbf’;
set newname for datafile 12 to ‘/home/OracleData/scp/zytk_test01.dbf’;
restore database;
switch datafile all; 
}

对 switch datafile all 命令的说明:

– 对于 nocatalog 模式下,rman 备份的信息是保存在控制文件里的,包括数据文件的路径信息。这里的  switch datafile all  的作用,就是更新控制文件里的信息。如果不更新控制文件的话,则进行 recover 操作时还在原来的位置找文件。

K、还原数据库以后,进行 recover 操作

RMAN> recover database;

Starting recover at 06-MAY-16
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=148
channel ORA_DISK_1: reading from backup piece /home/OracleBack/rmanbak/arch_20160223_0bqukp92_1_1
channel ORA_DISK_1: piece handle=/home/OracleBack/rmanbak/arch_20160223_0bqukp92_1_1 tag=ZYTK_DB_FULL
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/home/OracleArch/ArchiveLog/1_148_899483175.dbf thread=1 sequence=148
unable to find archived log
archived log thread=1 sequence=149
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 05/06/2016 23:53:58
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 149 and starting SCN of 3507749

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2016-05/131325p2.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计26146字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中