欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

RMAN 异机duplicate复制数据库

程序员文章站 2024-01-21 14:05:46
...

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)";