灌溉梦想,记录脚步
« »
2014 年 12 月 11 日技术合集

在11gR2中使用RMAN复制数据库

RMAN 可以通过复制或者克隆,从一个运行的库中复制一个备份。可以用来在远程站点上复制数据库,下面示例中源库和复制库使用同样的SID:DB11G

在源库中创建备份。

$ rman target=/
 
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN> BACKUP DATABASE PLUS ARCHIVELOG

为目标库创建password文件

$ orapwd file=/u01/app/oracle/product/11.2.0/db_1/dbs/orapwDB11G password=password entries=10

在”$ORACLE_HOME/network/admin” 中增加”tnsnames.ora” 允许目标库访问源库。

# Added to the tnsnames.ora
DB11G-SOURCE =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = ol5-112-dup1)(PORT = 1521))
    )
    (CONNECT_DATA =
      (ORACLE_SID = DB11G)
    )
  )

创建pfile文件

# Minimum Requirement.
DB_NAME=DB11G
 
# 修改目录位置.
#DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/DB11G/','/u01/app/oracle/oradata/NEWSID/'
#LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/DB11G/','/u02/app/oracle/oradata/NEWSID/'

创建数据库启动所需的目录

$ mkdir -p /u01/app/oracle/oradata/DB11G
$ mkdir -p /u01/app/oracle/fast_recovery_area/DB11G
$ mkdir -p /u01/app/oracle/admin/DB11G/adump

拷贝归档和备份文件到目标库

$ scp -r oracle@ol5-112-dup1:/u01/app/oracle/fast_recovery_area/DB11G/archivelog /u01/app/oracle/fast_recovery_area/DB11G
$ scp -r oracle@ol5-112-dup1:/u01/app/oracle/fast_recovery_area/DB11G/backupset /u01/app/oracle/fast_recovery_area/DB11G
$ scp -r oracle@ol5-112-dup1:/u01/app/oracle/fast_recovery_area/DB11G/autobackup /u01/app/oracle/fast_recovery_area/DB11G
# 启动目标库
 
$ ORACLE_SID=DB11G; export ORACLE_SID
$ sqlplus / as sysdba
Start the database in NOMOUNT mode.
 
SQL> STARTUP NOMOUNT;
 
# 启动RMAN
$ ORACLE_SID=DB11G; export ORACLE_SID
 
# No target or catalog. Metadata comes from backups.
$ rman AUXILIARY /
 
# 连接到源库
$ rman TARGET sys/password@DB11G-SOURCE AUXILIARY /
 
# 读取Catalog
$ rman CATALOG rman/password@rman-catalog AUXILIARY /
 
# 或者使用下列方式连接
$ rman TARGET sys/password@DB11G-SOURCE CATALOG rman/password@rman-catalog AUXILIARY /

恢复示例

# 使用相同的备份路径和恢复路径直接恢复
DUPLICATE TARGET DATABASE TO DB11G
  SPFILE
  NOFILENAMECHECK;
 
# 恢复4天前的数据库
DUPLICATE TARGET DATABASE TO DB11G
  UNTIL TIME 'SYSDATE-4'
  SPFILE
  NOFILENAMECHECK;
 
# 指定本地备份文件的路径
DUPLICATE DATABASE TO DB11G
  SPFILE
  BACKUP LOCATION '/source/app/oracle/fast_recovery_area/DB11G'
  NOFILENAMECHECK;
 
# 使用制定的备份文件恢复到具体日期
DUPLICATE DATABASE TO DB11G
  SPFILE
  BACKUP LOCATION '/source/app/oracle/fast_recovery_area/DB11G'
  NOFILENAMECHECK
  UNTIL TIME "TO_DATE('2014-11-17 07:00:00', 'YYYY-MM-DD HH24:MI:SS')";
 
# 在复制过程中修改spfile文件
DUPLICATE DATABASE TO MYCLONE
  SPFILE
    parameter_value_convert ('DB11G','MYCLONE')
    set db_file_name_convert='/u01/oradata/db11g/','/u01/oradata/myclone/'
    set log_file_name_convert='/u01/oradata/db11g/','/u01/oradata/myclone/'
    set control_files='/u01/oradata/myclone/control01.ctl','/u01/oradata/myclone//control02.ctl','/u01/oradata/myclone/control03.ctl'
    set db_name='MYCLONE'
    set log_archive_dest_1='location=/u01/oradata/myclone/arch'
  BACKUP LOCATION '/source/app/oracle/fast_recovery_area/DB11G'
  NOFILENAMECHECK;

通常情况下并不需要RMAN备份后也能进行复制,只要打开归档模式即可,下面这是一个示例:

首先靠包password和pfile文件,启动到mount模式,并在远端和目标端创建tnsnames.ora

DB11G-DESTINATION =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = ol5-112-dup2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (ORACLE_SID = DB11G)
    )
  )
 
#在目标端创建listener.ora文件。
 
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = DB11G.WORLD)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = DB11G)
    )
  )
 
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = ol5-112-dup2.localdomain)(PORT = 1521))
    )
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )
 
ADR_BASE_LISTENER = /u01/app/oracle

在源段连接到RMAN,并执行复制

$ ORACLE_SID=DB11G; export ORACLE_SID
 
$ rman TARGET sys/password@DB11G-SOURCE AUXILIARY sys/password@DB11G-DESTINATION
Include the FROM ACTIVE DATABASE clause in the DUPLICATE command.
 
DUPLICATE DATABASE TO DB11G
  FROM ACTIVE DATABASE
  SPFILE
  NOFILENAMECHECK;

日志信息 »

该日志于2014-12-11 15:19由 kevin 发表在技术合集分类下, 你可以发表评论。除了可以将这个日志以保留源地址及作者的情况下引用到你的网站或博客,还可以通过RSS 2.0订阅这个日志的所有评论。

没有评论

发表评论 »