0%

duplicate db from rman backup/duplicate复制数据库

源库需要开启归档,不需要备份,不会影响源库(当然,一点点clone性能除外)

和 from active database 不同,target可以处于关闭状态,channel使用的是 auxiliary实例的,不能配置 parallelism ,好像速度更快额,因为from active database 是先backup copy 然后在switch ,其实原理和直接拷贝rman备份恢复一样,只不过rman备份恢复更加灵活,不一定要在一个文件夹,可以指定arch文件恢复,但步骤相对较多,而这个duplicate基于rman备份复制比较简单,也是基于rman备份,先把source库恢复起来,然后在重置db_name为SRM2,注意额,rman恢复后db_name是一样的SRM,这个duplicate是复制库,db_name是SRM2不一样的,^_^

环境信息

1
2
3
4
5
6
7
8
9
source db:

sid=SRM
db_name = SRM
db_file_path = /u01/app/oracle/oradata/SRM/
sys_pwd = oracle
oracle_version = Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
服务器资源 = 4核4G内存40G磁盘
OS = CentOS Linux release 7.6.1810 (Core)

###操作步骤
####1. 启动auxiliary instance

1). 新建静态listener – 注意 sid 区分大小写,一定要和ORACLE_SID一样

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
lsnrctl stop
vim listener.ora
---------------------------------------------------------------------------------------
LISTENER=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
(ADDRESS=(PROTOCOL=ipc)(KEY=extproc))))
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=SRM)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME=SRM))
(SID_DESC=
(GLOBAL_DBNAME=SRM2)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME=SRM2))
)
---------------------------------------------------------------------------------------
lsnrctl start
lsnrctl status

2)增加tns

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
---------------------------------------------------------------------------------------
SRM =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = SRM)
)
)
SRM2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = SRM2)
)
)
---------------------------------------------------------------------------------------

3)复制密码文件,或者新建

1
[oracle@yg-test dbs]$ cp orapwSRM orapwSRM2

*4)创建pfile并修改启动nomount, 注意: 如果自己创建pfile要加上:.compatible=’11.2.0.4.0’**

1
SQL> create pfile='/home/oracle/dup_pfile.ora' from spfile;

5)修改dup_pfile.ora中的:

1
2
3
*.db_name='SRM2'
*.audit_file_dest='/u01/app/oracle/admin/SRM2/adump'
*.control_files='/u01/app/oracle/oradata/SRM2/control01.ctl','/u01/app/oracle/oradata/SRM2/control02.ctl'

6)添加参数

1
2
db_file_name_convert='/u01/app/oracle/oradata/SRM','/u01/app/oracle/oradata/SRM2'
log_file_name_convert='/u01/app/oracle/oradata/SRM','/u01/app/oracle/oradata/SRM2'

7)新建dup库的新文件夹:

1
2
mkdir -p /u01/app/oracle/admin/SRM2/adump /u01/app/oracle/oradata/SRM2

####2. 准备备份
**1)在源库操作备份

1
2
3
4
5
6
7
8
9
10
11
#注意: 源库SRM的数据、归档、控制文件都要在rman一个位置下面,rman下面只能有一个db备份,auxiliary要能访问这个rman目录
#新建备份文件夹
[oracle@yg-test ~]$ mkdir rman
#备份db
RMAN> backup as compressed backupset database format '/home/oracle/rman/db_%U';
#备份归档
RMAN> backup archivelog all format '/home/oracle/rman/arch_%U';
#备份spfile
RMAN> backup spfile format '/home/oracle/rman/spfile_%U';
#备份控制文件
RMAN> backup current controlfile format '/home/oracle/rman/control_%U';

####3. 开始基于源库duplicate

1)修改环境变量ORACLE_SID: SRM –> SRM2

1
2
3
4
5
6
7
8
[oracle@yg-test ~]$ echo $ORACLE_SID
SRM
[oracle@yg-test ~]$ sqlplus / as sysdba
SQL> shu immediate;
SQL> exit
[oracle@yg-test ~]$ export ORACLE_SID=SRM2
[oracle@yg-test ~]$ echo $ORACLE_SID
SRM2

2)以nomount模式启动:

1
2
3
[oracle@yg-test ~]$ sqlplus / as sysdba
SQL> startup nomount pfile=/home/oracle/dup_pfile.ora;
SQL> exit

3)检查实例进程

1
2
[oracle@yg-test ~]$ ps -ef |grep smon    # 只有auxiliary实例在运行
oracle 46994 1 0 07:21 ? 00:00:00 ora_smon_SMR2

4)检查远程sys登录 – 注意都必须是 : EXCLUSIVE

1
2
3
4
5
6
7
8
[oracle@yg-test ~]$ sqlplus / as sysdba
SQL> set line 140
SQL> show parameter remote_login_passwordfile

NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
remote_login_passwordfile string EXCLUSIVE

5)测试 aux db 的sys远程登录,都要正常登录,不能为idle状态

1
2
sqlplus sys/oracle@srm2 as sysdba

6)rman登录auxiliary库 # 注意区别,这里直接使用备份,没有登录target库

1
2
[oracle@yg-test ~]$ rman auxiliary sys/oracle@srm2
connected to auxiliary database: SRM (not mounted) -- 注意以后nomount启动,rman连上为 not mounted

7)开始复制 – 注意: 如果ctronl_file已经拷贝,由于其他原因再次拷贝,请先备份删除控制文件

1
RMAN> duplicate database to SRM2 backup location '/home/oracle/rman' nofilenamecheck;

8)重建spfile

1
2
3
4
5
6
7
8
SQL> shu immediate;
SQL> create spfile from pfile='/home/oracle/dup_pfile.ora';
SQL> startup
SQL> show parameter spfile;
NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
spfile string /u01/app/oracle/product/11.2.0
/dbhome_1/dbs/spfileSRM2.ora

9)校验 –查到之前数据,成功

1
2
3
4
5
SQL> select * from reco;
ID
----------
1