热门标签 | 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)";

推荐阅读
  • 1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]
  • 本文详细分析了Hive在启动过程中遇到的权限拒绝错误,并提供了多种解决方案,包括调整文件权限、用户组设置以及环境变量配置等。 ... [详细]
  • MySQL缓存机制深度解析
    本文详细探讨了MySQL的缓存机制,包括主从复制、读写分离以及缓存同步策略等内容。通过理解这些概念和技术,读者可以更好地优化数据库性能。 ... [详细]
  • MySQL 数据库迁移指南:从本地到远程及磁盘间迁移
    本文详细介绍了如何在不同场景下进行 MySQL 数据库的迁移,包括从一个硬盘迁移到另一个硬盘、从一台计算机迁移到另一台计算机,以及解决迁移过程中可能遇到的问题。 ... [详细]
  • Windows服务与数据库交互问题解析
    本文探讨了在Windows 10(64位)环境下开发的Windows服务,旨在定期向本地MS SQL Server (v.11)插入记录。尽管服务已成功安装并运行,但记录并未正确插入。我们将详细分析可能的原因及解决方案。 ... [详细]
  • 本文详细介绍如何使用arm-eabi-gdb调试Android平台上的C/C++程序。通过具体步骤和实用技巧,帮助开发者更高效地进行调试工作。 ... [详细]
  • 本文详细介绍如何使用Python进行配置文件的读写操作,涵盖常见的配置文件格式(如INI、JSON、TOML和YAML),并提供具体的代码示例。 ... [详细]
  • PHP 5.2.5 安装与配置指南
    本文详细介绍了 PHP 5.2.5 的安装和配置步骤,帮助开发者解决常见的环境配置问题,特别是上传图片时遇到的错误。通过本教程,您可以顺利搭建并优化 PHP 运行环境。 ... [详细]
  • 深入理解 SQL 视图、存储过程与事务
    本文详细介绍了SQL中的视图、存储过程和事务的概念及应用。视图为用户提供了一种灵活的数据查询方式,存储过程则封装了复杂的SQL逻辑,而事务确保了数据库操作的完整性和一致性。 ... [详细]
  • 构建基于BERT的中文NL2SQL模型:一个简明的基准
    本文探讨了将自然语言转换为SQL语句(NL2SQL)的任务,这是人工智能领域中一项非常实用的研究方向。文章介绍了笔者在公司举办的首届中文NL2SQL挑战赛中的实践,该比赛提供了金融和通用领域的表格数据,并标注了对应的自然语言与SQL语句对,旨在训练准确的NL2SQL模型。 ... [详细]
  • UNP 第9章:主机名与地址转换
    本章探讨了用于在主机名和数值地址之间进行转换的函数,如gethostbyname和gethostbyaddr。此外,还介绍了getservbyname和getservbyport函数,用于在服务器名和端口号之间进行转换。 ... [详细]
  • 掌握远程执行Linux脚本和命令的技巧
    本文将详细介绍如何利用Python的Paramiko库实现远程执行Linux脚本和命令,帮助读者快速掌握这一实用技能。通过具体的示例和详尽的解释,让初学者也能轻松上手。 ... [详细]
  • 使用Vultr云服务器和Namesilo域名搭建个人网站
    本文详细介绍了如何通过Vultr云服务器和Namesilo域名搭建一个功能齐全的个人网站,包括购买、配置服务器以及绑定域名的具体步骤。文章还提供了详细的命令行操作指南,帮助读者顺利完成建站过程。 ... [详细]
  • 在现代网络环境中,两台计算机之间的文件传输需求日益增长。传统的FTP和SSH方式虽然有效,但其配置复杂、步骤繁琐,难以满足快速且安全的传输需求。本文将介绍一种基于Go语言开发的新一代文件传输工具——Croc,它不仅简化了操作流程,还提供了强大的加密和跨平台支持。 ... [详细]
  • 使用Python在SAE上开发新浪微博应用的初步探索
    最近重新审视了新浪云平台(SAE)提供的服务,发现其已支持Python开发。本文将详细介绍如何利用Django框架构建一个简单的新浪微博应用,并分享开发过程中的关键步骤。 ... [详细]
author-avatar
手机用户2502854107
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有