关于RMAN 复制的理论知识,参考我的Blog:
RMAN 复制目标数据库的理论知识
http://blog.csdn.net/tianlesoftware/archive/2010/07/19/5746812.aspx
RMAN 异机复制和同机复制操作步骤是一样的,不同的是我们需要把备份的文件copy到辅助库上去,而且位置要和目标库上一直,因为备份集的位置是写在控制文件里的。
RMAN 同机复制数据库
http://blog.csdn.net/tianlesoftware/archive/2010/07/19/5747442.aspx
实验平台: REDHAT linux 4.7 + oracle 10g
目标库信息:
ORACLE_BASE: /u01/app/oracle
ORACLE_HOME: /u01/app/oracle/product/10.2.0/db_1
ORACLE_SID:orcl
IP: 192.168.1.20
辅助库信息:
ORACLE_BASE: /u01/app/oracle
ORACLE_HOME: /u01/app/oracle/product/10.2.0/db_1
ORACLE_SID:orcl
IP: 192.168.1.21
我们以实例名相同的为例,实例名不同也一样,在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 目录
[oracle@localhost oracle]$ mkdir oradata
[oracle@localhost oracle]$ ls
oradata oraInventory product
[oracle@localhost oracle]$ cd oradata/
[oracle@localhost oracle]$ mkdir orcl
1.2 其他目录
[oracle@localhost oracle]$ pwd
/u01/app/oracle
[oracle@localhost oracle]$ mkdir admin
[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
orcl
[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
[oracle@localhost orcl]$ ls
adump bdump cdump dpdump pfile udump
二. 创建pfile,复制到辅助数据库,并修改相关参数
2.1 在源库上创建pfile 文件
SQL> conn sys/admin@orcl as sysdba;
Connected.
SQL> create pfile from spfile;
File created.
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]$ ls
hc_DAVE.dat initdw.ora lkDAVE orapworcl spfileorcl.ora
hc_orcl.dat init.ora lkORCL snapcf_orcl.f
initDAVE.ora initorcl.ora orapwDAVE spfileDAVE.ora
[oracle@db1 dbs]$ scp initorcl.ora 192.168.1.21:/$ORACLE_HOME/dbs
The authenticity of host '192.168.1.21 (192.168.1.21)' can't be established.
RSA key fingerprint is 1a:20:7a:05:bd:e0:ac:04:21:02:b1:72:01:69:40:d6.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.21' (RSA) to the list of known hosts.
oracle@192.168.1.21's password:
initorcl.ora 100% 1108 1.1KB/s 00:00
2.3 在辅助库上确认文件是否传送过来
[oracle@localhost orcl]$ cd $ORACLE_HOME/dbs
[oracle@localhost dbs]$ ls
initdw.ora init.ora initorcl.ora
2.4 在辅助库上修改pfile参数
[oracle@localhost dbs]$ more initorcl.ora
orcl.__db_cache_size=167772160
orcl.__java_pool_size=4194304
orcl.__large_pool_size=4194304
orcl.__shared_pool_size=62914560
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.background_dump_dest='/u01/app/oracle/admin/orcl/bdump'
*.compatible='10.2.0.1.0'
*.control_file_record_keep_time=14
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/or
adata/orcl/control02.ctl','/u01/app/oracle/oradata/orcl/control03.ctl'
*.core_dump_dest='/u01/app/oracle/admin/orcl/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='orcl'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.job_queue_processes=10
*.log_archive_dest_1='location=/u01/archivelog'
*.open_cursors=300
*.pga_aggregate_target=81788928
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=246415360
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/orcl/udump'
说明,在这里我没有做修改,因为我异机复制实例名相同,存储位置也相同。 如果说你复制的不同的话,就需要修改相关的实例名。 如果存储位置不同的话,还需要添加以下参数,对数据文件位置进行转换。
db_file_name_convert = ('/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/DAVE')
三.创建辅助实例ORCL 的口令文件
[oracle@localhost dbs]$ cd $ORACLE_HOME/bin
[oracle@localhost bin]$ orapwd file=$ORACLE_HOME/dbs/orapworcl password=admin
[oracle@localhost bin]$ cd $ORACLE_HOME/dbs
[oracle@localhost dbs]$ ls
initdw.ora init.ora initorcl.ora orapworcl
windows下oracle默认的位置是$ORACLE_HOME/database目录,文件名格式是pwdSID.ora。
linux下oracle默认的位置是$ORACLE_HOME/dbs目录,文件名格式是orapwSID。
创建完后,数据库需要重启动,新的口令文件才能生效。
关于口令文件创建,详细内容参考blog:
Oracle OS认证 口令文件 密码丢失处理
http://blog.csdn.net/tianlesoftware/archive/2009/10/20/4698293.aspx
四.RMAN 备份源库(orcl)
[oracle@db1 backup]$ rman target sys/admin@orcl
Recovery Manager: Release 10.2.0.1.0 - Production on Sun Jul 18 18:26:16 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1248423599)
RMAN>RUN {
allocate channel c1 type disk;
allocate channel c2 type disk;
BACKUP FORMAT '/u02/backup/orcl_%U_%T' skip inaccessible filesperset 5 DATABASE TAG orcl_hot_db_bk;
sql 'alter system archive log current';
BACKUP FORMAT '/u02/backup/arch_%U_%T' skip inaccessible filesperset 5 ARCHIVELOG ALL DELETE INPUT;
backup current controlfile tag='bak_ctlfile' format='/u02/backup/ctl_file_%U_%T';
backup spfile tag='spfile' format='/u02/backup/ORCL_spfile_%U_%T';
release channel c2;
release channel c1;
}
备份脚本,具体参考:
Linux 平台下 RMAN 全备 和 增量备份 shell 脚本
http://blog.csdn.net/tianlesoftware/archive/2010/07/16/5740630.aspx
五.添加,配置监听
5.1 在辅助库的Listener.ora 文件中,添加如下内容
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(SID_NAME = orcl)
)
)
5.2 修改辅助库的tnsnames.ora 文件,添加如下内容
TARGETORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.20)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
5.3 修改源库的tnsnames.ora 文件,添加如下内容:
AUXORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.21)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
建议使用net manager 工具从界面来修改,这样不容易出错
Oracle 数据库监听配置
http://blog.csdn.net/tianlesoftware/archive/2009/11/25/4861572.aspx
Oracle Listener 动态注册 与 静态注册
http://blog.csdn.net/tianlesoftware/archive/2010/04/30/5543166.aspx
六. 将源库的备份拷贝到辅助数据库的相同位置
这里有两种方法,一种直接在辅助库上建相同的目录结构,在用SCP 命令把这些备份文件copy过去,但是这样会占用大量的网络资源。 还有一种就是建好目录结构后用NFS直接Mount上去。 在这里我们用后面一种方法试一下。
6.1 在辅助库上建相同的备份目录结构
因为我们在源库上备份是备份到/u02/backup目录中的,所以我们在辅助库上也建这个目录
[root@localhost /]# mkdir -p /u02/backup
[root@localhost /]# chown oracle /u02
[root@localhost /]# chmod 777 /u02
6.2 将源库的备份挂载到辅助库上
6.2.1 在源库上将/u02/backup 目录添加到共享
[root@db1 ~]# more /etc/exports
/u02/backup 192.168.1.21(rw,async,anonuid=65534,anongid=65534)
[root@db1 ~]# service nfs start
6.2.2 在辅助库上挂载源库的目录,注意,mount命令必须以root用户执行
[root@localhost /]# mount -t nfs -o rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,vers=3,timeo=600,actimeo=0
10.85.10.1:/u02/backup /u02/backup
-- 注意: 在挂载NFS的时候,一定要加上-t -o 参数,不然在RMAN 复制的时候会报错:
--ORA-27054: NFS file system where the file is created or resides is not mounted with correct options
[root@localhost /]# cd /u02/backup/
[root@localhost backup]# ls
arch_3klj4676_1_1_20100718 orcl_3hlj45vf_1_1_20100718
arch_3llj4676_1_1_20100718 orcl_3ilj465c_1_1_20100718
ctl_file_3mlj467h_1_1_20100718 orcl_3jlj4661_1_1_20100718
orcl_3glj45vf_1_1_20100718 ORCL_spfile_3nlj467k_1_1_20100718