ITPub博客

首页 > 数据库 > Oracle > duplicate复制数据库

duplicate复制数据库

原创 Oracle 作者:lllllcheng 时间:2016-01-18 21:53:39 0 删除 编辑
主hostname:enmoedu1   db_name=PROD1
备hostname:enmoedu2   db_name=ENMO2
操作过程:将主机enmoedu1上的数据库PROD1复制到主机enmoedu2上;


开启归档

[oracle@enmoedu1 admin]$ sqlplus / as sysdba
SYS@PROD1>shutdown immediate;
SYS@PROD1>startup mount;
ORACLE instance started.

Total System Global Area 1653518336 bytes
Fixed Size    2253784 bytes
Variable Size 1006636072 bytes
Database Buffers  637534208 bytes
Redo Buffers    7094272 bytes
Database mounted.
SYS@PROD1>alter database archivelog;


Database altered.

创建备库参数文件
[oracle@enmoedu2 dbs]$ ls
init.ora
[oracle@enmoedu2 dbs]$ cat init.ora|grep -v ^#>initENMO2.ora
db_name='ENMO2'
memory_target=1G
processes = 150
audit_file_dest='/u01/app/oracle/admin/ENMO2/adump'
audit_trail ='db'
db_block_size=8192
db_domain=''
db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
db_recovery_file_dest_size=2G
diagnostic_dest='/u01/app/oracle'
dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)'
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
control_files = '/u01/app/oracle/oradata/ENMO2/control01.ctl','/u01/app/oracle/oradata/ENMO2/control02.ctl'
compatible ='11.2.0.4.0'
db_file_name_convert=('PROD1','ENMO2')
log_file_name_convert=('PROD1','ENMO2')  

创建目录
[oracle@enmoedu2 ~]$ mkdir -p /u01/app/oracle/admin/ENMO2/adump
[oracle@enmoedu2 ~]$ mkdir -p /u01/app/oracle/flash_recovery_area
[oracle@enmoedu2 ~]$ mkdir -p /u01/app/oracle/oradata/ENMO2/

创建密码文件
[oracle@enmoedu1 dbs]$ scp orapwPROD1 oracle@enmoedu2:/u01/app/oracle/product/11.2.0/db_1/dbs/orapwENMO2
oracle@enmoedu2's password: 
orapwPROD1                                                                                                                           100% 1536     1.5KB/s   00:00    

[oracle@enmoedu2 dbs]$ ls
hc_ENMO2.dat  initENMO2.ora  init.ora  lkENMO2  orapwENMO2

配置监听
[oracle@enmoedu1 admin]$ cat listener.ora 

LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = enmoedu1)(PORT = 1521))
  )


ADR_BASE_LISTENER = /u01/app/oracle


SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = PROD1)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = PROD1)
    )
  )

[oracle@enmoedu2 admin]$ cat listener.ora 
LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = enmoedu2)(PORT = 1521))
  )


ADR_BASE_LISTENER = /u01/app/oracle


SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = ENMO2)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = ENMO2)
    )
  )

配置网络服务名
[oracle@enmoedu1 admin]$ cat tnsnames.ora 
[oracle@enmoedu2 admin]$ cat tnsnames.ora 
PROD1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = enmoedu1)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PROD1)
    )
  )


ENMO2 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = enmoedu2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = ENMO2)
    )
  )

开始拷贝

[oracle@enmoedu2 admin]$ sqlplus / as sysdba


Connected to an idle instance.


SYS@ENMO2>startup nomount;
ORACLE instance started.


Total System Global Area 1068937216 bytes
Fixed Size    2260088 bytes
Variable Size  671089544 bytes
Database Buffers  390070272 bytes
Redo Buffers    5517312 bytes

[oracle@enmoedu1 admin]$ sqlplus / as sysdba
SQL@PROD1> alter database open;


Database altered.

SYS@PROD1>alter system switch logfile;


System altered.




SQL@PROD1> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@enmoedu1 admin]$ rman target / auxiliary sys/oracle@ENMO2



Recovery Manager: Release 11.2.0.4.0 - Production on Mon Jan 18 18:25:45 2016


Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.


connected to target database: PROD1 (DBID=2122819531)
connected to auxiliary database: ENMO2 (not mounted)

RMAN> duplicate target database to ENMO2 from active database nofilenamecheck;


Starting Duplicate Db at 18-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=20 device type=DISK


contents of Memory Script:
{
   sql clone "create spfile from memory";
}
executing Memory Script


sql statement: create spfile from memory


contents of Memory Script:
{
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script


Oracle instance shut down


connected to auxiliary database (not started)
Oracle instance started


Total System Global Area    1068937216 bytes


Fixed Size                     2260088 bytes
Variable Size                671089544 bytes
Database Buffers             390070272 bytes
Redo Buffers                   5517312 bytes


contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''PROD1'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name = 
 ''ENMO2'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   backup as copy current controlfile auxiliary format  '/u01/app/oracle/oradata/ENMO2/control01.ctl';
   restore clone controlfile to  '/u01/app/oracle/oradata/ENMO2/control02.ctl' from 
 '/u01/app/oracle/oradata/ENMO2/control01.ctl';
   alter clone database mount;
}
executing Memory Script


sql statement: alter system set  db_name =  ''PROD1'' comment= ''Modified by RMAN duplicate'' scope=spfile


sql statement: alter system set  db_unique_name =  ''ENMO2'' comment= ''Modified by RMAN duplicate'' scope=spfile


Oracle instance shut down


Oracle instance started


Total System Global Area    1068937216 bytes


Fixed Size                     2260088 bytes
Variable Size                671089544 bytes
Database Buffers             390070272 bytes
Redo Buffers                   5517312 bytes


Starting backup at 18-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=34 device type=DISK
channel ORA_DISK_1: starting datafile copy
copying current control file
output file name=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_PROD1.f tag=TAG20160118T182923 RECID=2 STAMP=901477764
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 18-JAN-16


Starting restore at 18-JAN-16
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=18 device type=DISK


channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 18-JAN-16


database mounted


contents of Memory Script:
{
   set newname for datafile  1 to 
 "/u01/app/oracle/oradata/ENMO2/system01.dbf";
   set newname for datafile  2 to 
 "/u01/app/oracle/oradata/ENMO2/sysaux01.dbf";
   set newname for datafile  3 to 
 "/u01/app/oracle/oradata/ENMO2/undotbs01.dbf";
   set newname for datafile  4 to 
 "/u01/app/oracle/oradata/ENMO2/users01.dbf";
   backup as copy reuse
   datafile  1 auxiliary format 
 "/u01/app/oracle/oradata/ENMO2/system01.dbf"   datafile 
 2 auxiliary format 
 "/u01/app/oracle/oradata/ENMO2/sysaux01.dbf"   datafile 
 3 auxiliary format 
 "/u01/app/oracle/oradata/ENMO2/undotbs01.dbf"   datafile 
 4 auxiliary format 
 "/u01/app/oracle/oradata/ENMO2/users01.dbf"   ;
   sql 'alter system archive log current';
}
executing Memory Script


executing command: SET NEWNAME


executing command: SET NEWNAME


executing command: SET NEWNAME


executing command: SET NEWNAME


Starting backup at 18-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/PROD1/system01.dbf
output file name=/u01/app/oracle/oradata/ENMO2/system01.dbf tag=TAG20160118T182932
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf
output file name=/u01/app/oracle/oradata/ENMO2/sysaux01.dbf tag=TAG20160118T182932
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf
output file name=/u01/app/oracle/oradata/ENMO2/undotbs01.dbf tag=TAG20160118T182932
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/users01.dbf
output file name=/u01/app/oracle/oradata/ENMO2/users01.dbf tag=TAG20160118T182932
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 18-JAN-16


sql statement: alter system archive log current


contents of Memory Script:
{
   backup as copy reuse
   archivelog like  "/u01/app/oracle/product/11.2.0/db_1/dbs/arch1_3_901476364.dbf" auxiliary format 
 "/u01/app/oracle/flash_recovery_area/ENMO2/archivelog/2016_01_18/o1_mf_1_3_%u_.arc"   ;
   catalog clone recovery area;
   switch clone datafile all;
}
executing Memory Script


Starting backup at 18-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=3 RECID=2 STAMP=901477817
output file name=/u01/app/oracle/flash_recovery_area/ENMO2/archivelog/2016_01_18/o1_mf_1_3_07qrmtdp_.arc RECID=0 STAMP=0
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
Finished backup at 18-JAN-16


searching for all files in the recovery area


List of Files Unknown to the Database
=====================================
File Name: /u01/app/oracle/flash_recovery_area/ENMO2/archivelog/2016_01_18/o1_mf_1_3_07qrmtdp_.arc
cataloging files...
cataloging done


List of Cataloged Files
=======================
File Name: /u01/app/oracle/flash_recovery_area/ENMO2/archivelog/2016_01_18/o1_mf_1_3_07qrmtdp_.arc


datafile 1 switched to datafile copy
input datafile copy RECID=2 STAMP=901477816 file name=/u01/app/oracle/oradata/ENMO2/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=3 STAMP=901477816 file name=/u01/app/oracle/oradata/ENMO2/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=901477816 file name=/u01/app/oracle/oradata/ENMO2/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=901477816 file name=/u01/app/oracle/oradata/ENMO2/users01.dbf


contents of Memory Script:
{
   set until scn  930600;
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script


executing command: SET until clause


Starting recover at 18-JAN-16
using channel ORA_AUX_DISK_1


starting media recovery


archived log for thread 1 with sequence 3 is already on disk as file /u01/app/oracle/flash_recovery_area/ENMO2/archivelog/2016_01_18/o1_mf_1_3_07qrmtdp_.arc
archived log file name=/u01/app/oracle/flash_recovery_area/ENMO2/archivelog/2016_01_18/o1_mf_1_3_07qrmtdp_.arc thread=1 sequence=3
media recovery complete, elapsed time: 00:00:00
Finished recover at 18-JAN-16
Oracle instance started


Total System Global Area    1068937216 bytes


Fixed Size                     2260088 bytes
Variable Size                671089544 bytes
Database Buffers             390070272 bytes
Redo Buffers                   5517312 bytes


contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''ENMO2'' 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


sql statement: alter system set  db_name =  ''ENMO2'' 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    1068937216 bytes


Fixed Size                     2260088 bytes
Variable Size                671089544 bytes
Database Buffers             390070272 bytes
Redo Buffers                   5517312 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ENMO2" RESETLOGS ARCHIVELOG 
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP   1 ( '/u01/app/oracle/oradata/ENMO2/redo01.log' ) SIZE 50 M  REUSE,
  GROUP   2 ( '/u01/app/oracle/oradata/ENMO2/redo02.log' ) SIZE 50 M  REUSE,
  GROUP   3 ( '/u01/app/oracle/oradata/ENMO2/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/ENMO2/system01.dbf'
 CHARACTER SET WE8MSWIN1252




contents of Memory Script:
{
   set newname for tempfile  1 to 
 "/u01/app/oracle/oradata/ENMO2/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/oradata/ENMO2/sysaux01.dbf", 
 "/u01/app/oracle/oradata/ENMO2/undotbs01.dbf", 
 "/u01/app/oracle/oradata/ENMO2/users01.dbf";
   switch clone datafile all;
}
executing Memory Script


executing command: SET NEWNAME


renamed tempfile 1 to /u01/app/oracle/oradata/ENMO2/temp01.dbf in control file


cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/ENMO2/sysaux01.dbf RECID=1 STAMP=901477826
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/ENMO2/undotbs01.dbf RECID=2 STAMP=901477826
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/ENMO2/users01.dbf RECID=3 STAMP=901477826


datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=901477826 file name=/u01/app/oracle/oradata/ENMO2/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=901477826 file name=/u01/app/oracle/oradata/ENMO2/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=901477826 file name=/u01/app/oracle/oradata/ENMO2/users01.dbf


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


database opened
Finished Duplicate Db at 18-JAN-16




--END--

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30606744/viewspace-1978680/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2015-12-02

  • 博文量
    41
  • 访问量
    119791