热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

RMAN异机duplicate复制数据库

RMAN异机复制和同机复制操作步骤是一样的,不同的是我们需要把备份的文件copy到辅助库上去。

RMAN 异机复制和同机复制操作步骤是一样的,不同的是我们需要把备份的文件copy到辅助库上去。

实验平台: RedHat Linux 5.5 + Oracle 11g
RMAN 异机复制和同机复制操作步骤是一样的,不同的是我们需要把备份的文件copy到辅助库上去。

我们以实例名相同的为例,实例名不同也一样,在pfile里修改对应参数就可以了。

步骤如下:
(1)构建辅助数据库目录结构
(2)创建pfile,并复制到辅助数据库,修改相关内容
(3)创建辅助实例口令文件
(4)RMAN 备份源库
(5)添加配置监听
(6)将源库备份文件拷贝到辅助库相同位置
(7)用pfile文件,将辅助数据库启动到nomount 状态
(8)执行RMAN duplicate命令复制数据库
(9)创建spfile文件
(10)在磁带上恢复备份
(11)使用DBNEWID程序生成新的DBID

一.构建辅助数据库目录结构
1.1 Oracle data 目录

1.2 其他目录
[oracle@localhost oracle]$ mkdir -p /u01/app/oracle/admin/orcl/adump
[oracle@localhost oracle]$ ls
admin oradata oraInventory product
[oracle@localhost oracle]$ cd admin
[oracle@localhost admin]$ ls
[oracle@localhost admin]$ mkdir orcl
[oracle@localhost admin]$ ls
[oracle@localhost admin]$ cd orcl
[oracle@localhost orcl]$ mkdir adump
[oracle@localhost orcl]$ mkdir bdump
[oracle@localhost orcl]$ mkdir cdump
[oracle@localhost orcl]$ mkdir dpdump
[oracle@localhost orcl]$ mkdir pfile
[oracle@localhost orcl]$ mkdir udump

二. 创建pfile,复制到辅助数据库,并修改相关参数

2.1 在源库上创建pfile 文件
SQL> create pfile from spfile;

2.2 用scp 命令将pfile 文件传到辅助库。要放在$ORACLE_HOME/dbs目录下,不然ORACLE 不识别。
[oracle@db1 orcl]$ cd /u01/app/oracle/product/10.2.0/db_1/dbs
[oracle@db1 dbs]$ scp initorcl.ora 192.168.1.21:/$ORACLE_HOME/dbs

2.3 在辅助库上确认文件是否传送过来

2.4 在辅助库上修改pfile参数

说明,在这里我没有做修改,因为我异机复制实例名相同,存储位置也相同。 如果说你复制的不同的话,就需要修改相关的实例名。 如果存储位置不同的话,还需要添加以下参数,对数据文件位置进行转换。

db_file_name_convert
log_file_name_convert

三.创建辅助实例ORCL 的口令文件
[oracle@localhost dbs]$ cd $ORACLE_HOME/bin
[oracle@localhost bin]$ orapwd file=$ORACLE_HOME/dbs/orapworcl password=admin

创建完后,数据库需要重启动,新的口令文件才能生效。

四.RMAN 备份源库(orcl)
[oracle@db1 backup]$ rman target /
RMAN>RUN {
allocate channel c1 type disk;
allocate channel c2 type disk;
BACKUP skip inaccessible filesperset 3 DATABASE FORMAT '/orabackup/full_%D_%s_%p_%T';
sql 'alter system archive log current';
BACKUP skip inaccessible filesperset 10 ARCHIVELOG ALL FORMAT '/orabackup/arc_%D_%s_%p_%T' DELETE INPUT;
backup current controlfile format='/orabackup/ctl_%D_%s_%p_%T';
backup spfile format='/orabackup/spf_%D_%s_%p_%T';
release channel c2;
release channel c1;
}

五.添加,配置监听
5.1 在辅助库的Listener.ora 文件中,添加如下内容
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = standby)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = orcl)
)
(SID_DESC =
(GLOBAL_DBNAME = orcl2)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = orcl2)
)
)

5.2 修改源库的tnsnames.ora 文件,添加如下内容:
orcl2_au =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.99.92)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl2)
)
)

六.将源库的备份拷贝到辅助数据库的相同位置

这里有两种方法,一种直接在辅助库上建相同的目录结构,在用SCP 命令把这些备份文件copy过去,但是这样会占用大量的网络资源。 还有一种就是建好目录结构后用NFS直接Mount上去。 在这里我们用后面一种方法。

6.1 在辅助库上建相同的备份目录结构

6.2 将源库的备份挂载到辅助库上

6.2.1 在源库上将/u02/backup 目录添加到共享

[root@rhel5 ~]# at /etc/exports
/orabackup *(rw,async,anOnuid=65534,anOngid=65534)
[root@rhel5 ~]# service nfs start

6.2.2 在辅助库上挂载源库的目录,注意,mount命令必须以root用户执行
[root@rhel5 orabackup]# mount -t nfs -o rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,vers=3,timeo=600,actimeo=0 192.168.99.91:/orabackup /orabackup
-- 注意: 在挂载NFS的时候,一定要加上-t -o 参数,不然在RMAN 复制的时候会报错:
--ORA-27054: NFS file system where the file is created or resides is not mounted with correct options

七. 启动辅助库至nomount 状态,注意使用pfile参数启动

SQL> startup nomount pfile=?/dbs/initorcl2.ora

SQL> exit -- 启动后就退出session,因为在duplicata的时候不能有session连接

八. RMAN 连接到目标实例和辅助实例,,运行duplicate 命令复制数据库

[oracle@rhel5 admin]$ rman target / auxiliary sys/oracle@orcl2_au

RMAN> run {
allocate channel t1 type disk;
allocate channel t2 type disk;
allocate channel t3 type disk;
allocate auxiliary channel a2 type disk;
allocate auxiliary channel a3 type disk;
allocate auxiliary channel a4 type disk;
duplicate target database to orcl2 nofilenamecheck
logfile
'/oradata/orcl2/redo01.dbf' size 50m,
'/oradata/orcl2/redo02.dbf' size 50m,
'/oradata/orcl2/redo03.dbf' size 50m;
}

注: 这个地方有2个地方需要说明:
(1) Nofilenamecheck 参数:
如果在复制时,位置不同时,我们会用参数db_file_name_convert 对文件位置进行转换。 但是在这个复制示例中我们用的是相同的位置。 所以这里必须加上nofilenamecheck参数。 该参数通知复制操作不必在执行还原操作前确认文件名是不同的。如果没有指定nofilenamecheck参数,rman会给出如下错误:
RMAN-05001: auxiliary filename /u01/app/oracle/oradata/orcl/example01.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary filename /u01/app/oracle/oradata/orcl/users01.dbf conflicts with a file used by the target database

(2) logfile 参数:
在完成复制进程并执行最有一条open resetlogs命令时,RMAN 必须为辅助数据库构建全新的日志文件。 如上面命令所示,我们可以在duplicate 命令中指定logfile参数,并指定使用的日志文件的大小,数目和位置。
还可以在pfile里指定log_file_name_convert 参数来进行转换。 这种方法相对而言要简单一点。

using target database control file instead of recovery catalog
allocated channel: t1
channel t1: SID=46 device type=DISK

allocated channel: t2
channel t2: SID=43 device type=DISK

allocated channel: t3
channel t3: SID=36 device type=DISK

allocated channel: a2
channel a2: SID=18 device type=DISK

allocated channel: a3
channel a3: SID=21 device type=DISK

allocated channel: a4
channel a4: SID=22 device type=DISK

Starting Duplicate Db at 22-OCT-13

contents of Memory Script:
{
sql clone "alter system set db_name =
''ORCL2'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''ORCL2'' comment=
''Modified by RMAN duplicate'' scope=spfile";
shutdown clone immediate;
startup clone force nomount
restore clone primary controlfile;
alter clone database mount;
}
executing Memory Script
sql statement: alter system set db_name = ''ORCL2'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set db_unique_name = ''ORCL2'' comment= ''Modified by RMAN duplicate'' scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area 849530880 bytes

Fixed Size 1339824 bytes
Variable Size 629149264 bytes
Database Buffers 213909504 bytes
Redo Buffers 5132288 bytes
allocated channel: a2
channel a2: SID=19 device type=DISK
allocated channel: a3
channel a3: SID=20 device type=DISK
allocated channel: a4
channel a4: SID=21 device type=DISK

Starting restore at 22-OCT-13

channel a2: starting datafile backup set restore
channel a2: restoring control file
channel a2: reading from backup piece /orabackup/ctl_22_37_1_20131022
channel a2: piece handle=/orabackup/ctl_22_37_1_20131022 tag=TAG20131022T140831
channel a2: restored backup piece 1
channel a2: restore complete, elapsed time: 00:00:03
output file name=/oradata/orcl2/datafiles/control01.ctl
output file name=/oradata/orcl2/datafiles/control02.ctl
Finished restore at 22-OCT-13

database mounted

contents of Memory Script:
{
set until scn 883198;
set newname for datafile 1 to
"/oradata/orcl2/datafilessystem01.dbf";
set newname for datafile 2 to
"/oradata/orcl2/datafilessysaux01.dbf";
set newname for datafile 3 to
"/oradata/orcl2/datafilesundotbs01.dbf";
set newname for datafile 4 to
"/oradata/orcl2/datafileSUSErs01.dbf";
set newname for datafile 5 to
"/oradata/orcl2/datafilesexample01.dbf";
restore
clone database
;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 22-OCT-13

channel a2: starting datafile backup set restore
channel a2: specifying datafile(s) to restore from backup set
channel a2: restoring datafile 00001 to /oradata/orcl2/datafilessystem01.dbf
channel a2: restoring datafile 00004 to /oradata/orcl2/datafilesusers01.dbf
channel a2: reading from backup piece /orabackup/full_22_33_1_20131022
channel a3: starting datafile backup set restore
channel a3: specifying datafile(s) to restore from backup set
channel a3: restoring datafile 00002 to /oradata/orcl2/datafilessysaux01.dbf
channel a3: restoring datafile 00003 to /oradata/orcl2/datafilesundotbs01.dbf
channel a3: restoring datafile 00005 to /oradata/orcl2/datafilesexample01.dbf
channel a3: reading from backup piece /orabackup/full_22_34_1_20131022
channel a3: piece handle=/orabackup/full_22_34_1_20131022 tag=TAG20131022T140657
channel a3: restored backup piece 1
channel a3: restore complete, elapsed time: 00:01:09
channel a2: piece handle=/orabackup/full_22_33_1_20131022 tag=TAG20131022T140657
channel a2: restored backup piece 1
channel a2: restore complete, elapsed time: 00:01:21
Finished restore at 22-OCT-13

contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=829493590 file name=/oradata/orcl2/datafilessystem01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=829493590 file name=/oradata/orcl2/datafilessysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=7 STAMP=829493590 file name=/oradata/orcl2/datafilesundotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=829493590 file name=/oradata/orcl2/datafilesusers01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=9 STAMP=829493590 file name=/oradata/orcl2/datafilesexample01.dbf

contents of Memory Script:
{
set until scn 883198;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 22-OCT-13
starting media recovery

channel a2: starting archived log restore to default destination
channel a2: restoring archived log
archived log thread=1 sequence=17
channel a2: restoring archived log
archived log thread=1 sequence=18
channel a2: reading from backup piece /orabackup/arc_22_36_1_20131022
channel a2: piece handle=/orabackup/arc_22_36_1_20131022 tag=TAG20131022T140825
channel a2: restored backup piece 1
channel a2: restore complete, elapsed time: 00:00:01
archived log file name=/oradata/orcl2/arch/1_17_829415524.arc thread=1 sequence=17
channel clone_default: deleting archived log(s)
archived log file name=/oradata/orcl2/arch/1_17_829415524.arc RECID=15 STAMP=829493595
archived log file name=/oradata/orcl2/arch/1_18_829415524.arc thread=1 sequence=18
channel clone_default: deleting archived log(s)
archived log file name=/oradata/orcl2/arch/1_18_829415524.arc RECID=16 STAMP=829493595
media recovery complete, elapsed time: 00:00:02
Finished recover at 22-OCT-13

contents of Memory Script:
{
shutdown clone immediate;
startup clone nomount;
sql clone "alter system set db_name =
''ORCL2'' comment=
''Reset to original value by RMAN'' scope=spfile";
sql clone "alter system reset db_unique_name scope=spfile";
shutdown clone immediate;
startup clone nomount;
}
executing Memory Script
database dismounted
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 849530880 bytes

Fixed Size 1339824 bytes
Variable Size 629149264 bytes
Database Buffers 213909504 bytes
Redo Buffers 5132288 bytes
allocated channel: a2
channel a2: SID=19 device type=DISK
allocated channel: a3
channel a3: SID=20 device type=DISK
allocated channel: a4
channel a4: SID=21 device type=DISK
sql statement: alter system set db_name = ''ORCL2'' comment= ''Reset to original value by RMAN'' scope=spfile
sql statement: alter system reset db_unique_name scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started

Total System Global Area 849530880 bytes

Fixed Size 1339824 bytes
Variable Size 629149264 bytes
Database Buffers 213909504 bytes
Redo Buffers 5132288 bytes
allocated channel: a2
channel a2: SID=19 device type=DISK
allocated channel: a3
channel a3: SID=20 device type=DISK
allocated channel: a4
channel a4: SID=21 device type=DISK
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORCL2" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/oradata/orcl2/redo01.dbf' SIZE 50 M ,
GROUP 2 '/oradata/orcl2/redo02.dbf' SIZE 50 M ,
GROUP 3 '/oradata/orcl2/redo03.dbf' SIZE 50 M
DATAFILE
'/oradata/orcl2/datafilessystem01.dbf'
CHARACTER SET ZHS16GBK

contents of Memory Script:
{
set newname for tempfile 1 to
"/oradata/orcl2/datafilestemp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy "/oradata/orcl2/datafilessysaux01.dbf",
"/oradata/orcl2/datafilesundotbs01.dbf",
"/oradata/orcl2/datafilesusers01.dbf",
"/oradata/orcl2/datafilesexample01.dbf";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /oradata/orcl2/datafilestemp01.dbf in control file
cataloged datafile copy
datafile copy file name=/oradata/orcl2/datafilessysaux01.dbf RECID=1 STAMP=829493815
cataloged datafile copy
datafile copy file name=/oradata/orcl2/datafilesundotbs01.dbf RECID=2 STAMP=829493815
cataloged datafile copy
datafile copy file name=/oradata/orcl2/datafilesusers01.dbf RECID=3 STAMP=829493815
cataloged datafile copy
datafile copy file name=/oradata/orcl2/datafilesexample01.dbf RECID=4 STAMP=829493815

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=829493815 file name=/oradata/orcl2/datafilessysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=829493815 file name=/oradata/orcl2/datafilesundotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=829493815 file name=/oradata/orcl2/datafilesusers01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=829493815 file name=/oradata/orcl2/datafilesexample01.dbf

contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 22-OCT-13
released channel: t1
released channel: t2
released channel: t3
released channel: a2
released channel: a3
released channel: a4

RMAN>

九. 创建spfile,并验证数据库
通过上面8步的操作,复制操作已经完成。 我们现在创建一个spfile。
SQL> create spfile from pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initorcl.ora';
File created.

SQL> select name from v$database;
NAME
---------
ORCL2

十. 在远程服务器上复制磁带备份
如果在远程服务器上复制磁带备份,必须配置辅助通道,以反映介质管理器的需求。 除了指定介质管理器和用于常规通道的类或池外,还必须指定目标客户端名称,如下所示:
RMAN> configure auxiliary channel 1 device type sbt parms="env=(nb_ora_serv=db1,nb_ora_client=db2)";

推荐阅读
  • 本文深入探讨了SQL数据库中常见的面试问题,包括如何获取自增字段的当前值、防止SQL注入的方法、游标的作用与使用、索引的形式及其优缺点,以及事务和存储过程的概念。通过详细的解答和示例,帮助读者更好地理解和应对这些技术问题。 ... [详细]
  • 主调|大侠_重温C++ ... [详细]
  • 本文介绍了数据库体系的基础知识,涵盖关系型数据库(如MySQL)和非关系型数据库(如MongoDB)的基本操作及高级功能。通过三个阶段的学习路径——基础、优化和部署,帮助读者全面掌握数据库的使用和管理。 ... [详细]
  • 福克斯新闻数据库配置失误导致1300万条敏感记录泄露
    由于数据库配置错误,福克斯新闻暴露了一个58GB的未受保护数据库,其中包含约1300万条网络内容管理记录。任何互联网用户都可以访问这些数据,引发了严重的安全风险。 ... [详细]
  • 本文详细介绍了优化DB2数据库性能的多种方法,涵盖统计信息更新、缓冲池调整、日志缓冲区配置、应用程序堆大小设置、排序堆参数调整、代理程序管理、锁机制优化、活动应用程序限制、页清除程序配置、I/O服务器数量设定以及编入组提交数调整等方面。通过这些技术手段,可以显著提升数据库的运行效率和响应速度。 ... [详细]
  • 1.执行sqlsever存储过程,消息:SQLServer阻止了对组件“AdHocDistributedQueries”的STATEMENT“OpenRowsetOpenDatas ... [详细]
  • PostgreSQL 最新动态 —— 2022年4月6日
    了解 PostgreSQL 社区的最新进展和技术分享 ... [详细]
  • 本文详细介绍了如何在云服务器上配置Nginx、Tomcat、JDK和MySQL。涵盖从下载、安装到配置的完整步骤,帮助读者快速搭建Java Web开发环境。 ... [详细]
  • 优化Flask应用的并发处理:解决Mysql连接过多问题
    本文探讨了在Flask应用中通过优化后端架构来应对高并发请求,特别是针对Mysql 'too many connections' 错误的解决方案。我们将介绍如何利用Redis缓存、Gunicorn多进程和Celery异步任务队列来提升系统的性能和稳定性。 ... [详细]
  • 使用JS、HTML5和C3创建自定义弹出窗口
    本文介绍如何结合JavaScript、HTML5和C3.js来实现一个功能丰富的自定义弹出窗口。通过具体的代码示例,详细讲解了实现过程中的关键步骤和技术要点。 ... [详细]
  • 本文介绍了一个基于 Java SpringMVC 和 SSM 框架的综合系统,涵盖了操作日志记录、文件管理、头像编辑、权限控制、以及多种技术集成如 Shiro、Redis 等,旨在提供一个高效且功能丰富的开发平台。 ... [详细]
  • 本文探讨了如何在Hive(基于Hadoop)环境中编写类似SQL的语句,以去除字段中的空格。特别是在处理邮政编码等数据时,去除特定位置的空格是常见的需求。 ... [详细]
  • 本文深入探讨了MySQL中常见的面试问题,包括事务隔离级别、存储引擎选择、索引结构及优化等关键知识点。通过详细解析,帮助读者在面对BAT等大厂面试时更加从容。 ... [详细]
  • 本文详细介绍了Linux系统中的进程管理函数,涵盖了获取进程ID、用户ID、创建子进程、信号处理等关键操作。通过这些函数,开发者可以更好地控制和管理进程行为。 ... [详细]
  • 本文详细介绍了如何在Linux系统中创建和管理DB2数据库,包括用户切换、数据库创建、错误处理、连接与断开、表空间和缓冲池的创建,以及用户权限管理和数据导入导出等操作。 ... [详细]
author-avatar
mobiledu2502891023
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有