Oracle 12C RMAN Duplicating the PDB to remote CDB

使用RMAN对CDB中的PDB进行复制的操作如下
1.检查源RAC CDB(jy)的参数文件,数据文件,联机日志文件,控制文件,归档日志文件的存储目录

SQL> show parameter spfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- --------------------------------------------
spfile                               string      +DATA/JY/PARAMETERFILE/spfile.303.961976713

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
+DATA/JY/DATAFILE/system.317.962209603
+DATA/JY/DATAFILE/sysaux.298.962209605
+DATA/JY/DATAFILE/undotbs1.277.962209605
+DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/system.256.962209675
+DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/sysaux.270.962209675
+DATA/JY/DATAFILE/users.301.962209605
+DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/undotbs1.296.962209675
+DATA/JY/DATAFILE/undotbs2.312.962209605
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/system.271.962209649
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/sysaux.316.962209649
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undotbs1.264.962209649
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undo_2.268.962209649
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/users.278.962209649
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/test.275.962210609
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/system.260.962469409
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/sysaux.259.962469409
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undotbs1.265.962469409
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undo_2.266.962469409
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/users.267.962469409
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/test.269.962469409


SQL> show parameter control_files

NAME                                 TYPE        VALUE
------------------------------------ ----------- -------------------------------------------
control_files                        string      +DATA/JY/CONTROLFILE/current.272.961976315


SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
+DATA/JY/ONLINELOG/group_2.302.961976321
+DATA/JY/ONLINELOG/group_1.261.961976319
+DATA/JY/ONLINELOG/group_3.263.961976697
+DATA/JY/ONLINELOG/group_4.262.961976705


SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            +TEST/arch
Oldest online log sequence     127
Next log sequence to archive   128
Current log sequence           128

2.在目标主机上创建存储目标数据库(dupjy)相关数据库文件的目录,目标主机上的/u01/app/oracle/oradata/dupjy目录用来存储数据库的数据文件,控制文件,联机重做日志文件),/u01/app/oracle/arch/dupjy目录用来存储数据库的归档重做日志文件。

3.将源数据库的密码文件复制到目标主机的相应目录中并修改为目标数据库(dupjy)对应的文件名

[grid@jytest1 ~]$ srvctl config database -db jy
Database unique name: jy
Database name: jy
Oracle home: /u01/app/oracle/product/12.2.0/db
Oracle user: oracle
Spfile: +DATA/JY/PARAMETERFILE/spfile.303.961976713
Password file: +DATA/JY/PASSWORD/pwdjy.274.961976109
Domain:
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools:
Disk Groups: DATA
Mount point paths:
Services:
Type: RAC
Start concurrency:
Stop concurrency:
OSDBA group: dba
OSOPER group: oper
Database instances: jy1,jy2
Configured nodes: jytest1,jytest2
CSS critical: no
CPU count: 0
Memory target: 0
Maximum memory: 0
Default network number for database services:
Database is administrator managed

[grid@jytest1 ~]$ asmcmd cp  +DATA/JY/PASSWORD/pwdjy.274.961976109 /home/grid/pwddupjy
copying +DATA/JY/PASSWORD/pwdjy.274.961976109 -> /home/grid/pwddupjy


[oracle@shard1 dbs]# scp grid@10.138.130.171:/home/grid/pwddupjy /u01/app/oracle/product/12.2.0/db/dbs/
The authenticity of host '10.138.130.171 (10.138.130.171)' can't be established.
ECDSA key fingerprint is 7a:62:58:8b:77:98:52:94:d6:d5:0c:c4:6c:87:a6:7f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.138.130.171' (ECDSA) to the list of known hosts.
grid@10.138.130.171's password:
pwddupjy

[oracle@shard1 dbs]$ mv pwddupjy orapwdupjy

4.使用源数据库的spfile文件来创建目标数据库要使用的spfile文件
在源数据库中执行下面的命令来创建pfile参数文件

SQL> create pfile from spfile;

File created.

[root@shard1 ~]# scp oracle@10.138.130.171:/u01/app/oracle/product/12.2.0/db/dbs/initjy1.ora /u01/app/oracle/product/12.2.0/db/dbs/
grid@10.138.130.171's password:
initjy1.ora                                                                                                                                                                                   

             100% 1731     1.7KB/s   00:00
[root@shard1 ~]#


[oracle@shard1 dbs]$ cat initdupjy.ora
*.audit_file_dest='/u01/app/oracle/admin/dupjy/adump'
*.cluster_database=false
*.compatible='12.2.0'
*.control_files='/u01/app/oracle/oradata/dupjy/control01.ctl'
*.db_block_size=8192
*.db_name='dupjy'
*.diagnostic_dest='/u01/app/oracle'
*.enable_pluggable_database=true
*.open_cursors=300
*.pga_aggregate_target=1g
*.processes=2000
*.remote_login_passwordfile='exclusive'
*.sga_max_size=2147483648
*.sga_target=2147483648
db_file_name_convert= 

('+DATA/JY/DATAFILE/','/u01/app/oracle/oradata/dupjy/','+DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/','/u01/app/oracle/oradata/dupjy/','+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATA 

FILE/','/u01/app/oracle/oradata/dupjy/','+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/','/u01/app/oracle/oradata/dupjy/')
log_file_name_convert=('+DATA/JY/ONLINELOG/','/u01/app/oracle/oradata/dupjy/')



[oracle@shard1 dbs]$ export ORACLE_SID=dupjy
[oracle@shard1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Thu Jan 18 19:06:00 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup nomount pfile='/u01/app/oracle/product/12.2.0/db/dbs/initdupjy.ora'
ORACLE instance started.

Total System Global Area 2147483648 bytes
Fixed Size                  8794848 bytes
Variable Size             570428704 bytes
Database Buffers         1560281088 bytes
Redo Buffers                7979008 bytes

SQL> create spfile from pfile='/u01/app/oracle/product/12.2.0/db/dbs/initdupjy.ora';

File created.

5.使用spfile参数文件来启动目标数据库实例(辅助实例dupjy)

SQL> shutdown immediate
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.

Total System Global Area 2147483648 bytes
Fixed Size                  8794848 bytes
Variable Size             570428704 bytes
Database Buffers         1560281088 bytes
Redo Buffers                7979008 bytes


SQL> show parameter spfile

NAME                                 TYPE                   VALUE
------------------------------------ ---------------------- -----------------------------------------------------
spfile                               string                 /u01/app/oracle/product/12.2.0/db/dbs/spfiledupjy.ora

6.给目标数据库配置静态监听

[oracle@shard1 admin]$ vi listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/12.2.0/db/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = shard1)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = dupjy)
      (ORACLE_HOME = /u01/app/oracle/product/12.2.0/db)
      (GLOBAL_DBNAME=dupjy)
    )
  )


[oracle@shard1 admin]$ lsnrctl start

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 18-JAN-2018 20:30:34

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

Starting /u01/app/oracle/product/12.2.0/db/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 12.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/12.2.0/db/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/shard1/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=shard1)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=shard1)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                18-JAN-2018 20:30:34
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.2.0/db/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/shard1/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=shard1)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "dupjy" has 1 instance(s).
  Instance "dupjy", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully


7.在目标主机上配置tns,用来通过网络服务名来连接源数据库与目标数据库

[oracle@shard1 admin]$ vi tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/12.2.0/db/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

JY =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.138.130.171)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = jy)
    )
  )

DUPJY =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.138.130.180)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = dupjy)
    )
  )

8.在目标主机上测试是否可以通过使用网络服务名来连接源数据库与目标数据库

[oracle@shard1 admin]$ sqlplus /nolog

SQL*Plus: Release 12.2.0.1.0 Production on Thu Jan 18 21:02:53 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

SQL> conn / as sysdba
Connected.
SQL> startup nomount
ORACLE instance started.

Total System Global Area 2147483648 bytes
Fixed Size                  8794848 bytes
Variable Size             570428704 bytes
Database Buffers         1560281088 bytes
Redo Buffers                7979008 bytes
SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
[oracle@shard1 admin]$ sqlplus /nolog

SQL*Plus: Release 12.2.0.1.0 Production on Thu Jan 18 21:04:51 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

SQL> conn sys/abcd@dupjy as sysdba
Connected.
SQL> conn sys/abcd@jy as sysdba
Connected.

9.在源主机上配置目标数据库的tns名

[oracle@jytest1 admin]$ vi tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/12.2.0/db/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.


JY =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = jytest-scan)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = jy)
    )
  )



DUPJY =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.138.130.180)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = dupjy)
      (UR = A)
    )
  )

10.在源主机上测试能否可以使用网络服务名来连接源数据库与目标数据库

[oracle@jytest1 admin]$ sqlplus /nolog
SQL*Plus: Release 12.2.0.1.0 Production on Fri Jan 19 03:16:59 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

SQL> conn sys/abcd@jy as sysdba
Connected.
SQL> conn sys/abcd@dupjy as sysdba
Connected.

11.执行PDB数据库复制

[oracle@jytest1 ~]$ rman target sys/abcd@jy catalog rco/abcd@jypdb_173 auxiliary sys/abcd@dupjy

Recovery Manager: Release 12.2.0.1.0 - Production on Tue Jan 23 17:47:09 2018

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

connected to target database: JY (DBID=979425723)
connected to recovery catalog database
connected to auxiliary database: DUPJY (not mounted)

RMAN> duplicate database to dupjy pluggable database jypdb from active database nofilenamecheck using compressed backupset;

Starting Duplicate Db at 23-JAN-18
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=2269 device type=DISK
current log archived

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''JY'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name = 
 ''DUPJY'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone from service  'jy' using compressed backupset
   primary controlfile;
   alter clone database mount;
}
executing Memory Script

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

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

Oracle instance shut down

Oracle instance started

Total System Global Area    2147483648 bytes

Fixed Size                     8794848 bytes
Variable Size               1056967968 bytes
Database Buffers            1073741824 bytes
Redo Buffers                   7979008 bytes

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

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:06
output file name=/u01/app/oracle/oradata/dupjy/control01.ctl
Finished restore at 23-JAN-18

database mounted
Skipping pluggable database TESTPDB
Automatically adding tablespace SYSTEM
Automatically adding tablespace SYSAUX
Automatically adding tablespace PDB$SEED:SYSTEM
Automatically adding tablespace PDB$SEED:SYSAUX
Automatically adding tablespace TESTPDB:SYSTEM
Automatically adding tablespace TESTPDB:UNDOTBS1
Automatically adding tablespace UNDOTBS1
Automatically adding tablespace TESTPDB:UNDO_2
Automatically adding tablespace UNDOTBS2
Skipping tablespace USERS
RMAN-05529: warning: DB_FILE_NAME_CONVERT resulted in invalid ASM names; names changed to disk group only.

contents of Memory Script:
{
   sql clone 'alter database flashback off';
   set newname for datafile  1 to 
 "/u01/app/oracle/oradata/dupjy/system.317.962209603";
   set newname for datafile  3 to 
 "/u01/app/oracle/oradata/dupjy/sysaux.298.962209605";
   set newname for datafile  4 to 
 "/u01/app/oracle/oradata/dupjy/undotbs1.277.962209605";
   set newname for datafile  5 to 
 "/u01/app/oracle/oradata/dupjy/system.256.962209675";
   set newname for datafile  6 to 
 "/u01/app/oracle/oradata/dupjy/sysaux.270.962209675";
   set newname for datafile  8 to 
 "/u01/app/oracle/oradata/dupjy/undotbs1.296.962209675";
   set newname for datafile  9 to 
 "/u01/app/oracle/oradata/dupjy/undotbs2.312.962209605";
   set newname for datafile  10 to 
 "/u01/app/oracle/oradata/dupjy/system.271.962209649";
   set newname for datafile  11 to 
 "/u01/app/oracle/oradata/dupjy/sysaux.316.962209649";
   set newname for datafile  12 to 
 "/u01/app/oracle/oradata/dupjy/undotbs1.264.962209649";
   set newname for datafile  13 to 
 "/u01/app/oracle/oradata/dupjy/undo_2.268.962209649";
   set newname for datafile  14 to 
 "/u01/app/oracle/oradata/dupjy/users.278.962209649";
   set newname for datafile  15 to 
 "/u01/app/oracle/oradata/dupjy/test.275.962210609";
   restore
   from  nonsparse   from service 
 'jy'   using compressed backupset
   clone database
   skip forever tablespace  "USERS",
 "TESTPDB":"USERS",
 "TESTPDB":"UNDO_2",
 "TESTPDB":"UNDOTBS1",
 "TESTPDB":"TEST",
 "TESTPDB":"SYSTEM",
 "TESTPDB":"SYSAUX"   ;
   sql 'alter system archive log current';
}
executing Memory Script

sql statement: alter database flashback off

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 23-JAN-18
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/dupjy/system.317.962209603
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:45
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/dupjy/sysaux.298.962209605
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:36
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/dupjy/undotbs1.277.962209605
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/dupjy/system.256.962209675
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/dupjy/sysaux.270.962209675
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:36
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00008 to /u01/app/oracle/oradata/dupjy/undotbs1.296.962209675
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00009 to /u01/app/oracle/oradata/dupjy/undotbs2.312.962209605
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:26
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00010 to /u01/app/oracle/oradata/dupjy/system.271.962209649
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00011 to /u01/app/oracle/oradata/dupjy/sysaux.316.962209649
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:46
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00012 to /u01/app/oracle/oradata/dupjy/undotbs1.264.962209649
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:08
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00013 to /u01/app/oracle/oradata/dupjy/undo_2.268.962209649
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:08
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00014 to /u01/app/oracle/oradata/dupjy/users.278.962209649
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:05
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00015 to /u01/app/oracle/oradata/dupjy/test.275.962210609
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
Finished restore at 23-JAN-18

sql statement: alter system archive log current
current log archived

contents of Memory Script:
{
   restore clone force from service  'jy' using compressed backupset
   archivelog from scn  15660582;
   switch clone datafile all;
}
executing Memory Script

Starting restore at 23-JAN-18
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=163
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=164
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=165
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=2 sequence=144
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=2 sequence=145
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
Finished restore at 23-JAN-18

datafile 1 switched to datafile copy
input datafile copy RECID=17 STAMP=966167434 file name=/u01/app/oracle/oradata/dupjy/system.317.962209603
datafile 3 switched to datafile copy
input datafile copy RECID=18 STAMP=966167434 file name=/u01/app/oracle/oradata/dupjy/sysaux.298.962209605
datafile 4 switched to datafile copy
input datafile copy RECID=19 STAMP=966167434 file name=/u01/app/oracle/oradata/dupjy/undotbs1.277.962209605
datafile 5 switched to datafile copy
input datafile copy RECID=20 STAMP=966167434 file name=/u01/app/oracle/oradata/dupjy/system.256.962209675
datafile 6 switched to datafile copy
input datafile copy RECID=21 STAMP=966167434 file name=/u01/app/oracle/oradata/dupjy/sysaux.270.962209675
datafile 8 switched to datafile copy
input datafile copy RECID=22 STAMP=966167434 file name=/u01/app/oracle/oradata/dupjy/undotbs1.296.962209675
datafile 9 switched to datafile copy
input datafile copy RECID=23 STAMP=966167434 file name=/u01/app/oracle/oradata/dupjy/undotbs2.312.962209605
datafile 10 switched to datafile copy
input datafile copy RECID=24 STAMP=966167434 file name=/u01/app/oracle/oradata/dupjy/system.271.962209649
datafile 11 switched to datafile copy
input datafile copy RECID=25 STAMP=966167434 file name=/u01/app/oracle/oradata/dupjy/sysaux.316.962209649
datafile 12 switched to datafile copy
input datafile copy RECID=26 STAMP=966167435 file name=/u01/app/oracle/oradata/dupjy/undotbs1.264.962209649
datafile 13 switched to datafile copy
input datafile copy RECID=27 STAMP=966167435 file name=/u01/app/oracle/oradata/dupjy/undo_2.268.962209649
datafile 14 switched to datafile copy
input datafile copy RECID=28 STAMP=966167435 file name=/u01/app/oracle/oradata/dupjy/users.278.962209649
datafile 15 switched to datafile copy
input datafile copy RECID=29 STAMP=966167435 file name=/u01/app/oracle/oradata/dupjy/test.275.962210609

contents of Memory Script:
{
   set until scn  15661286;
   recover
   clone database
   skip forever tablespace  "USERS",
 "TESTPDB":"USERS",
 "TESTPDB":"UNDO_2",
 "TESTPDB":"UNDOTBS1",
 "TESTPDB":"TEST",
 "TESTPDB":"SYSTEM",
 "TESTPDB":"SYSAUX"    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 23-JAN-18
using channel ORA_AUX_DISK_1

Executing: alter database datafile 7 offline drop
Executing: alter database datafile 20 offline drop
Executing: alter database datafile 19 offline drop
Executing: alter database datafile 18 offline drop
Executing: alter database datafile 21 offline drop
Executing: alter database datafile 16 offline drop
Executing: alter database datafile 17 offline drop
starting media recovery

archived log for thread 1 with sequence 164 is already on disk as file /u01/app/oracle/oradata/arch_dupjy/1_164_961976319.dbf
archived log for thread 1 with sequence 165 is already on disk as file /u01/app/oracle/oradata/arch_dupjy/1_165_961976319.dbf
archived log for thread 2 with sequence 144 is already on disk as file /u01/app/oracle/oradata/arch_dupjy/2_144_961976319.dbf
archived log for thread 2 with sequence 145 is already on disk as file /u01/app/oracle/oradata/arch_dupjy/2_145_961976319.dbf
archived log file name=/u01/app/oracle/oradata/arch_dupjy/1_164_961976319.dbf thread=1 sequence=164
archived log file name=/u01/app/oracle/oradata/arch_dupjy/2_144_961976319.dbf thread=2 sequence=144
archived log file name=/u01/app/oracle/oradata/arch_dupjy/1_165_961976319.dbf thread=1 sequence=165
archived log file name=/u01/app/oracle/oradata/arch_dupjy/2_145_961976319.dbf thread=2 sequence=145
media recovery complete, elapsed time: 00:00:02
Finished recover at 23-JAN-18
Oracle instance started

Total System Global Area    2147483648 bytes

Fixed Size                     8794848 bytes
Variable Size               1056967968 bytes
Database Buffers            1073741824 bytes
Redo Buffers                   7979008 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''DUPJY'' comment=
 ''Reset to original value by RMAN'' scope=spfile";
   sql clone "alter system reset  db_unique_name scope=spfile";
}
executing Memory Script

sql statement: alter system set  db_name =  ''DUPJY'' comment= ''Reset to original value by RMAN'' scope=spfile

sql statement: alter system reset  db_unique_name scope=spfile
Oracle instance started

Total System Global Area    2147483648 bytes

Fixed Size                     8794848 bytes
Variable Size               1056967968 bytes
Database Buffers            1073741824 bytes
Redo Buffers                   7979008 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUPJY" RESETLOGS ARCHIVELOG 
  MAXLOGFILES    192
  MAXLOGMEMBERS      3
  MAXDATAFILES     1024
  MAXINSTANCES    32
  MAXLOGHISTORY      292
 LOGFILE
  GROUP   1 ( '/u01/app/oracle/oradata/dupjy/group_1.261.961976319' ) SIZE 200 M  REUSE,
  GROUP   2 ( '/u01/app/oracle/oradata/dupjy/group_2.302.961976321' ) SIZE 200 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/dupjy/system.317.962209603',
  '/u01/app/oracle/oradata/dupjy/system.256.962209675',
  '/u01/app/oracle/oradata/dupjy/system.271.962209649'
 CHARACTER SET ZHS16GBK

sql statement: ALTER DATABASE ADD LOGFILE 
  
  INSTANCE 'i2' 
  GROUP   3 ( '/u01/app/oracle/oradata/dupjy/group_3.263.961976697' ) SIZE 200 M  REUSE,
  GROUP   4 ( '/u01/app/oracle/oradata/dupjy/group_4.262.961976705' ) SIZE 200 M  REUSE

contents of Memory Script:
{
   set newname for tempfile  1 to 
 "+DATA";
   set newname for tempfile  2 to 
 "+DATA";
   set newname for tempfile  3 to 
 "+DATA";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/oradata/dupjy/sysaux.298.962209605", 
 "/u01/app/oracle/oradata/dupjy/undotbs1.277.962209605", 
 "/u01/app/oracle/oradata/dupjy/sysaux.270.962209675", 
 "/u01/app/oracle/oradata/dupjy/undotbs1.296.962209675", 
 "/u01/app/oracle/oradata/dupjy/undotbs2.312.962209605", 
 "/u01/app/oracle/oradata/dupjy/sysaux.316.962209649", 
 "/u01/app/oracle/oradata/dupjy/undotbs1.264.962209649", 
 "/u01/app/oracle/oradata/dupjy/undo_2.268.962209649", 
 "/u01/app/oracle/oradata/dupjy/users.278.962209649", 
 "/u01/app/oracle/oradata/dupjy/test.275.962210609";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to +DATA in control file
renamed tempfile 2 to +DATA in control file
renamed tempfile 3 to +DATA in control file

cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/sysaux.298.962209605 RECID=1 STAMP=966167470
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/undotbs1.277.962209605 RECID=2 STAMP=966167471
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/sysaux.270.962209675 RECID=3 STAMP=966167471
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/undotbs1.296.962209675 RECID=4 STAMP=966167471
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/undotbs2.312.962209605 RECID=5 STAMP=966167471
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/sysaux.316.962209649 RECID=6 STAMP=966167471
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/undotbs1.264.962209649 RECID=7 STAMP=966167471
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/undo_2.268.962209649 RECID=8 STAMP=966167471
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/users.278.962209649 RECID=9 STAMP=966167471
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/test.275.962210609 RECID=10 STAMP=966167471

datafile 3 switched to datafile copy
input datafile copy RECID=1 STAMP=966167470 file name=/u01/app/oracle/oradata/dupjy/sysaux.298.962209605
datafile 4 switched to datafile copy
input datafile copy RECID=2 STAMP=966167471 file name=/u01/app/oracle/oradata/dupjy/undotbs1.277.962209605
datafile 6 switched to datafile copy
input datafile copy RECID=3 STAMP=966167471 file name=/u01/app/oracle/oradata/dupjy/sysaux.270.962209675
datafile 8 switched to datafile copy
input datafile copy RECID=4 STAMP=966167471 file name=/u01/app/oracle/oradata/dupjy/undotbs1.296.962209675
datafile 9 switched to datafile copy
input datafile copy RECID=5 STAMP=966167471 file name=/u01/app/oracle/oradata/dupjy/undotbs2.312.962209605
datafile 11 switched to datafile copy
input datafile copy RECID=6 STAMP=966167471 file name=/u01/app/oracle/oradata/dupjy/sysaux.316.962209649
datafile 12 switched to datafile copy
input datafile copy RECID=7 STAMP=966167471 file name=/u01/app/oracle/oradata/dupjy/undotbs1.264.962209649
datafile 13 switched to datafile copy
input datafile copy RECID=8 STAMP=966167471 file name=/u01/app/oracle/oradata/dupjy/undo_2.268.962209649
datafile 14 switched to datafile copy
input datafile copy RECID=9 STAMP=966167471 file name=/u01/app/oracle/oradata/dupjy/users.278.962209649
datafile 15 switched to datafile copy
input datafile copy RECID=10 STAMP=966167471 file name=/u01/app/oracle/oradata/dupjy/test.275.962210609

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

database opened
Executing: drop pluggable database "TESTPDB" including datafiles

contents of Memory Script:
{
   sql clone "alter pluggable database all open";
}
executing Memory Script

sql statement: alter pluggable database all open
Dropping offline and skipped tablespaces
Executing: alter database default tablespace system
Executing: drop tablespace "USERS" including contents cascade constraints
Finished Duplicate Db at 23-JAN-18

12.检查源数据库中的PDB(jypdb)是否被成功复制到目标数据库dupjy中

SQL> select name,open_mode from v$pdbs;

NAME                                                                                                                             OPEN_MODE
-------------------------------------------------------------------------------------------------------------------------------- ----------
PDB$SEED                                                                                                                         READ ONLY
JYPDB                                                                                                                            READ WRITE

到此复制RAC CDB数据库中PDB(jypdb)到单实例CDB数据库就操作完成

Oracle 12C RMAN Duplicating the Whole RAC CDB to local RAC CDB

下面的例子是将源RAC CDB数据库通过rman的duplicate命令复制一个RAC CDB数据库,具体的复制操作如下
1.检查源RAC CDB(jy)的参数文件,数据文件,联机日志文件,控制文件,归档日志文件的存储目录

SQL> show parameter spfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- --------------------------------------------
spfile                               string      +DATA/JY/PARAMETERFILE/spfile.303.961976713

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
+DATA/JY/DATAFILE/system.317.962209603
+DATA/JY/DATAFILE/sysaux.298.962209605
+DATA/JY/DATAFILE/undotbs1.277.962209605
+DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/system.256.962209675
+DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/sysaux.270.962209675
+DATA/JY/DATAFILE/users.301.962209605
+DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/undotbs1.296.962209675
+DATA/JY/DATAFILE/undotbs2.312.962209605
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/system.271.962209649
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/sysaux.316.962209649
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undotbs1.264.962209649
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undo_2.268.962209649
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/users.278.962209649
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/test.275.962210609
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/system.260.962469409
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/sysaux.259.962469409
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undotbs1.265.962469409
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undo_2.266.962469409
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/users.267.962469409
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/test.269.962469409


SQL> show parameter control_files

NAME                                 TYPE        VALUE
------------------------------------ ----------- -------------------------------------------
control_files                        string      +DATA/JY/CONTROLFILE/current.272.961976315


SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
+DATA/JY/ONLINELOG/group_2.302.961976321
+DATA/JY/ONLINELOG/group_1.261.961976319
+DATA/JY/ONLINELOG/group_3.263.961976697
+DATA/JY/ONLINELOG/group_4.262.961976705


SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            +TEST/arch
Oldest online log sequence     127
Next log sequence to archive   128
Current log sequence           128

2.在目标主机上创建存储目标数据库(dup)相关数据库文件的目录,目标主机上的+fra/dup目录用来存储数据库的数据文件,控制文件,联机重做日志文件),+fra/dup目录用来存储数据库的归档重做日志文件

ASMCMD [+fra] > mkdir dup

3.将源数据库的密码文件复制到目标主机的相应目录中并修改为目标数据库(dup)对应的文件名

[grid@jytest1 ~]$ srvctl config database -db jy
Database unique name: jy
Database name: jy
Oracle home: /u01/app/oracle/product/12.2.0/db
Oracle user: oracle
Spfile: +DATA/JY/PARAMETERFILE/spfile.303.961976713
Password file: +DATA/JY/PASSWORD/pwdjy.274.961976109
Domain: 
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: 
Disk Groups: DATA
Mount point paths: 
Services: 
Type: RAC
Start concurrency: 
Stop concurrency: 
OSDBA group: dba
OSOPER group: oper
Database instances: jy1,jy2
Configured nodes: jytest1,jytest2
CSS critical: no
CPU count: 0
Memory target: 0
Maximum memory: 0
Default network number for database services: 
Database is administrator managed

[grid@jytest1 admin]$ asmcmd cp  +DATA/JY/PASSWORD/pwdjy.274.961976109 /home/grid/orapwdup1
copying +DATA/JY/PASSWORD/pwdjy.274.961976109 -> /home/grid/orapwdup1

[root@jytest1 ~]# cp /home/grid/orapwdup /u01/app/oracle/product/12.2.0/db/dbs/orapwdup1
[root@jytest1 ~]# chown -R oracle:oinstall /u01/app/oracle/product/12.2.0/db/dbs/orapwdup1
[root@jytest1 ~]# chmod -R 777 /u01/app/oracle/product/12.2.0/db/dbs/orapwdup1

将密码文件orapwdup复制到2号实例主机上

[oracle@jytest2 dbs]$ scp oracle@10.138.130.171:/u01/app/oracle/product/12.2.0/db/dbs/orapwdup1 /u01/app/oracle/product/12.2.0/db/dbs/
orapwdup1                                                                   100% 3584     3.5KB/s   00:00    

[oracle@jytest2 dbs]$ mv orapwdup1 orapwdup2

4.使用源数据库的spfile文件来创建目标数据库要使用的spfile文件
在源数据库中执行下面的命令来创建pfile参数文件

SQL> create pfile from spfile;

File created.

[oracle@jytest1 dbs]$ vi initdup1.ora
*.audit_file_dest='/u01/app/oracle/admin/dup/adump'
*.cluster_database=false
*.compatible='12.2.0'
*.control_files='+fra/dup/CONTROLFILE/control01.ctl'
*.db_block_size=8192
*.db_name='dup'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=jyXDB)'
*.enable_pluggable_database=true
dup2.instance_number=2
dup1.instance_number=1
*.local_listener='-oraagent-dummy-'
*.log_archive_dest_1='location=+test/arch/dup'
*.nls_language='AMERICAN'
*.nls_territory='AMERICA'
*.open_cursors=300
*.pga_aggregate_target=1g
*.processes=2000
*.remote_login_passwordfile='exclusive'
*.sga_max_size=2147483648
*.sga_target=2147483648
dup2.thread=2
dup1.thread=1
*.undo_retention=8640
dup1.undo_tablespace='UNDOTBS1'
dup2.undo_tablespace='UNDOTBS2'
*.db_file_name_convert=('+DATA/JY/','+fra/dup')
*.log_file_name_convert=('+DATA/JY/','+fra/dup')


[oracle@jytest1 dbs]$ export ORACLE_SID=dup1
[oracle@jytest1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Fri Jan 19 19:46:07 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup nomount pfile='/u01/app/oracle/product/12.2.0/db/dbs/initdup1.ora'
ORACLE instance started.

Total System Global Area 2147483648 bytes
Fixed Size                  8794848 bytes
Variable Size            1459621152 bytes
Database Buffers          671088640 bytes
Redo Buffers                7979008 bytes



SQL> create spfile='+fra/dup/spfiledup.ora' from pfile='/u01/app/oracle/product/12.2.0/db/dbs/initdup1.ora';

File created.

[oracle@jytest1 dbs]$ vi initdup1.ora
spfile=+fra/dup/spfiledup.ora

[oracle@jytest2 dbs]$ vi initdup1.ora
spfile=+fra/dup/spfiledup.ora

5.使用spfile参数文件来启动目标数据库实例(辅助实例dup)

SQL> shutdown immediate
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.

Total System Global Area 2147483648 bytes
Fixed Size                  8794848 bytes
Variable Size             570428704 bytes
Database Buffers         1560281088 bytes
Redo Buffers                7979008 bytes

SQL> show parameter spfile

NAME                                 TYPE                   VALUE
------------------------------------ ---------------------- ----------------------------------------------------
spfile                               string                 /u01/app/oracle/product/12.2.0/db/dbs/spfiledup1.ora

6.给目标数据库配置静态监听与tns名

[grid@jytest1 admin]$ vi listener.ora

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = dup1)
      (ORACLE_HOME =/u01/app/oracle/product/12.2.0/db)
      (GLOBAL_DBNAME=dup)
    )
  )

[grid@jytest2 admin]$ vi listener.ora

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = dup2)
      (ORACLE_HOME =/u01/app/oracle/product/12.2.0/db)
      (GLOBAL_DBNAME=dup)
    )
  )


[grid@jytest1 admin]$ srvctl stop listener -listener LISTENER

[grid@jytest1 admin]$ srvctl start listener -listener LISTENER
[grid@jytest1 admin]$ lsnrctl status

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 19-JAN-2018 22:36:22

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                19-JAN-2018 22:32:51
Uptime                    0 days 0 hr. 3 min. 31 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/product/12.2.0/crs/network/admin/listener.ora
Listener Log File         /u01/app/grid/diag/tnslsnr/jytest1/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.138.130.171)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.138.130.175)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=jytest1.jydba.net)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/product/12.2.0/db/admin/jy/xdb_wallet))(Presentation=HTTP)

(Session=RAW))
Services Summary...
Service "+ASM" has 1 instance(s).
  Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "+ASM_CRS" has 1 instance(s).
  Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "+ASM_DATA" has 1 instance(s).
  Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "+ASM_FRA" has 1 instance(s).
  Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "+ASM_TEST" has 1 instance(s).
  Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "5f9ac6865e87549fe053ab828a0ade94" has 1 instance(s).
  Instance "jy1", status READY, has 1 handler(s) for this service...
Service "600d6f56deb669cce053ab828a0aab7e" has 1 instance(s).
  Instance "jy1", status READY, has 1 handler(s) for this service...
Service "dup" has 1 instance(s).
  Instance "dup1", status UNKNOWN, has 1 handler(s) for this service...
Service "jy" has 1 instance(s).
  Instance "jy1", status READY, has 1 handler(s) for this service...
Service "jyXDB" has 1 instance(s).
  Instance "jy1", status READY, has 1 handler(s) for this service...
Service "jypdb" has 1 instance(s).
  Instance "jy1", status READY, has 1 handler(s) for this service...
Service "testpdb" has 1 instance(s).
  Instance "jy1", status READY, has 1 handler(s) for this service...
The command completed successfully


[grid@jytest2 admin]$ lsnrctl status

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 19-JAN-2018 22:41:01

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                19-JAN-2018 22:37:29
Uptime                    0 days 0 hr. 3 min. 31 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/product/12.2.0/crs/network/admin/listener.ora
Listener Log File         /u01/app/grid/diag/tnslsnr/jytest2/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.138.130.172)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.138.130.176)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=jytest2.jydba.net)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/product/12.2.0/db/admin/jy/xdb_wallet))(Presentation=HTTP)

(Session=RAW))
Services Summary...
Service "+ASM" has 1 instance(s).
  Instance "+ASM2", status READY, has 1 handler(s) for this service...
Service "+ASM_CRS" has 1 instance(s).
  Instance "+ASM2", status READY, has 1 handler(s) for this service...
Service "+ASM_DATA" has 1 instance(s).
  Instance "+ASM2", status READY, has 1 handler(s) for this service...
Service "+ASM_FRA" has 1 instance(s).
  Instance "+ASM2", status READY, has 1 handler(s) for this service...
Service "+ASM_TEST" has 1 instance(s).
  Instance "+ASM2", status READY, has 1 handler(s) for this service...
Service "5f9ac6865e87549fe053ab828a0ade94" has 1 instance(s).
  Instance "jy2", status READY, has 1 handler(s) for this service...
Service "600d6f56deb669cce053ab828a0aab7e" has 1 instance(s).
  Instance "jy2", status READY, has 1 handler(s) for this service...
Service "dup" has 1 instance(s).
  Instance "dup2", status UNKNOWN, has 1 handler(s) for this service...
Service "jy" has 1 instance(s).
  Instance "jy2", status READY, has 1 handler(s) for this service...
Service "jyXDB" has 1 instance(s).
  Instance "jy2", status READY, has 1 handler(s) for this service...
Service "jypdb" has 1 instance(s).
  Instance "jy2", status READY, has 1 handler(s) for this service...
Service "testpdb" has 1 instance(s).
  Instance "jy2", status READY, has 1 handler(s) for this service...
The command completed successfully

7.在目标主机上配置tns,用来通过网络服务名来连接源数据库与目标数据库

[oracle@jytest1 admin]$ vi tnsnames.ora 
DUP =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.138.130.171)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = dup)
      (UR = A)
    )
  )

[oracle@jytest2 admin]$ vi tnsnames.ora 
DUP =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.138.130.172)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = dup)
      (UR = A)
    )
  )

8.在目标主机上测试是否可以通过使用网络服务名来连接源数据库与目标数据库

[oracle@jytest1 admin]$ sqlplus /nolog

SQL*Plus: Release 12.2.0.1.0 Production on Fri Jan 19 22:58:34 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

SQL> conn sys/abcd@dup as sysdba
Connected.
SQL> conn sys/abcd@jy as sysdba
Connected.

9.执行数据库复制

[oracle@jytest1 admin]$ rman target sys/abcd@jy catalog rco/abcd@jypdb_173 auxiliary sys/abcd@dup

Recovery Manager: Release 12.2.0.1.0 - Production on Fri Jan 19 23:16:15 2018

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

connected to target database: JY (DBID=979425723)
connected to recovery catalog database
connected to auxiliary database: DUP (not mounted)

RMAN> duplicate target database to dup from active database nofilenamecheck using compressed backupset;

Starting Duplicate Db at 19-JAN-18
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=2275 device type=DISK
current log archived

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''JY'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name = 
 ''DUP'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone from service  'jy' using compressed backupset
   primary controlfile;
   alter clone database mount;
}
executing Memory Script

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

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

Oracle instance shut down

Oracle instance started

Total System Global Area    2147483648 bytes

Fixed Size                     8794848 bytes
Variable Size               1459621152 bytes
Database Buffers             671088640 bytes
Redo Buffers                   7979008 bytes

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

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:06
output file name=+FRA/dup/CONTROLFILE/control01.ctl
Finished restore at 19-JAN-18

database mounted
RMAN-05529: warning: DB_FILE_NAME_CONVERT resulted in invalid ASM names; names changed to disk group only.

contents of Memory Script:
{
   sql clone 'alter database flashback off';
   set newname for datafile  1 to 
 "+FRA";
   set newname for datafile  3 to 
 "+FRA";
   set newname for datafile  4 to 
 "+FRA";
   set newname for datafile  5 to 
 "+FRA";
   set newname for datafile  6 to 
 "+FRA";
   set newname for datafile  7 to 
 "+FRA";
   set newname for datafile  8 to 
 "+FRA";
   set newname for datafile  9 to 
 "+FRA";
   set newname for datafile  10 to 
 "+FRA";
   set newname for datafile  11 to 
 "+FRA";
   set newname for datafile  12 to 
 "+FRA";
   set newname for datafile  13 to 
 "+FRA";
   set newname for datafile  14 to 
 "+FRA";
   set newname for datafile  15 to 
 "+FRA";
   set newname for datafile  16 to 
 "+FRA";
   set newname for datafile  17 to 
 "+FRA";
   set newname for datafile  18 to 
 "+FRA";
   set newname for datafile  19 to 
 "+FRA";
   set newname for datafile  20 to 
 "+FRA";
   set newname for datafile  21 to 
 "+FRA";
   restore
   from  nonsparse   from service 
 'jy'   using compressed backupset
   clone database
   ;
   sql 'alter system archive log current';
}
executing Memory Script

sql statement: alter database flashback off

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 19-JAN-18
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:55
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00003 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:46
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00004 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:16
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00005 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00006 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:36
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00007 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00008 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00009 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00010 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00011 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:36
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00012 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00013 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00014 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:36
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00015 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00016 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:16
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00017 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:35
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00018 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00019 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00020 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00021 to +FRA
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
Finished restore at 19-JAN-18

sql statement: alter system archive log current
current log archived

contents of Memory Script:
{
   restore clone force from service  'jy' using compressed backupset
   archivelog from scn  13147698;
   switch clone datafile all;
}
executing Memory Script

Starting restore at 19-JAN-18
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=137
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:08
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=138
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=139
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=2 sequence=114
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=2 sequence=115
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
Finished restore at 19-JAN-18

datafile 1 switched to datafile copy
input datafile copy RECID=24 STAMP=965863480 file name=+FRA/DUP/DATAFILE/system.376.965863053
datafile 3 switched to datafile copy
input datafile copy RECID=25 STAMP=965863482 file name=+FRA/DUP/DATAFILE/sysaux.379.965863109
datafile 4 switched to datafile copy
input datafile copy RECID=26 STAMP=965863482 file name=+FRA/DUP/DATAFILE/undotbs1.380.965863215
datafile 5 switched to datafile copy
input datafile copy RECID=27 STAMP=965863482 file name=+FRA/DUP/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/system.381.965863229
datafile 6 switched to datafile copy
input datafile copy RECID=28 STAMP=965863482 file name=+FRA/DUP/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/sysaux.382.965863245
datafile 7 switched to datafile copy
input datafile copy RECID=29 STAMP=965863483 file name=+FRA/DUP/DATAFILE/users.364.965863281
datafile 8 switched to datafile copy
input datafile copy RECID=30 STAMP=965863483 file name=+FRA/DUP/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/undotbs1.365.965863281
datafile 9 switched to datafile copy
input datafile copy RECID=31 STAMP=965863483 file name=+FRA/DUP/DATAFILE/undotbs2.366.965863289
datafile 10 switched to datafile copy
input datafile copy RECID=32 STAMP=965863483 file name=+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/system.367.965863293
datafile 11 switched to datafile copy
input datafile copy RECID=33 STAMP=965863483 file name=+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/sysaux.326.965863309
datafile 12 switched to datafile copy
input datafile copy RECID=34 STAMP=965863484 file name=+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undotbs1.285.965863345
datafile 13 switched to datafile copy
input datafile copy RECID=35 STAMP=965863484 file name=+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undo_2.325.965863349
datafile 14 switched to datafile copy
input datafile copy RECID=36 STAMP=965863484 file name=+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/users.369.965863351
datafile 15 switched to datafile copy
input datafile copy RECID=37 STAMP=965863484 file name=+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/test.370.965863387
datafile 16 switched to datafile copy
input datafile copy RECID=38 STAMP=965863484 file name=+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/system.371.965863391
datafile 17 switched to datafile copy
input datafile copy RECID=39 STAMP=965863485 file name=+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/sysaux.372.965863407
datafile 18 switched to datafile copy
input datafile copy RECID=40 STAMP=965863485 file name=+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undotbs1.373.965863443
datafile 19 switched to datafile copy
input datafile copy RECID=41 STAMP=965863485 file name=+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undo_2.375.965863445
datafile 20 switched to datafile copy
input datafile copy RECID=42 STAMP=965863485 file name=+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/users.377.965863449
datafile 21 switched to datafile copy
input datafile copy RECID=43 STAMP=965863485 file name=+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/test.378.965863451

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

executing command: SET until clause

Starting recover at 19-JAN-18
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 137 is already on disk as file +TEST/arch/dup/1_137_961976319.dbf
archived log for thread 1 with sequence 138 is already on disk as file +TEST/arch/dup/1_138_961976319.dbf
archived log for thread 1 with sequence 139 is already on disk as file +TEST/arch/dup/1_139_961976319.dbf
archived log for thread 2 with sequence 114 is already on disk as file +TEST/arch/dup/2_114_961976319.dbf
archived log for thread 2 with sequence 115 is already on disk as file +TEST/arch/dup/2_115_961976319.dbf
archived log file name=+TEST/arch/dup/2_114_961976319.dbf thread=2 sequence=114
archived log file name=+TEST/arch/dup/1_137_961976319.dbf thread=1 sequence=137
archived log file name=+TEST/arch/dup/1_138_961976319.dbf thread=1 sequence=138
archived log file name=+TEST/arch/dup/2_115_961976319.dbf thread=2 sequence=115
archived log file name=+TEST/arch/dup/1_139_961976319.dbf thread=1 sequence=139
media recovery complete, elapsed time: 00:00:04
Finished recover at 19-JAN-18
Oracle instance started

Total System Global Area    2147483648 bytes

Fixed Size                     8794848 bytes
Variable Size               1459621152 bytes
Database Buffers             671088640 bytes
Redo Buffers                   7979008 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''DUP'' comment=
 ''Reset to original value by RMAN'' scope=spfile";
   sql clone "alter system reset  db_unique_name scope=spfile";
}
executing Memory Script

sql statement: alter system set  db_name =  ''DUP'' comment= ''Reset to original value by RMAN'' scope=spfile

sql statement: alter system reset  db_unique_name scope=spfile
Oracle instance started

Total System Global Area    2147483648 bytes

Fixed Size                     8794848 bytes
Variable Size               1459621152 bytes
Database Buffers             671088640 bytes
Redo Buffers                   7979008 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUP" RESETLOGS ARCHIVELOG 
  MAXLOGFILES    192
  MAXLOGMEMBERS      3
  MAXDATAFILES     1024
  MAXINSTANCES    32
  MAXLOGHISTORY      292
 LOGFILE
  GROUP   1 ( '+FRA' ) SIZE 200 M  REUSE,
  GROUP   2 ( '+FRA' ) SIZE 200 M  REUSE
 DATAFILE
  '+FRA/DUP/DATAFILE/system.376.965863053',
  '+FRA/DUP/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/system.381.965863229',
  '+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/system.367.965863293',
  '+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/system.371.965863391'
 CHARACTER SET ZHS16GBK

sql statement: ALTER DATABASE ADD LOGFILE 
  
  INSTANCE 'i2' 
  GROUP   3 ( '+FRA' ) SIZE 200 M  REUSE,
  GROUP   4 ( '+FRA' ) SIZE 200 M  REUSE

contents of Memory Script:
{
   set newname for tempfile  1 to 
 "+FRA";
   set newname for tempfile  2 to 
 "+FRA";
   set newname for tempfile  3 to 
 "+FRA";
   set newname for tempfile  4 to 
 "+FRA";
   switch clone tempfile all;
   catalog clone datafilecopy  "+FRA/DUP/DATAFILE/sysaux.379.965863109", 
 "+FRA/DUP/DATAFILE/undotbs1.380.965863215", 
 "+FRA/DUP/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/sysaux.382.965863245", 
 "+FRA/DUP/DATAFILE/users.364.965863281", 
 "+FRA/DUP/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/undotbs1.365.965863281", 
 "+FRA/DUP/DATAFILE/undotbs2.366.965863289", 
 "+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/sysaux.326.965863309", 
 "+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undotbs1.285.965863345", 
 "+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undo_2.325.965863349", 
 "+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/users.369.965863351", 
 "+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/test.370.965863387", 
 "+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/sysaux.372.965863407", 
 "+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undotbs1.373.965863443", 
 "+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undo_2.375.965863445", 
 "+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/users.377.965863449", 
 "+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/test.378.965863451";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to +FRA in control file
renamed tempfile 2 to +FRA in control file
renamed tempfile 3 to +FRA in control file
renamed tempfile 4 to +FRA in control file

cataloged datafile copy
datafile copy file name=+FRA/DUP/DATAFILE/sysaux.379.965863109 RECID=1 STAMP=965863550
cataloged datafile copy
datafile copy file name=+FRA/DUP/DATAFILE/undotbs1.380.965863215 RECID=2 STAMP=965863550
cataloged datafile copy
datafile copy file name=+FRA/DUP/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/sysaux.382.965863245 RECID=3 STAMP=965863550
cataloged datafile copy
datafile copy file name=+FRA/DUP/DATAFILE/users.364.965863281 RECID=4 STAMP=965863550
cataloged datafile copy
datafile copy file name=+FRA/DUP/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/undotbs1.365.965863281 RECID=5 STAMP=965863550
cataloged datafile copy
datafile copy file name=+FRA/DUP/DATAFILE/undotbs2.366.965863289 RECID=6 STAMP=965863550
cataloged datafile copy
datafile copy file name=+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/sysaux.326.965863309 RECID=7 STAMP=965863550
cataloged datafile copy
datafile copy file name=+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undotbs1.285.965863345 RECID=8 STAMP=965863550
cataloged datafile copy
datafile copy file name=+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undo_2.325.965863349 RECID=9 STAMP=965863550
cataloged datafile copy
datafile copy file name=+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/users.369.965863351 RECID=10 STAMP=965863551
cataloged datafile copy
datafile copy file name=+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/test.370.965863387 RECID=11 STAMP=965863551
cataloged datafile copy
datafile copy file name=+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/sysaux.372.965863407 RECID=12 STAMP=965863551
cataloged datafile copy
datafile copy file name=+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undotbs1.373.965863443 RECID=13 STAMP=965863551
cataloged datafile copy
datafile copy file name=+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undo_2.375.965863445 RECID=14 STAMP=965863551
cataloged datafile copy
datafile copy file name=+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/users.377.965863449 RECID=15 STAMP=965863551
cataloged datafile copy
datafile copy file name=+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/test.378.965863451 RECID=16 STAMP=965863551

datafile 3 switched to datafile copy
input datafile copy RECID=1 STAMP=965863550 file name=+FRA/DUP/DATAFILE/sysaux.379.965863109
datafile 4 switched to datafile copy
input datafile copy RECID=2 STAMP=965863550 file name=+FRA/DUP/DATAFILE/undotbs1.380.965863215
datafile 6 switched to datafile copy
input datafile copy RECID=3 STAMP=965863550 file name=+FRA/DUP/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/sysaux.382.965863245
datafile 7 switched to datafile copy
input datafile copy RECID=4 STAMP=965863550 file name=+FRA/DUP/DATAFILE/users.364.965863281
datafile 8 switched to datafile copy
input datafile copy RECID=5 STAMP=965863550 file name=+FRA/DUP/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/undotbs1.365.965863281
datafile 9 switched to datafile copy
input datafile copy RECID=6 STAMP=965863550 file name=+FRA/DUP/DATAFILE/undotbs2.366.965863289
datafile 11 switched to datafile copy
input datafile copy RECID=7 STAMP=965863550 file name=+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/sysaux.326.965863309
datafile 12 switched to datafile copy
input datafile copy RECID=8 STAMP=965863550 file name=+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undotbs1.285.965863345
datafile 13 switched to datafile copy
input datafile copy RECID=9 STAMP=965863550 file name=+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undo_2.325.965863349
datafile 14 switched to datafile copy
input datafile copy RECID=10 STAMP=965863551 file name=+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/users.369.965863351
datafile 15 switched to datafile copy
input datafile copy RECID=11 STAMP=965863551 file name=+FRA/DUP/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/test.370.965863387
datafile 17 switched to datafile copy
input datafile copy RECID=12 STAMP=965863551 file name=+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/sysaux.372.965863407
datafile 18 switched to datafile copy
input datafile copy RECID=13 STAMP=965863551 file name=+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undotbs1.373.965863443
datafile 19 switched to datafile copy
input datafile copy RECID=14 STAMP=965863551 file name=+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undo_2.375.965863445
datafile 20 switched to datafile copy
input datafile copy RECID=15 STAMP=965863551 file name=+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/users.377.965863449
datafile 21 switched to datafile copy
input datafile copy RECID=16 STAMP=965863551 file name=+FRA/DUP/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/test.378.965863451

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

database opened

contents of Memory Script:
{
   sql clone "alter pluggable database all open";
}
executing Memory Script

sql statement: alter pluggable database all open
Finished Duplicate Db at 19-JAN-18

10.检查数据是否一致
在源数据库查询表记录

SQL> conn sys/abcd@jy as sysdba
Connected.
SQL> show parameter db_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_name                              string      jy
SQL> alter session set container=jypdb;

Session altered.

SQL> select count(*) from JY.SALES_Q3_1998;

  COUNT(*)
----------
     50515

在目标数据库查询表记录

SQL> conn sys/abcd@dup as sysdba
Connected.
SQL> show parameter db_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_name                              string      DUP
SQL> alter session set container=jypdb;

Session altered.

SQL> select count(*) from JY.SALES_Q3_1998;

  COUNT(*)
----------
     50515

到此复制整个RAC CDB数据库为RAC CDB数据库完成,后面就是向集群注册数据库就不详细介绍了。

Oracle 12c RMAN Duplicating the Whole CDB

下面的例子是将源RAC CDB数据库通过rman的duplicate命令复制一个单实例的CDB数据库,具体的复制操作如下
1.检查源RAC CDB(jy)的参数文件,数据文件,联机日志文件,控制文件,归档日志文件的存储目录

SQL> show parameter spfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- --------------------------------------------
spfile                               string      +DATA/JY/PARAMETERFILE/spfile.303.961976713

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
+DATA/JY/DATAFILE/system.317.962209603
+DATA/JY/DATAFILE/sysaux.298.962209605
+DATA/JY/DATAFILE/undotbs1.277.962209605
+DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/system.256.962209675
+DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/sysaux.270.962209675
+DATA/JY/DATAFILE/users.301.962209605
+DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/undotbs1.296.962209675
+DATA/JY/DATAFILE/undotbs2.312.962209605
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/system.271.962209649
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/sysaux.316.962209649
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undotbs1.264.962209649
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undo_2.268.962209649
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/users.278.962209649
+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/test.275.962210609
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/system.260.962469409
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/sysaux.259.962469409
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undotbs1.265.962469409
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undo_2.266.962469409
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/users.267.962469409
+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/test.269.962469409


SQL> show parameter control_files

NAME                                 TYPE        VALUE
------------------------------------ ----------- -------------------------------------------
control_files                        string      +DATA/JY/CONTROLFILE/current.272.961976315


SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
+DATA/JY/ONLINELOG/group_2.302.961976321
+DATA/JY/ONLINELOG/group_1.261.961976319
+DATA/JY/ONLINELOG/group_3.263.961976697
+DATA/JY/ONLINELOG/group_4.262.961976705


SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            +TEST/arch
Oldest online log sequence     127
Next log sequence to archive   128
Current log sequence           128

2.在目标主机上创建存储目标数据库(dupjy)相关数据库文件的目录,目标主机上的/u01/app/oracle/oradata/dupjy目录用来存储数据库的数据文件,控制文件,联机重做日志文件),/u01/app/oracle/arch/dupjy目录用来存储数据库的归档重做日志文件。

3.将源数据库的密码文件复制到目标主机的相应目录中并修改为目标数据库(dupjy)对应的文件名

[grid@jytest1 ~]$ srvctl config database -db jy
Database unique name: jy
Database name: jy
Oracle home: /u01/app/oracle/product/12.2.0/db
Oracle user: oracle
Spfile: +DATA/JY/PARAMETERFILE/spfile.303.961976713
Password file: +DATA/JY/PASSWORD/pwdjy.274.961976109
Domain: 
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: 
Disk Groups: DATA
Mount point paths: 
Services: 
Type: RAC
Start concurrency: 
Stop concurrency: 
OSDBA group: dba
OSOPER group: oper
Database instances: jy1,jy2
Configured nodes: jytest1,jytest2
CSS critical: no
CPU count: 0
Memory target: 0
Maximum memory: 0
Default network number for database services: 
Database is administrator managed

[grid@jytest1 ~]$ asmcmd cp  +DATA/JY/PASSWORD/pwdjy.274.961976109 /home/grid/pwddupjy
copying +DATA/JY/PASSWORD/pwdjy.274.961976109 -> /home/grid/pwddupjy


[oracle@shard1 dbs]# scp grid@10.138.130.171:/home/grid/pwddupjy /u01/app/oracle/product/12.2.0/db/dbs/
The authenticity of host '10.138.130.171 (10.138.130.171)' can't be established.
ECDSA key fingerprint is 7a:62:58:8b:77:98:52:94:d6:d5:0c:c4:6c:87:a6:7f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.138.130.171' (ECDSA) to the list of known hosts.
grid@10.138.130.171's password: 
pwddupjy          

[oracle@shard1 dbs]$ mv pwddupjy orapwdupjy

4.使用源数据库的spfile文件来创建目标数据库要使用的spfile文件,在源数据库中执行下面的命令来创建pfile参数文件

SQL> create pfile from spfile;

File created.

[root@shard1 ~]# scp oracle@10.138.130.171:/u01/app/oracle/product/12.2.0/db/dbs/initjy1.ora /u01/app/oracle/product/12.2.0/db/dbs/
grid@10.138.130.171's password: 
initjy1.ora                                                                                                                                                                                   

            100% 1731     1.7KB/s   00:00    
[root@shard1 ~]# 


[oracle@shard1 dbs]$ cat initdupjy.ora
*.audit_file_dest='/u01/app/oracle/admin/dupjy/adump'
*.cluster_database=false
*.compatible='12.2.0'
*.control_files='/u01/app/oracle/oradata/dupjy/control01.ctl'
*.db_block_size=8192
*.db_name='dupjy'
*.diagnostic_dest='/u01/app/oracle'
*.enable_pluggable_database=true
*.open_cursors=300
*.pga_aggregate_target=1g
*.processes=2000
*.remote_login_passwordfile='exclusive'
*.sga_max_size=2147483648
*.sga_target=2147483648
db_file_name_convert=
('+DATA/JY/DATAFILE/','/u01/app/oracle/oradata/dupjy/','+DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/','/u01/app/oracle/oradata/dupjy/','+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATA
FILE/','/u01/app/oracle/oradata/dupjy/','+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/','/u01/app/oracle/oradata/dupjy/')
log_file_name_convert=('+DATA/JY/ONLINELOG/','/u01/app/oracle/oradata/dupjy/')



[oracle@shard1 dbs]$ export ORACLE_SID=dupjy
[oracle@shard1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Thu Jan 18 19:06:00 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup nomount pfile='/u01/app/oracle/product/12.2.0/db/dbs/initdupjy.ora'
ORACLE instance started.

Total System Global Area 2147483648 bytes
Fixed Size                  8794848 bytes
Variable Size             570428704 bytes
Database Buffers         1560281088 bytes
Redo Buffers                7979008 bytes

SQL> create spfile from pfile='/u01/app/oracle/product/12.2.0/db/dbs/initdupjy.ora';

File created.

5.使用spfile参数文件来启动目标数据库实例(辅助实例dupjy)

SQL> shutdown immediate
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.

Total System Global Area 2147483648 bytes
Fixed Size                  8794848 bytes
Variable Size             570428704 bytes
Database Buffers         1560281088 bytes
Redo Buffers                7979008 bytes


SQL> show parameter spfile

NAME                                 TYPE                   VALUE
------------------------------------ ---------------------- -----------------------------------------------------
spfile                               string                 /u01/app/oracle/product/12.2.0/db/dbs/spfiledupjy.ora

6.给目标数据库配置静态监听

[oracle@shard1 admin]$ vi listener.ora 
# listener.ora Network Configuration File: /u01/app/oracle/product/12.2.0/db/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = shard1)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = dupjy)
      (ORACLE_HOME = /u01/app/oracle/product/12.2.0/db)
      (GLOBAL_DBNAME=dupjy)
    )
  )


[oracle@shard1 admin]$ lsnrctl start

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 18-JAN-2018 20:30:34

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

Starting /u01/app/oracle/product/12.2.0/db/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 12.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/12.2.0/db/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/shard1/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=shard1)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=shard1)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                18-JAN-2018 20:30:34
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.2.0/db/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/shard1/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=shard1)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "dupjy" has 1 instance(s).
  Instance "dupjy", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully


7.在目标主机上配置tns,用来通过网络服务名来连接源数据库与目标数据库

[oracle@shard1 admin]$ vi tnsnames.ora 
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/12.2.0/db/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

JY =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.138.130.171)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = jy)
    )
  )

DUPJY =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.138.130.180)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = dupjy)
    )
  )

8.在目标主机上测试是否可以通过使用网络服务名来连接源数据库与目标数据库

[oracle@shard1 admin]$ sqlplus /nolog

SQL*Plus: Release 12.2.0.1.0 Production on Thu Jan 18 21:02:53 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

SQL> conn / as sysdba
Connected.
SQL> startup nomount
ORACLE instance started.

Total System Global Area 2147483648 bytes
Fixed Size                  8794848 bytes
Variable Size             570428704 bytes
Database Buffers         1560281088 bytes
Redo Buffers                7979008 bytes
SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
[oracle@shard1 admin]$ sqlplus /nolog

SQL*Plus: Release 12.2.0.1.0 Production on Thu Jan 18 21:04:51 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

SQL> conn sys/abcd@dupjy as sysdba
Connected.
SQL> conn sys/abcd@jy as sysdba
Connected.

9.在源主机上配置目标数据库的tns名

[oracle@jytest1 admin]$ vi tnsnames.ora 
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/12.2.0/db/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.


JY =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = jytest-scan)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = jy)
    )
  )



DUPJY =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.138.130.180)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = dupjy)
      (UR = A)
    )
  )

10.在源主机上测试能否可以使用网络服务名来连接源数据库与目标数据库

[oracle@jytest1 admin]$ sqlplus /nolog

SQL*Plus: Release 12.2.0.1.0 Production on Fri Jan 19 03:16:59 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

SQL> conn sys/abcd@jy as sysdba
Connected.
SQL> conn sys/abcd@dupjy as sysdba
Connected.

11.执行数据库复制

[oracle@jytest1 admin]$ rman target sys/abcd@jy catalog rco/abcd@jypdb_173 auxiliary sys/abcd@dupjy

Recovery Manager: Release 12.2.0.1.0 - Production on Fri Jan 19 03:36:45 2018

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

connected to target database: JY (DBID=979425723)
connected to recovery catalog database
connected to auxiliary database: DUPJY (not mounted)

RMAN> duplicate target database to dupjy from active database nofilenamecheck using compressed backupset;

Starting Duplicate Db at 19-JAN-18
starting full resync of recovery catalog
full resync complete
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=2269 device type=DISK
current log archived

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''JY'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name = 
 ''dupjy'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone from service  'jy' using compressed backupset
   primary controlfile;
   alter clone database mount;
}
executing Memory Script

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

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

Oracle instance shut down

Oracle instance started

Total System Global Area    2147483648 bytes

Fixed Size                     8794848 bytes
Variable Size                570428704 bytes
Database Buffers            1560281088 bytes
Redo Buffers                   7979008 bytes

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

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:06
output file name=/u01/app/oracle/oradata/dupjy/control01.ctl
Finished restore at 19-JAN-18

database mounted
RMAN-05529: warning: DB_FILE_NAME_CONVERT resulted in invalid ASM names; names changed to disk group only.

contents of Memory Script:
{
   sql clone 'alter database flashback off';
   set newname for datafile  1 to 
 "/u01/app/oracle/oradata/dupjy/system.317.962209603";
   set newname for datafile  3 to 
 "/u01/app/oracle/oradata/dupjy/sysaux.298.962209605";
   set newname for datafile  4 to 
 "/u01/app/oracle/oradata/dupjy/undotbs1.277.962209605";
   set newname for datafile  5 to 
 "/u01/app/oracle/oradata/dupjy/system.256.962209675";
   set newname for datafile  6 to 
 "/u01/app/oracle/oradata/dupjy/sysaux.270.962209675";
   set newname for datafile  7 to 
 "/u01/app/oracle/oradata/dupjy/users.301.962209605";
   set newname for datafile  8 to 
 "/u01/app/oracle/oradata/dupjy/undotbs1.296.962209675";
   set newname for datafile  9 to 
 "/u01/app/oracle/oradata/dupjy/undotbs2.312.962209605";
   set newname for datafile  10 to 
 "/u01/app/oracle/oradata/dupjy/system.271.962209649";
   set newname for datafile  11 to 
 "/u01/app/oracle/oradata/dupjy/sysaux.316.962209649";
   set newname for datafile  12 to 
 "/u01/app/oracle/oradata/dupjy/undotbs1.264.962209649";
   set newname for datafile  13 to 
 "/u01/app/oracle/oradata/dupjy/undo_2.268.962209649";
   set newname for datafile  14 to 
 "/u01/app/oracle/oradata/dupjy/users.278.962209649";
   set newname for datafile  15 to 
 "/u01/app/oracle/oradata/dupjy/test.275.962210609";
   set newname for datafile  16 to 
 "/u01/app/oracle/oradata/dupjy/system.260.962469409";
   set newname for datafile  17 to 
 "/u01/app/oracle/oradata/dupjy/sysaux.259.962469409";
   set newname for datafile  18 to 
 "/u01/app/oracle/oradata/dupjy/undotbs1.265.962469409";
   set newname for datafile  19 to 
 "/u01/app/oracle/oradata/dupjy/undo_2.266.962469409";
   set newname for datafile  20 to 
 "/u01/app/oracle/oradata/dupjy/users.267.962469409";
   set newname for datafile  21 to 
 "/u01/app/oracle/oradata/dupjy/test.269.962469409";
   restore
   from  nonsparse   from service 
 'jy'   using compressed backupset
   clone database
   ;
   sql 'alter system archive log current';
}
executing Memory Script

sql statement: alter database flashback off

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 19-JAN-18
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/dupjy/system.317.962209603
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:15
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/dupjy/sysaux.298.962209605
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:03:06
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/dupjy/undotbs1.277.962209605
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:45
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/dupjy/system.256.962209675
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:36
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/dupjy/sysaux.270.962209675
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:56
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/dupjy/users.301.962209605
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00008 to /u01/app/oracle/oradata/dupjy/undotbs1.296.962209675
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00009 to /u01/app/oracle/oradata/dupjy/undotbs2.312.962209605
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:16
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00010 to /u01/app/oracle/oradata/dupjy/system.271.962209649
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:35
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00011 to /u01/app/oracle/oradata/dupjy/sysaux.316.962209649
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:16
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00012 to /u01/app/oracle/oradata/dupjy/undotbs1.264.962209649
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:18
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00013 to /u01/app/oracle/oradata/dupjy/undo_2.268.962209649
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:16
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00014 to /u01/app/oracle/oradata/dupjy/users.278.962209649
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:36
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00015 to /u01/app/oracle/oradata/dupjy/test.275.962210609
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00016 to /u01/app/oracle/oradata/dupjy/system.260.962469409
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:36
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00017 to /u01/app/oracle/oradata/dupjy/sysaux.259.962469409
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:05
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00018 to /u01/app/oracle/oradata/dupjy/undotbs1.265.962469409
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:16
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00019 to /u01/app/oracle/oradata/dupjy/undo_2.266.962469409
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00020 to /u01/app/oracle/oradata/dupjy/users.267.962469409
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00021 to /u01/app/oracle/oradata/dupjy/test.269.962469409
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:08
Finished restore at 19-JAN-18

sql statement: alter system archive log current
current log archived

contents of Memory Script:
{
   restore clone force from service  'jy' using compressed backupset
   archivelog from scn  12917437;
   switch clone datafile all;
}
executing Memory Script

Starting restore at 19-JAN-18
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=130
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=131
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=2 sequence=106
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:26
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=2 sequence=107
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using compressed network backup set from service jy
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=2 sequence=108
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 19-JAN-18

datafile 1 switched to datafile copy
input datafile copy RECID=24 STAMP=965771246 file name=/u01/app/oracle/oradata/dupjy/system.317.962209603
datafile 3 switched to datafile copy
input datafile copy RECID=25 STAMP=965771246 file name=/u01/app/oracle/oradata/dupjy/sysaux.298.962209605
datafile 4 switched to datafile copy
input datafile copy RECID=26 STAMP=965771246 file name=/u01/app/oracle/oradata/dupjy/undotbs1.277.962209605
datafile 5 switched to datafile copy
input datafile copy RECID=27 STAMP=965771246 file name=/u01/app/oracle/oradata/dupjy/system.256.962209675
datafile 6 switched to datafile copy
input datafile copy RECID=28 STAMP=965771247 file name=/u01/app/oracle/oradata/dupjy/sysaux.270.962209675
datafile 7 switched to datafile copy
input datafile copy RECID=29 STAMP=965771247 file name=/u01/app/oracle/oradata/dupjy/users.301.962209605
datafile 8 switched to datafile copy
input datafile copy RECID=30 STAMP=965771247 file name=/u01/app/oracle/oradata/dupjy/undotbs1.296.962209675
datafile 9 switched to datafile copy
input datafile copy RECID=31 STAMP=965771247 file name=/u01/app/oracle/oradata/dupjy/undotbs2.312.962209605
datafile 10 switched to datafile copy
input datafile copy RECID=32 STAMP=965771247 file name=/u01/app/oracle/oradata/dupjy/system.271.962209649
datafile 11 switched to datafile copy
input datafile copy RECID=33 STAMP=965771247 file name=/u01/app/oracle/oradata/dupjy/sysaux.316.962209649
datafile 12 switched to datafile copy
input datafile copy RECID=34 STAMP=965771247 file name=/u01/app/oracle/oradata/dupjy/undotbs1.264.962209649
datafile 13 switched to datafile copy
input datafile copy RECID=35 STAMP=965771247 file name=/u01/app/oracle/oradata/dupjy/undo_2.268.962209649
datafile 14 switched to datafile copy
input datafile copy RECID=36 STAMP=965771247 file name=/u01/app/oracle/oradata/dupjy/users.278.962209649
datafile 15 switched to datafile copy
input datafile copy RECID=37 STAMP=965771247 file name=/u01/app/oracle/oradata/dupjy/test.275.962210609
datafile 16 switched to datafile copy
input datafile copy RECID=38 STAMP=965771247 file name=/u01/app/oracle/oradata/dupjy/system.260.962469409
datafile 17 switched to datafile copy
input datafile copy RECID=39 STAMP=965771247 file name=/u01/app/oracle/oradata/dupjy/sysaux.259.962469409
datafile 18 switched to datafile copy
input datafile copy RECID=40 STAMP=965771248 file name=/u01/app/oracle/oradata/dupjy/undotbs1.265.962469409
datafile 19 switched to datafile copy
input datafile copy RECID=41 STAMP=965771248 file name=/u01/app/oracle/oradata/dupjy/undo_2.266.962469409
datafile 20 switched to datafile copy
input datafile copy RECID=42 STAMP=965771248 file name=/u01/app/oracle/oradata/dupjy/users.267.962469409
datafile 21 switched to datafile copy
input datafile copy RECID=43 STAMP=965771248 file name=/u01/app/oracle/oradata/dupjy/test.269.962469409

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

executing command: SET until clause

Starting recover at 19-JAN-18
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 130 is already on disk as file /u01/app/oracle/product/12.2.0/db/dbs/arch1_130_961976319.dbf
archived log for thread 1 with sequence 131 is already on disk as file /u01/app/oracle/product/12.2.0/db/dbs/arch1_131_961976319.dbf
archived log for thread 2 with sequence 107 is already on disk as file /u01/app/oracle/product/12.2.0/db/dbs/arch2_107_961976319.dbf
archived log for thread 2 with sequence 108 is already on disk as file /u01/app/oracle/product/12.2.0/db/dbs/arch2_108_961976319.dbf
archived log file name=/u01/app/oracle/product/12.2.0/db/dbs/arch1_130_961976319.dbf thread=1 sequence=130
archived log file name=/u01/app/oracle/product/12.2.0/db/dbs/arch2_107_961976319.dbf thread=2 sequence=107
archived log file name=/u01/app/oracle/product/12.2.0/db/dbs/arch2_108_961976319.dbf thread=2 sequence=108
archived log file name=/u01/app/oracle/product/12.2.0/db/dbs/arch1_131_961976319.dbf thread=1 sequence=131
media recovery complete, elapsed time: 00:00:02
Finished recover at 19-JAN-18
Oracle instance started

Total System Global Area    2147483648 bytes

Fixed Size                     8794848 bytes
Variable Size                570428704 bytes
Database Buffers            1560281088 bytes
Redo Buffers                   7979008 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''DUPJY'' comment=
 ''Reset to original value by RMAN'' scope=spfile";
   sql clone "alter system reset  db_unique_name scope=spfile";
}
executing Memory Script

sql statement: alter system set  db_name =  ''DUPJY'' comment= ''Reset to original value by RMAN'' scope=spfile

sql statement: alter system reset  db_unique_name scope=spfile
Oracle instance started

Total System Global Area    2147483648 bytes

Fixed Size                     8794848 bytes
Variable Size                570428704 bytes
Database Buffers            1560281088 bytes
Redo Buffers                   7979008 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUPJY" RESETLOGS ARCHIVELOG 
  MAXLOGFILES    192
  MAXLOGMEMBERS      3
  MAXDATAFILES     1024
  MAXINSTANCES    32
  MAXLOGHISTORY      292
 LOGFILE
  GROUP   1 ( '/u01/app/oracle/oradata/dupjy/group_1.261.961976319' ) SIZE 200 M  REUSE,
  GROUP   2 ( '/u01/app/oracle/oradata/dupjy/group_2.302.961976321' ) SIZE 200 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/dupjy/system.317.962209603',
  '/u01/app/oracle/oradata/dupjy/system.256.962209675',
  '/u01/app/oracle/oradata/dupjy/system.271.962209649',
  '/u01/app/oracle/oradata/dupjy/system.260.962469409'
 CHARACTER SET ZHS16GBK

sql statement: ALTER DATABASE ADD LOGFILE 
  
  INSTANCE 'i2' 
  GROUP   3 ( '/u01/app/oracle/oradata/dupjy/group_3.263.961976697' ) SIZE 200 M  REUSE,
  GROUP   4 ( '/u01/app/oracle/oradata/dupjy/group_4.262.961976705' ) SIZE 200 M  REUSE

contents of Memory Script:
{
   set newname for tempfile  1 to 
 "+DATA";
   set newname for tempfile  2 to 
 "+DATA";
   set newname for tempfile  3 to 
 "+DATA";
   set newname for tempfile  4 to 
 "+DATA";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/oradata/dupjy/sysaux.298.962209605", 
 "/u01/app/oracle/oradata/dupjy/undotbs1.277.962209605", 
 "/u01/app/oracle/oradata/dupjy/sysaux.270.962209675", 
 "/u01/app/oracle/oradata/dupjy/users.301.962209605", 
 "/u01/app/oracle/oradata/dupjy/undotbs1.296.962209675", 
 "/u01/app/oracle/oradata/dupjy/undotbs2.312.962209605", 
 "/u01/app/oracle/oradata/dupjy/sysaux.316.962209649", 
 "/u01/app/oracle/oradata/dupjy/undotbs1.264.962209649", 
 "/u01/app/oracle/oradata/dupjy/undo_2.268.962209649", 
 "/u01/app/oracle/oradata/dupjy/users.278.962209649", 
 "/u01/app/oracle/oradata/dupjy/test.275.962210609", 
 "/u01/app/oracle/oradata/dupjy/sysaux.259.962469409", 
 "/u01/app/oracle/oradata/dupjy/undotbs1.265.962469409", 
 "/u01/app/oracle/oradata/dupjy/undo_2.266.962469409", 
 "/u01/app/oracle/oradata/dupjy/users.267.962469409", 
 "/u01/app/oracle/oradata/dupjy/test.269.962469409";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to +DATA in control file
renamed tempfile 2 to +DATA in control file
renamed tempfile 3 to +DATA in control file
renamed tempfile 4 to +DATA in control file

cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/sysaux.298.962209605 RECID=1 STAMP=965771317
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/undotbs1.277.962209605 RECID=2 STAMP=965771317
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/sysaux.270.962209675 RECID=3 STAMP=965771317
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/users.301.962209605 RECID=4 STAMP=965771317
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/undotbs1.296.962209675 RECID=5 STAMP=965771317
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/undotbs2.312.962209605 RECID=6 STAMP=965771317
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/sysaux.316.962209649 RECID=7 STAMP=965771317
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/undotbs1.264.962209649 RECID=8 STAMP=965771317
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/undo_2.268.962209649 RECID=9 STAMP=965771317
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/users.278.962209649 RECID=10 STAMP=965771317
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/test.275.962210609 RECID=11 STAMP=965771317
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/sysaux.259.962469409 RECID=12 STAMP=965771317
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/undotbs1.265.962469409 RECID=13 STAMP=965771317
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/undo_2.266.962469409 RECID=14 STAMP=965771317
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/users.267.962469409 RECID=15 STAMP=965771317
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupjy/test.269.962469409 RECID=16 STAMP=965771317

datafile 3 switched to datafile copy
input datafile copy RECID=1 STAMP=965771317 file name=/u01/app/oracle/oradata/dupjy/sysaux.298.962209605
datafile 4 switched to datafile copy
input datafile copy RECID=2 STAMP=965771317 file name=/u01/app/oracle/oradata/dupjy/undotbs1.277.962209605
datafile 6 switched to datafile copy
input datafile copy RECID=3 STAMP=965771317 file name=/u01/app/oracle/oradata/dupjy/sysaux.270.962209675
datafile 7 switched to datafile copy
input datafile copy RECID=4 STAMP=965771317 file name=/u01/app/oracle/oradata/dupjy/users.301.962209605
datafile 8 switched to datafile copy
input datafile copy RECID=5 STAMP=965771317 file name=/u01/app/oracle/oradata/dupjy/undotbs1.296.962209675
datafile 9 switched to datafile copy
input datafile copy RECID=6 STAMP=965771317 file name=/u01/app/oracle/oradata/dupjy/undotbs2.312.962209605
datafile 11 switched to datafile copy
input datafile copy RECID=7 STAMP=965771317 file name=/u01/app/oracle/oradata/dupjy/sysaux.316.962209649
datafile 12 switched to datafile copy
input datafile copy RECID=8 STAMP=965771317 file name=/u01/app/oracle/oradata/dupjy/undotbs1.264.962209649
datafile 13 switched to datafile copy
input datafile copy RECID=9 STAMP=965771317 file name=/u01/app/oracle/oradata/dupjy/undo_2.268.962209649
datafile 14 switched to datafile copy
input datafile copy RECID=10 STAMP=965771317 file name=/u01/app/oracle/oradata/dupjy/users.278.962209649
datafile 15 switched to datafile copy
input datafile copy RECID=11 STAMP=965771317 file name=/u01/app/oracle/oradata/dupjy/test.275.962210609
datafile 17 switched to datafile copy
input datafile copy RECID=12 STAMP=965771317 file name=/u01/app/oracle/oradata/dupjy/sysaux.259.962469409
datafile 18 switched to datafile copy
input datafile copy RECID=13 STAMP=965771317 file name=/u01/app/oracle/oradata/dupjy/undotbs1.265.962469409
datafile 19 switched to datafile copy
input datafile copy RECID=14 STAMP=965771317 file name=/u01/app/oracle/oradata/dupjy/undo_2.266.962469409
datafile 20 switched to datafile copy
input datafile copy RECID=15 STAMP=965771317 file name=/u01/app/oracle/oradata/dupjy/users.267.962469409
datafile 21 switched to datafile copy
input datafile copy RECID=16 STAMP=965771317 file name=/u01/app/oracle/oradata/dupjy/test.269.962469409

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

database opened

contents of Memory Script:
{
   sql clone "alter pluggable database all open";
}
executing Memory Script

sql statement: alter pluggable database all open
Finished Duplicate Db at 19-JAN-18


12.检查数据是否一致
在源数据库查询表记录

SQL> conn sys/abcd@jypdb  as sysdba
Connected.

SQL> select count(*) from JY.SALES_Q3_1998;

  COUNT(*)
----------
     50515

在目标数据库查询表记录

SQL> conn sys/abcd@jypdb as sysdba
Connected.

SQL> select count(*) from JY.SALES_Q3_1998;

  COUNT(*)
----------
     50515

到此复制整个RAC CDB数据库为单实例CDB数据库完成

Oracle 12C xtts and dbms_file_transfer

1.初始化设置阶段
1.1安装目标数据库软件并创建目标数据库
在目标系统上安装目标Oracle数据库软件,版本应该为Oracle12c,操作系统是Linux,我这里都是12.2.0.1。在源数据库中创建了一个要被传输到目标数据库的表空间jy,用户方案jy,源数据库版本也是12.2.0.1,操作系统是Linux。

1.2识别要被传输的表空间
源数据库中要被传输的表空间为jy,用户方案jy。

1.3在源系统上安装xttconvert脚本

[oracle@jytest3 xtts_script]$ unzip rman_xttconvert_v3.zip
Archive:  rman_xttconvert_v3.zip
  inflating: xtt.properties
  inflating: xttcnvrtbkupdest.sql
  inflating: xttdbopen.sql
  inflating: xttdriver.pl
  inflating: xttprep.tmpl
 extracting: xttstartupnomount.sql

 [oracle@jytest1 backup]$ vi $ORACLE_HOME/dbs/initxtt.ora
db_name=xtt
compatible=12.2.0.0.0
[oracle@jytest1 backup]$ export ORACLE_SID=xtt
[oracle@jytest1 backup]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Tue Aug 22 18:25:46 2017

Copyright (c) 1982, 2016, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> startup nomount
ORACLE instance started.

Total System Global Area  444596224 bytes
Fixed Size                  8621520 bytes
Variable Size             377487920 bytes
Database Buffers           50331648 bytes
Redo Buffers                8155136 bytes

1.4 创建需要使用的目录
如果使用dbms_file_transfer方法,那么配置目录对象与dblink,注意dbms_file_transfer方法要求目标数据库的版本为11.2.0.4,如果使用dbms_file_transfer访求,那么必须创建以下三个数据库对象:
.在源数据库中创建一个数据库目录对象,它指向要被复制的数据文件所存放的目录
.在目标数据库中创建一个数据库目录对象,它指向将要存放数据文件的目录
.在目标数据库中创建一个dblink连接到源数据库

源数据库目录对象引用源数据库中当前存放数据文件的目录。例如,下面创建目录对象指向,数据文件存放目录+DATA/ORCL/DATAFILE/,连接到源数据库房执行以下命令:

[oracle@jytest3 ~]$ export ORACLE_SID=orcl
[oracle@jytest3 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Mon Aug 21 19:57:36 2017

Copyright (c) 1982, 2016, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
+DATA/ORCL/DATAFILE/system.280.941831569
+DATA/ORCL/DATAFILE/sysaux.281.941831647
+DATA/ORCL/DATAFILE/undotbs1.282.941831677
+DATA/ORCL/DATAFILE/users.284.941831687
+DATA/ORCL/DATAFILE/jy.371.952394755

SQL> create directory sourcedir as '+DATA/ORCL/DATAFILE';

Directory created.

目标数据库目录对象引用目标数据库中将要存储数据文件的目录。这个目录是最终目标数据库将要存放数据文件的目录+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/,连接到目标数据库执行以下命令要注意的是目录对象与dblink要在CDB中创建

[oracle@jytest1 ~]$ sqlplus /nolog

SQL*Plus: Release 12.2.0.1.0 Production on Mon Aug 21 16:24:46 2017

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

SQL> conn sys/abcd@jy as sysdba
Connected.

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
+DATA/JY/4B2C6373AE2547CCE053AB828A0A7CA3/DATAFILE/system.274.939167015
+DATA/JY/4B2C6373AE2547CCE053AB828A0A7CA3/DATAFILE/sysaux.275.939167015
+DATA/JY/4B2C6373AE2547CCE053AB828A0A7CA3/DATAFILE/undotbs1.273.939167015
+DATA/JY/4B2C6373AE2547CCE053AB828A0A7CA3/DATAFILE/undo_2.277.939167063
+DATA/JY/4B2C6373AE2547CCE053AB828A0A7CA3/DATAFILE/testtb01.dbf
+DATA/JY/4B2C6373AE2547CCE053AB828A0A7CA3/DATAFILE/undotbs2.278.945029905
+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/example01.dbf
+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/test01.dbf
+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/users01.dbf
+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/sales_test_01.dbf
+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/emp_test_01.dbf

NAME
--------------------------------------------------------------------------------
+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/orders_test_01.dbf

12 rows selected.

SQL> create directory destdir as '+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile';

Directory created.

在目标数据库中创建一个dblink连接到源数据库。例如创建一个名叫ttslink的dblink,执行以下命令:

SQL> create public database link ttslink
  2    connect to system identified by "xxzx#7817600"
  3    using '(DESCRIPTION =
  4      (ADDRESS_LIST =
  5        (ADDRESS = (PROTOCOL = TCP)(HOST =10.138.130.173)(PORT = 1521))
  6      )
  7      (CONNECT_DATA =
  8        (SERVER = DEDICATED)
  9        (SERVICE_NAME =orcl)
 10      )
 11    )';

Database link created.

SQL> select * from dual@ttslink;

D
-
X

在源系统中创建目录/ora_xtts/backupformat用来存储源系统中对源数据库生成的备份及增量备份文件,xtt.properties文件中的backupformat参数设置该目录。

[oracle@jytest3 ora_xtts]$ mkdir backupformat

在目标系统中创建目录/tts/backup用来存储手动从源系统中传输过来的备份及增量备份文件,xtt.properties文件中的stageondest参数设置该目录。

[oracle@jytest1 tts]$ mkdir backup

xtt.properties文件中的storageondest参数设置目标数据库最终存储数据文件的目录,这里是

+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/目录。

1.5在源系统中配置xtt.properties文件

SQL> select platform_id from v$database;

PLATFORM_ID
-----------
         13


[oracle@jytest3 xtts_script]$ vi xtt.properties
tablespaces=JY
platformid=13
srcdir=SOURCEDIR
dstdir=DESTDIR
srclink=ttslink
storageondest=+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/
backupformat=/ora_xtts/backupformat
stageondest=/tts/xtts
backupondest=/tts/backup
asm_home=/u01/app/product/12.2.0/crs
asm_sid=+ASM1
parallel=4
cnvinst_home=/u01/app/oracle/product/12.2.0/db
cnvinst_sid=xtt

1.6将源系统中的xttconvert脚本与xtt.properties文件复制到目标系统中
在源系统中以Oracle软件用户来进行复制

[oracle@jytest1 tts]$ scp -r oracle@10.138.130.173:/ora_xtts/xtts_script/ /tts/
The authenticity of host '10.138.130.173 (10.138.130.173)' can't be established.
ECDSA key fingerprint is 67:29:52:b1:c0:74:ff:33:fc:67:63:53:31:14:69:ec.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.138.130.173' (ECDSA) to the list of known hosts.
oracle@10.138.130.173's password:
rman_xttconvert_v3.zip                                                                                                                                                                                    100%   33KB  33.2KB/s   00:00
xttcnvrtbkupdest.sql                                                                                                                                                                                      100% 1390     1.4KB/s   00:00
xttdbopen.sql                                                                                                                                                                                             100%   71     0.1KB/s   00:00
xttdriver.pl                                                                                                                                                                                              100%  136KB 136.1KB/s   00:00
xttprep.tmpl                                                                                                                                                                                              100%   11KB  11.4KB/s   00:00
xttstartupnomount.sql                                                                                                                                                                                     100%   52     0.1KB/s   00:00
xtt.properties.jy                                                                                                                                                                                         100% 7969     7.8KB/s   00:00
xtt.properties                                                                                                                                                                                            100%  217     0.2KB/s   00:00

[oracle@jytest1 tts]$ cd xtts_script
[oracle@jytest1 xtts_script]$ ls -lrt
total 212
-rw-r--r-- 1 oracle oinstall  33949 Aug 18 23:35 rman_xttconvert_v3.zip
-rw-r--r-- 1 oracle oinstall   1390 Aug 18 23:35 xttcnvrtbkupdest.sql
-rw-r--r-- 1 oracle oinstall     71 Aug 18 23:35 xttdbopen.sql
-rw-r--r-- 1 oracle oinstall 139331 Aug 18 23:35 xttdriver.pl
-rw-r--r-- 1 oracle oinstall  11710 Aug 18 23:35 xttprep.tmpl
-rw-r--r-- 1 oracle oinstall     52 Aug 18 23:35 xttstartupnomount.sql
-rw-r--r-- 1 oracle oinstall   7969 Aug 18 23:35 xtt.properties.jy
-rw-r--r-- 1 oracle oinstall    217 Aug 18 23:35 xtt.properties

1.7设置环境变量TMPDIR
在源系统与目标系统中设置环境变量TMPDIR。使用shell来执行Perl脚本xttdriver.pl所生成的文件会存储在$TMPDIR目录中,如果没有设置TMPDIR环境变量,那么生成的文件会存储在/tmp目录中。

源系统

[oracle@jytest3 ora_xtts]$ export TMPDIR=/ora_xtts/xtts_script

目标系统

[oracle@jytest1 tts]$ export TMPDIR=/tts/xtts_script

2.准备阶段
在准备阶段,要被传输的表空间会在源系统中生成备份,然后将备份传输到目标系统中,并通过执行xttdriver.pl脚本将备份还原。注意,对于要传输大量数据文件,可以使用dbms_file_transfer进行传输(可以参考文档 1389592.1中的准备阶段)会要比手动传输备份文件到目标系统中快很多。这种方法也适用于Oracle 12c,11G – Reduce Transportable Tablespace Downtime using Cross Platform Incremental Backup (Doc ID 1389592.1).

2.1在源系统中对要传输的表空间生成备份
在源系统中,以oracle软件用户登录,并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向源数据库,执行以下命令来生成备份

[oracle@jytest3 xtts_script]$ export ORACLE_HOME=/u01/app/oracle/product/12.2.0/db
[oracle@jytest3 xtts_script]$ export ORACLE_SID=orcl

[oracle@jytest3 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -S
============================================================
trace file is /ora_xtts/xtts_script/setupgetfile_Aug21_Mon_20_33_36_837//Aug21_Mon_20_33_36_837_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Starting prepare phase
--------------------------------------------------------------------

Prepare source for Tablespaces:
                  'JY'  /tts/xtts
xttpreparesrc.sql for 'JY' started at Mon Aug 21 20:33:36 2017
xttpreparesrc.sql for  ended at Mon Aug 21 20:33:36 2017
Prepare source for Tablespaces:
                  ''''  /tts/xtts
xttpreparesrc.sql for '''' started at Mon Aug 21 20:33:36 2017
xttpreparesrc.sql for  ended at Mon Aug 21 20:33:36 2017

--------------------------------------------------------------------
Done with prepare phase
--------------------------------------------------------------------


[oracle@jytest3 xtts_script]$ cat xttnewdatafiles.txt
::JY
5,DESTDIR:/jy.371.952394755
[oracle@jytest3 xtts_script]$ cat getfile.sql
0,SOURCEDIR,jy.371.952394755,DESTDIR,jy_371_952394755

要被传输的一组表空间必须是online,read write状态且不包含脱机数据文件。如果在源数据库中被传输表空间的一个或多个数据文件是脱机状态或read only就会触发错误。如果表空间在整个表空间传输过程中都保持read only状态,那么就使用传统的跨平台传输表空间,不要使用跨平台增量备份传输表空间。

2.2 传输数据文件到目标系统中
在目标系统中,使用Oracle软件用户登录并设置相关环境变量(ORACLE_HOME与ORACLE_SID)来指向目标数据库,并复制上一步生成的xttnewdatafiles.txt与getfile.sql文件到目标系统并执行操作来获取数据文件

[oracle@jytest1 xtts_script]$ scp oracle@10.138.130.173:/ora_xtts/xtts_script/xttnewdatafiles.txt /tts/xtts_script/
oracle@10.138.130.173's password:
xttnewdatafiles.txt                                                                                                                                                                                       100%   33     0.0KB/s   00:00
[oracle@jytest1 xtts_script]$ scp oracle@10.138.130.173:/ora_xtts/xtts_script/getfile.sql    /tts/xtts_script/
oracle@10.138.130.173's password:
getfile.sql                                                                                                                                                                                               100%   54     0.1KB/s   00:00
[oracle@jytest1 xtts_script]$ ls -lrt
total 220
-rw-r--r-- 1 oracle oinstall   1390 May 24 16:57 xttcnvrtbkupdest.sql
-rw-r--r-- 1 oracle oinstall     52 May 24 16:57 xttstartupnomount.sql
-rw-r--r-- 1 oracle oinstall  11710 May 24 16:57 xttprep.tmpl
-rw-r--r-- 1 oracle oinstall 139331 May 24 16:57 xttdriver.pl
-rw-r--r-- 1 oracle oinstall     71 May 24 16:57 xttdbopen.sql
-rw-r--r-- 1 oracle oinstall   7969 Jun  5 08:47 xtt.properties.jy
-rw-r--r-- 1 oracle oinstall  33949 Aug 18 23:35 rman_xttconvert_v3.zip
-rw-r--r-- 1 oracle oinstall    351 Aug 21 17:02 xtt.properties
-rw-r--r-- 1 oracle oinstall     33 Aug 21 17:17 xttnewdatafiles.txt
-rw-r--r-- 1 oracle oinstall     54 Aug 21 17:17 getfile.sql

[oracle@jytest1 xtts_script]$ export TMPDIR=/tts/xtts_script
[oracle@jytest1 xtts_script]$ export ORACLE_HOME=/u01/app/oracle/product/12.2.0/db
[oracle@jytest1 xtts_script]$ export ORACLE_SID=jy1
[oracle@jytest1 xtts_script]$ export XTTDEBUG=1
[oracle@jytest1 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -G
============================================================
trace file is /tts/xtts_script/getfile_Aug22_Tue_17_28_19_991//Aug22_Tue_17_28_19_991_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------

Key: cnvinst_home
Values: /u01/app/oracle/product/12.2.0/db
Key: backupondest
Values: /tts/backup
Key: backupformat
Values: /ora_xtts/backupformat
Key: cnvinst_sid
Values: jy1
Key: asm_sid
Values: +ASM1
Key: stageondest
Values: /tts/xtts
Key: srclink
Values: ttslink
Key: parallel
Values: 4
Key: tablespaces
Values: JY
Key: platformid
Values: 13
Key: asm_home
Values: /u01/app/product/12.2.0/crs
Key: dstdir
Values: DESTDIR
Key: srcdir
Values: SOURCEDIR
Key: storageondest
Values: +DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/

--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------

ARGUMENT tablespaces
ARGUMENT platformid
ARGUMENT backupformat
ARGUMENT stageondest
ARGUMENT srcdir
ARGUMENT dstdir
ARGUMENT srclink

--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

ORACLE_SID  : jy1
ORACLE_HOME : /u01/app/oracle/product/12.2.0/db

--------------------------------------------------------------------
Getting datafiles from source
--------------------------------------------------------------------

fetchCheckDirObjectsDST: Check dir path

fetchDirEntry: remotelink not present


--------------------------------------------------------------------
Executing getfile for /tts/xtts_script/getfile_Aug22_Tue_17_28_19_991//getfile_sourcedir_jy.371.952394755_0.sql
--------------------------------------------------------------------

PL/SQL procedure successfully completed.

--------------------------------------------------------------------
Completed getting datafiles from source
--------------------------------------------------------------------

3.前滚阶段
下面在源数据库中创建增量数据

SQL> select * from jy.jy_test;

   USER_ID
----------
         1
         2
         3
SQL> insert into jy.jy_test values(4);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from jy.jy_test;

   USER_ID
----------
         1
         2
         3
         4

在这个阶段会在源系统中对源数据库创建增量备份,将增量备份文件传输到目标系统并转换为目标系统所使用的字节序,然后将转换后的增量备份应用到数据文件。这个阶段的操作可以执行多次。每一次成功的增量备份所花的时间要比上一次的少,这将使用目标数据库中的数据文件的内容更接近源数据库的内容。在执行这个阶段操作时被传输的数据完全可以被访问。

3.1 在源系统中对被传输的表空间LDJC,CDZJ创建增量备份
在源系统中,以Oracle软件用户登录并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向源数据库,并执行以下命令来创建增量备份:

[oracle@jytest3 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -i
============================================================
trace file is /ora_xtts/xtts_script/incremental_Aug22_Tue_21_19_39_709//Aug22_Tue_21_19_39_709_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------

Key: srclink
Values: ttslink
Key: cnvinst_home
Values: /u01/app/oracle/product/12.2.0/db
Key: platformid
Values: 13
Key: storageondest
Values: +DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/
Key: asm_sid
Values: +ASM1
Key: dstdir
Values: DESTDIR
Key: backupondest
Values: /tts/backup
Key: srcdir
Values: SOURCEDIR
Key: cnvinst_sid
Values: jy1
Key: tablespaces
Values: JY
Key: asm_home
Values: /u01/app/product/12.2.0/crs
Key: backupformat
Values: /ora_xtts/backupformat
Key: parallel
Values: 4
Key: stageondest
Values: /tts/xtts

--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------

ARGUMENT tablespaces
ARGUMENT platformid
ARGUMENT backupformat
ARGUMENT stageondest

--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

ORACLE_SID  : orcl
ORACLE_HOME : /u01/app/oracle/product/12.2.0/db

--------------------------------------------------------------------
Backup incremental
--------------------------------------------------------------------

fetchCheckDirObjectsSRC: Check dir path

fetchDirEntry: remotelink not present

TABLESPACE STRING :'JY'
Prepare source for Tablespaces:
                  'JY'  /tts/xtts
xttpreparesrc.sql for 'JY' started at Tue Aug 22 21:19:39 2017
xttpreparesrc.sql for  ended at Tue Aug 22 21:19:39 2017
#DNAME:+DATA/ORCL/DATAFILE
#FNAME:jy.371.952394755
#PLAN:JY::::62924193
#TRANSFER:source_file_name=JY,+DATA/ORCL/DATAFILE,jy.371.952394755
#NEWDESTDF:5,DESTDIR:+DATA/ORCL/DATAFILE,/jy.371.952394755
#PLAN:5
verifySrcdirDatafiles: Entered
TABLESPACE STRING :''''
Prepare source for Tablespaces:
                  ''''  /tts/xtts
xttpreparesrc.sql for '''' started at Tue Aug 22 21:19:39 2017
xttpreparesrc.sql for  ended at Tue Aug 22 21:19:40 2017

verifySrcdirDatafiles: Entered
JY: +DATA/ORCL/DATAFILE/jy.371.952394755

============================================================
No new datafiles added
=============================================================
TABLESPACE STRING :'JY'
Prepare newscn for Tablespaces: 'JY'
JY::::62924193
 5
TABLESPACE STRING :''''''
Prepare newscn for Tablespaces: ''''''


--------------------------------------------------------------------
Starting incremental backup
--------------------------------------------------------------------

/ora_xtts/xtts_script/incremental_Aug22_Tue_21_19_39_709//rmanincr.cmd

Recovery Manager: Release 12.2.0.1.0 - Production on Tue Aug 22 21:19:40 2017

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

RMAN-06005: connected to target database: ORCL (DBID=1469612247)

RMAN> set nocfau;
2> host 'echo ts::JY';
3> backup incremental from scn 62924193
4>   tag tts_incr_update tablespace 'JY'  format
5>  '/ora_xtts/backupformat/%U';
6>
RMAN-03023: executing command: SET NOCFAU
RMAN-06009: using target database control file instead of recovery catalog

ts::JY
RMAN-06134: host command complete

RMAN-03090: Starting backup at 22-AUG-17
RMAN-08030: allocated channel: ORA_DISK_1
RMAN-08500: channel ORA_DISK_1: SID=43 device type=DISK
RMAN-08008: channel ORA_DISK_1: starting full datafile backup set
RMAN-08010: channel ORA_DISK_1: specifying datafile(s) in backup set
RMAN-08522: input datafile file number=00005 name=+DATA/ORCL/DATAFILE/jy.371.952394755
RMAN-08038: channel ORA_DISK_1: starting piece 1 at 22-AUG-17
RMAN-08044: channel ORA_DISK_1: finished piece 1 at 22-AUG-17
RMAN-08530: piece handle=/ora_xtts/backupformat/2dscipng_1_1 tag=TTS_INCR_UPDATE comment=NONE
RMAN-08540: channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
RMAN-03091: Finished backup at 22-AUG-17

Recovery Manager complete.


--------------------------------------------------------------------
Done backing up incrementals
--------------------------------------------------------------------

上面的操作会执行RMAN命令对xtt.properties文件中所指定的所有表空间生成增量备份文件。并且还将创建以下文件供后面的操作使用:
.tsbkupmap.txt
.incrbackups.txt

tsbkupmap.txt的内容如下:

[oracle@jytest3 xtts_script]$ cat tsbkupmap.txt
JY::5:::1=2dscipng_1_1

文件中的内容记录了表空间与增量备份的关联关系

incrbackups.txt的内容如下:

[oracle@jytest3 xtts_script]$ cat incrbackups.txt
/ora_xtts/backupformat/2dscipng_1_1

文件中的内容显示了生成的增量备份文件信息

[oracle@jytest3 backupformat]$ ls -lrt
total 56
-rw-r-----. 1 oracle asmadmin 57344 Aug 22 21:19 2dscipng_1_1

3.2 将增量备份传输到目标系统中
将上一步生成的增量备份传输到目标系统中由xtt.properties文件中的stageondest目录(/oracle11/xtts)中。

[oracle@jytest3 xtts_script]$ scp `cat incrbackups.txt` oracle@10.138.130.171:/tts/xtts/
oracle@10.138.130.171's password:
2dscipng_1_1
                                                                                                                                                                               100%   56KB  56.0KB/s   00:00

3.3 在目标系统中转换增量备份并应用到数据文件副本
在目标系统中以Oracle软件用户登录并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向目标数据库,并从源系统中将上一步生成的xttplan.txt与tsbkupmap.txt文件。

[oracle@jytest3 xtts_script]$ scp /ora_xtts/xtts_script/xttplan.txt oracle@10.138.130.171:/tts/xtts_script
oracle@10.138.130.171's password:
xttplan.txt                                                                                                                                                                                               100%   17     0.0KB/s   00:00
[oracle@jytest3 xtts_script]$ scp /ora_xtts/xtts_script/tsbkupmap.txt oracle@10.138.130.171:/tts/xtts_script
oracle@10.138.130.171's password:
tsbkupmap.txt                                                                                                                                                                                             100%   23     0.0KB/s   00:00
[oracle@jytest3 xtts_script]$ scp /ora_xtts/xtts_script/incrbackups.txt oracle@10.138.130.171:/tts/xtts_script
oracle@10.138.130.171's password:
incrbackups.txt                                                                                                                                                                                           100%   36     0.0KB/s   00:00


[oracle@jytest1 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -r
============================================================
trace file is /tts/xtts_script/rollforward_Aug22_Tue_18_27_05_399//Aug22_Tue_18_27_05_399_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------

Key: backupformat
Values: /ora_xtts/backupformat
Key: srclink
Values: ttslink
Key: tablespaces
Values: JY
Key: parallel
Values: 4
Key: asm_home
Values: /u01/app/product/12.2.0/crs
Key: cnvinst_sid
Values: xtt
Key: platformid
Values: 13
Key: stageondest
Values: /tts/xtts
Key: cnvinst_home
Values: /u01/app/oracle/product/12.2.0/db
Key: asm_sid
Values: +ASM1
Key: dstdir
Values: DESTDIR
Key: backupondest
Values: /tts/backup
Key: srcdir
Values: SOURCEDIR

--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------

ARGUMENT tablespaces
ARGUMENT platformid
ARGUMENT backupformat
ARGUMENT stageondest
ARGUMENT backupondest

--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

ORACLE_SID  : jy1
ORACLE_HOME : /u01/app/oracle/product/12.2.0/db

--------------------------------------------------------------------
Start rollforward
--------------------------------------------------------------------

convert instance: /u01/app/oracle/product/12.2.0/db

convert instance: xtt

ORACLE instance started.

Total System Global Area 6442450944 bytes
Fixed Size                  8807168 bytes
Variable Size            3909094656 bytes
Database Buffers         1442840576 bytes
Redo Buffers                7966720 bytes
In-Memory Area           1073741824 bytes
rdfno 5

BEFORE ROLLPLAN

datafile number : 5

datafile name   : +DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/jy_371_952394755

AFTER ROLLPLAN

CONVERTED BACKUP PIECE/tts/backup/xib_2dscipng_1_1_5

PL/SQL procedure successfully completed.
Entering RollForward
After applySetDataFile
Done: applyDataFileTo
Done: applyDataFileTo
Done: RestoreSetPiece
Done: RestoreBackupPiece

PL/SQL procedure successfully completed.
asmcmd rm /tts/backup/xib_2dscipng_1_1_5  /u01/app/product/12.2.0/crs .. +ASM1

Connected to an idle instance.
ASMCMD-8102: no connection to Oracle ASM; command requires Oracle ASM to run
ASMCMD:


--------------------------------------------------------------------
End of rollforward phase
--------------------------------------------------------------------

这步前滚数据文件的操作,会以sys用户连接到增量转换实例,转换完增量备份后,然后连接到目标数据库并将增量备份应用到每个表空间注意:对于每一次增量备份都需要将xttplan.txt与tsbkupmap.txt文件复制一次,不要对脚本所生成的xttplan.txt.new文件进行修改,复制或者其它任何改变。执行这步操作时目标实例会进行重启操作。

3.4 为下一次增量备份判断from_scn
再次生成增量数据

SQL> insert into jy.jy_test values(5);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from jy.jy_test;

   USER_ID
----------
         1
         2
         3
         4
         5

在源系统中,以Oracle软件用户登录并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向源数据库,执行以下命令来判断from_scn:

[oracle@jytest3 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -s
============================================================
trace file is /ora_xtts/xtts_script/determinescn_Aug22_Tue_21_54_18_326//Aug22_Tue_21_54_18_326_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------

Key: backupformat
Values: /ora_xtts/backupformat
Key: cnvinst_home
Values: /u01/app/oracle/product/12.2.0/db
Key: tablespaces
Values: JY
Key: platformid
Values: 13
Key: stageondest
Values: /tts/xtts
Key: backupondest
Values: /tts/backup
Key: parallel
Values: 4
Key: asm_home
Values: /u01/app/product/12.2.0/crs
Key: srcdir
Values: SOURCEDIR
Key: dstdir
Values: DESTDIR
Key: asm_sid
Values: +ASM1
Key: cnvinst_sid
Values: xtt
Key: srclink
Values: ttslink

--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------

ARGUMENT tablespaces
ARGUMENT platformid
ARGUMENT backupformat
ARGUMENT stageondest

--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

ORACLE_SID  : orcl
ORACLE_HOME : /u01/app/oracle/product/12.2.0/db
TABLESPACE STRING :'JY'
Prepare newscn for Tablespaces: 'JY'

TABLESPACE STRING :''''
Prepare newscn for Tablespaces: ''''

New /ora_xtts/xtts_script/xttplan.txt with FROM SCN's generated


New /ora_xtts/xtts_script/xttplan.txt with FROM SCN's generated
[oracle@jytest3 xtts_script]$ cat xttplan.txt
 JY::::62924193
 5

4.传输阶段
在执行传输阶段操作时,源数据库中被传输表空间要设置为read only状态,并且通过创建与应用最后一次的增量备份使用目标数据库中的数据文件与源数据库中的数据文件内容保持一致。在目标数据库数据文件与源数据库数据文件内容达成一致后,在源系统中执行正常的传输表空间操作来导出元数据,然后将元数据导入到目标数据库中。直到传输阶段操作完成之前,被传输的数据只能以read only模式被访问。

4.1 将源数据库中被传输表空间设置为read only状态
在源系统中,以Oracle软件用户登录并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向源数据库,并执行以下命令将表空间设置为read only:

SQL> alter tablespace jy read only;

Tablespace altered.

4.2 最后一次创建增量备份,并传输到目标系统且执行转换并应用到目标数据文件
在源系统中,以Oracle软件用户登录并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向源数据库,并执行以下命令来创建增量备份:

[oracle@jytest3 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -i
============================================================
trace file is /ora_xtts/xtts_script/incremental_Aug22_Tue_21_57_21_478//Aug22_Tue_21_57_21_478_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------

Key: parallel
Values: 4
Key: backupformat
Values: /ora_xtts/backupformat
Key: asm_home
Values: /u01/app/product/12.2.0/crs
Key: platformid
Values: 13
Key: tablespaces
Values: JY
Key: cnvinst_home
Values: /u01/app/oracle/product/12.2.0/db
Key: stageondest
Values: /tts/xtts
Key: srclink
Values: ttslink
Key: srcdir
Values: SOURCEDIR
Key: backupondest
Values: /tts/backup
Key: dstdir
Values: DESTDIR
Key: asm_sid
Values: +ASM1
Key: cnvinst_sid
Values: xtt

--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------

ARGUMENT tablespaces
ARGUMENT platformid
ARGUMENT backupformat
ARGUMENT stageondest

--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

ORACLE_SID  : orcl
ORACLE_HOME : /u01/app/oracle/product/12.2.0/db

--------------------------------------------------------------------
Backup incremental
--------------------------------------------------------------------

fetchCheckDirObjectsSRC: Check dir path

fetchDirEntry: remotelink not present

TABLESPACE STRING :'JY'
Prepare source for Tablespaces:
                  'JY'  /tts/xtts
xttpreparesrc.sql for 'JY' started at Tue Aug 22 21:57:21 2017
xttpreparesrc.sql for  ended at Tue Aug 22 21:57:21 2017
#DNAME:+DATA/ORCL/DATAFILE
#FNAME:jy.371.952394755
#PLAN:JY::::62928997
#TRANSFER:source_file_name=JY,+DATA/ORCL/DATAFILE,jy.371.952394755
#NEWDESTDF:5,DESTDIR:+DATA/ORCL/DATAFILE,/jy.371.952394755
#PLAN:5
verifySrcdirDatafiles: Entered
TABLESPACE STRING :''''
Prepare source for Tablespaces:
                  ''''  /tts/xtts
xttpreparesrc.sql for '''' started at Tue Aug 22 21:57:21 2017
xttpreparesrc.sql for  ended at Tue Aug 22 21:57:21 2017

verifySrcdirDatafiles: Entered
JY: +DATA/ORCL/DATAFILE/jy.371.952394755

============================================================
No new datafiles added
=============================================================
TABLESPACE STRING :'JY'
Prepare newscn for Tablespaces: 'JY'
JY::::62928997
 5
TABLESPACE STRING :''''''
Prepare newscn for Tablespaces: ''''''


--------------------------------------------------------------------
Starting incremental backup
--------------------------------------------------------------------

/ora_xtts/xtts_script/incremental_Aug22_Tue_21_57_21_478//rmanincr.cmd

Recovery Manager: Release 12.2.0.1.0 - Production on Tue Aug 22 21:57:21 2017

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

RMAN-06005: connected to target database: ORCL (DBID=1469612247)

RMAN> set nocfau;
2> host 'echo ts::JY';
3> backup incremental from scn 62924193
4>   tag tts_incr_update tablespace 'JY'  format
5>  '/ora_xtts/backupformat/%U';
6>
RMAN-03023: executing command: SET NOCFAU
RMAN-06009: using target database control file instead of recovery catalog

ts::JY
RMAN-06134: host command complete

RMAN-03090: Starting backup at 22-AUG-17
RMAN-08030: allocated channel: ORA_DISK_1
RMAN-08500: channel ORA_DISK_1: SID=43 device type=DISK
RMAN-08008: channel ORA_DISK_1: starting full datafile backup set
RMAN-08010: channel ORA_DISK_1: specifying datafile(s) in backup set
RMAN-08522: input datafile file number=00005 name=+DATA/ORCL/DATAFILE/jy.371.952394755
RMAN-08038: channel ORA_DISK_1: starting piece 1 at 22-AUG-17
RMAN-08044: channel ORA_DISK_1: finished piece 1 at 22-AUG-17
RMAN-08530: piece handle=/ora_xtts/backupformat/2esciru5_1_1 tag=TTS_INCR_UPDATE comment=NONE
RMAN-08540: channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
RMAN-03091: Finished backup at 22-AUG-17

Recovery Manager complete.


--------------------------------------------------------------------
Done backing up incrementals
--------------------------------------------------------------------

上面的操作会执行RMAN命令对xtt.properties文件中所指定的所有表空间生成增量备份文件。并且还将创建以下文件供后面的操作使用:
.tsbkupmap.txt
.incrbackups.txt

tsbkupmap.txt的内容如下:

[oracle@jytest3 xtts_script]$ cat tsbkupmap.txt
JY::5:::1=2esciru5_1_1

文件中的内容记录了表空间与增量备份的关联关系

incrbackups.txt的内容如下:

[oracle@jytest3 xtts_script]$ cat incrbackups.txt
/ora_xtts/backupformat/2esciru5_1_1

文件中的内容显示了生成的增量备份文件信息

[oracle@jytest3 backupformat]$ ls -lrt
total 112
-rw-r-----. 1 oracle asmadmin 57344 Aug 22 21:19 2dscipng_1_1
-rw-r-----. 1 oracle asmadmin 57344 Aug 22 21:57 2esciru5_1_1

将增量备份传输到目标系统中
将上一步生成的增量备份传输到目标系统中由xtt.properties文件中的stageondest目录(/oracle11/xtts)中。

[oracle@jytest3 xtts_script]$ scp `cat incrbackups.txt` oracle@10.138.130.171:/tts/xtts/
oracle@10.138.130.171's password:
2dscipng_1_1
                                                                                                                                                                               100%   56KB  56.0KB/s   00:00

在目标系统中转换增量备份并应用到数据文件副本
在目标系统中以Oracle软件用户登录并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向目标数据库,并从源系统中将上一步生成的xttplan.txt与tsbkupmap.txt文件。

[oracle@jytest3 xtts_script]$ scp `cat incrbackups.txt` oracle@10.138.130.171:/tts/xtts/
oracle@10.138.130.171's password:
2esciru5_1_1                                                                                                                                                                                              100%   56KB  56.0KB/s   00:00
[oracle@jytest3 xtts_script]$ scp /ora_xtts/xtts_script/xttplan.txt oracle@10.138.130.171:/tts/xtts_script
oracle@10.138.130.171's password:
xttplan.txt                                                                                                                                                                                               100%   19     0.0KB/s   00:00
[oracle@jytest3 xtts_script]$ scp /ora_xtts/xtts_script/tsbkupmap.txt oracle@10.138.130.171:/tts/xtts_script
oracle@10.138.130.171's password:
tsbkupmap.txt                                                                                                                                                                                             100%   23     0.0KB/s   00:00
[oracle@jytest3 xtts_script]$ scp /ora_xtts/xtts_script/incrbackups.txt oracle@10.138.130.171:/tts/xtts_script
oracle@10.138.130.171's password:
incrbackups.txt                                                                                                                                                                                           100%   36     0.0KB/s   00:00

[oracle@jytest1 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -r
============================================================
trace file is /tts/xtts_script/rollforward_Aug22_Tue_18_38_06_743//Aug22_Tue_18_38_06_743_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------

Key: cnvinst_home
Values: /u01/app/oracle/product/12.2.0/db
Key: dstdir
Values: DESTDIR
Key: stageondest
Values: /tts/xtts
Key: platformid
Values: 13
Key: parallel
Values: 4
Key: backupformat
Values: /ora_xtts/backupformat
Key: asm_home
Values: /u01/app/product/12.2.0/crs
Key: cnvinst_sid
Values: xtt
Key: srclink
Values: ttslink
Key: srcdir
Values: SOURCEDIR
Key: asm_sid
Values: +ASM1
Key: tablespaces
Values: JY
Key: backupondest
Values: /tts/backup

--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------

ARGUMENT tablespaces
ARGUMENT platformid
ARGUMENT backupformat
ARGUMENT stageondest
ARGUMENT backupondest

--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

ORACLE_SID  : jy1
ORACLE_HOME : /u01/app/oracle/product/12.2.0/db

--------------------------------------------------------------------
Start rollforward
--------------------------------------------------------------------

convert instance: /u01/app/oracle/product/12.2.0/db

convert instance: xtt

ORACLE instance started.

Total System Global Area 6442450944 bytes
Fixed Size                  8807168 bytes
Variable Size            3892317440 bytes
Database Buffers         1459617792 bytes
Redo Buffers                7966720 bytes
In-Memory Area           1073741824 bytes
rdfno 5

BEFORE ROLLPLAN

datafile number : 5

datafile name   : +DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/jy_371_952394755

AFTER ROLLPLAN

CONVERTED BACKUP PIECE/tts/backup/xib_2esciru5_1_1_5

PL/SQL procedure successfully completed.
Entering RollForward
After applySetDataFile
Done: applyDataFileTo
Done: applyDataFileTo
Done: RestoreSetPiece
Done: RestoreBackupPiece

PL/SQL procedure successfully completed.
asmcmd rm /tts/backup/xib_2esciru5_1_1_5  /u01/app/product/12.2.0/crs .. +ASM1

Connected to an idle instance.
ASMCMD-8102: no connection to Oracle ASM; command requires Oracle ASM to run
ASMCMD:


--------------------------------------------------------------------
End of rollforward phase
--------------------------------------------------------------------

4.3 在目标数据库中导入元数据
在目标系统中以Oracle软件用户登录并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向目标数据库,执行以下命令来生成Data Pump TTS命令:

[oracle@jytest1 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -e
============================================================
trace file is /tts/xtts_script/generate_Aug22_Tue_18_39_22_670//Aug22_Tue_18_39_22_670_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------

Key: cnvinst_home
Values: /u01/app/oracle/product/12.2.0/db
Key: cnvinst_sid
Values: xtt
Key: asm_sid
Values: +ASM1
Key: dstdir
Values: DESTDIR
Key: platformid
Values: 13
Key: backupondest
Values: /tts/backup
Key: parallel
Values: 4
Key: stageondest
Values: /tts/xtts
Key: tablespaces
Values: JY
Key: srclink
Values: ttslink
Key: srcdir
Values: SOURCEDIR
Key: backupformat
Values: /ora_xtts/backupformat
Key: asm_home
Values: /u01/app/product/12.2.0/crs

--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------

ARGUMENT tablespaces
ARGUMENT platformid
ARGUMENT backupformat
ARGUMENT stageondest

--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

ORACLE_SID  : jy1
ORACLE_HOME : /u01/app/oracle/product/12.2.0/db

--------------------------------------------------------------------
Generating plugin
--------------------------------------------------------------------


--------------------------------------------------------------------
Done generating plugin file /tts/xtts_script/xttplugin.txt
--------------------------------------------------------------------

[oracle@jytest1 xtts_script]$ cat xttplugin.txt
impdp directory= logfile= \
network_link= transport_full_check=no \
transport_tablespaces=JY \
transport_datafiles='+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/jy_371_952394755'

上面的命令会生成一个名叫xttplugin.txt的文件,文件创建了一个使用network_link参数执行传输表空间导入元数据的命令。命令中的transport_tablespaces与transport_datafiles参数已经设置正确。注意network_link模式指示导入通过使用dblink来完成,就不需要执行导出或使用dump文件。如果选择执行这个命令来完成表空间的传输就需要修改directory,logfile与network_link参数

SQL> create directory dump_dir as '/tts/xtts_script';

Directory created.
SQL> grant read,write on directory dump_dir to public;

Grant succeeded.


在目标数据库中创建用户方案jy

SQL> create user jy identified by "jy";

User created.

SQL> grant dba,connect,resource to jy;

Grant succeeded.

[oracle@jytest1 xtts_script]$ impdp  system/abcd@jypdb directory=dump_dir logfile=tts_imp.log network_link=ttslink transport_full_check=no transport_tablespaces=JY transport_datafiles='+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/jy_371_952394755'

Import: Release 12.2.0.1.0 - Production on Tue Aug 22 18:45:00 2017

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

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Starting "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_03":  system/********@jypdb directory=dump_dir logfile=tts_imp.log network_link=ttslink transport_full_check=no transport_tablespaces=JY transport_datafiles=+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/jy_371_952394755
Source time zone is +08:00 and target time zone is +00:00.
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/TABLE_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/STATISTICS/MARKER
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Job "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_03" successfully completed at Tue Aug 22 18:46:20 2017 elapsed 0 00:01:11


[oracle@jytest1 xtts_script]$ impdp system/abcd@jypdb directory=dump_dir logfile=ysj.log  content=metadata_only exclude=table,index network_link=ttslink

Import: Release 12.2.0.1.0 - Production on Tue Aug 22 18:47:22 2017

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

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01":  system/********@jypdb directory=dump_dir logfile=ysj.log content=metadata_only exclude=table,index network_link=ttslink
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully completed at Tue Aug 22 18:47:49 2017 elapsed 0 00:00:21

5.验证传输数据
5.1检查表空间是否有损坏

[oracle@jytest1 xtts_script]$ rman target sys/abcd@jypdb

Recovery Manager: Release 12.2.0.1.0 - Production on Sat Aug 19 01:17:35 2017

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

connected to target database: JY:JYPDB (DBID=2825277312)

RMAN> validate tablespace jy check logical;

Starting validate at 19-AUG-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1144 instance=jy1 device type=DISK
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00083 name=+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/jy_5.dbf
channel ORA_DISK_1: validation complete, elapsed time: 00:00:07
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
83   OK     0              1            64001           1590987
  File Name: +DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/jy_5.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              5
  Index      0              0
  Other      0              63994

Finished validate at 19-AUG-17

5.2将目标数据库中的表空间JY修改为read write状态

SQL> alter tablespace jy read write;

Tablespace altered.

6.清除操作
如果使用单独的转换home与实例,那么可以关闭转换实例并删除转换home。还可以删除源系统中创建的backupformat目录,目标系统中创建的bacup目录,源系统与目标系统中设置的环境变量$TMPDIR。

xttdriver.pl脚本选项
–backup:对源数据库中要被传输的表空间创建level 0级备份。这些备份将被写到xtt.properties文件中backupoformat参数所指定的目录中。这些备份需要手动复制到目标系统中stageondest参数所指定的目录中。而且还会生成tsbkupmap.txt与xttnewdatafiles.txt文件并且也需要复制到目标系统中相应目录(TMPDIR变量所指向的目录)

–restore:在目标系统中还原并转换stageondest目录中的数据文件备份的副本。还原的文件将会存储到storageondest参数所指定的目录中

–bkpincr:在源系统中对表空间创建增量备份并存储在backupformat参数所指定的目录中。这步操作还会创建incrbackups.txt文件它列出了所创建的备份。这个文件与tsbkupmap.txt必须复制到目标系统中的stageondest参数所指定的目录中

-recover:将增量备份应用到已经还原的数据文件上

-s:对源数据库判断新的from_scn可以执行一次或多次。这个操作将会计算下一个from_scn,并记录在xttplan.txt文件中,然后使用创建增量备份时会使用。

-bkpexport:将执行最后一次增量备份并且会创建元数据的dump文件用来导入数据文件。增量备份将会存储在backupformat参数所指定的目录中并且会创建incrbckups.txt与tsbkupmaps.txt文件,这些都要复制到目标系统中

–resincrdmp:将恢复最后一次增量备份并应用到数据文件。同时dump文件会被还原到TMPDIR变量所指定的目录中,dump文件可以用来导入

-e:在目标系统中生成传输表空间要导入的元数据脚本

-d debug:为了以debug模式来执行xttdriver.pl 与RMAN脚本。也可以设置环境变量XTTDEBUG=1,debug级别可以为1,2,3,例如xttdriver.pl -3

xtt.properties文件参数说明
tablespaces:用逗号来分隔从源数据库要被传输到目标数据库的表空间列表,例如tablespaces=TS1,TS2

platformid:从v$database.platform_id获得的源数据库的platform id,例如platformid=13

backupformat:源系统中存储备份文件的目录。这个目录必须要有足够的空间来存储所有创建的备份与增量备份文件。这个目录可以是目标系统上通过NFS-mounted文件系统所挂载到源系统中的一个目录,在这种情况下,目标系统中的stageondest参数也引用这个相同的NFS目录。例如,backupformat=/stage_source

stageondest:目标系统中存储从源系统中手动传输过来的数据文件副本。这个目录要有足够的空间来存储数据文件副本。这个目录同时也是用来存储从源系统传输过来的增量备份文件的目录。在目标系统上执行xttdriver.pl -c转换数据文件与执行xttdriver.pl -r前滚数据文件时会从这个目录中读取数据文件副本与增量备份文件。这个目标也可以是一个DBFS-mounted文件系统。个目录可以是源系统上通过NFS-mounted文件系统所挂载到目标系统中的一个目录,在这种情况下,源系统中的backupformat参数与dfcopydir参数就会引用这个相同的NFS目录。可以参考See Note 359515.1 for mount option guidelines。例如stageondest=/stage_dest

storageondest:目标系统中用来存储xttdriver.pl -c转换操作后所生成的数据文件副本的目录,也就是目标数据库最终存储数据文件的目录。这个目录要有足够的空间来永久存储数据文件。这个参数当使用RMAN备份来生成初始化数据文件副本时才使用,例如
storageondest=+DATA或者storageondest=/oradata/test

asm_home:目标系统中ASM实例的ORACLE_HOME。注意如果backupondest设置为文件系统目录,那么就要删除asm_home与asm_sid参数,例如asm_home=/u01/app/11.2.0.4/grid

asm_sid:目标系统中ASM实例的ORACLE_SID。例如asm_sid=+ASM1

parallel:定义rmanconvert.cmd命令文件中rman convert命令的并行度。如果不设置这个参数,那么xttdriver.pl将使用parallel=8的缺省并行度。例如,parallel=3

Oracle 12C xtts and rman

这篇文章将介绍在12c及更高的版本中,为了在不同字节序的系统之间迁移数据使用跨平台增量备份传输表空间迁移数据将会使用最少的停机时间。

使用跨平台增量备份传输表空间迁移数据的第一步就是在源系统中对源数据库生成一个完全备份副本。然后,使用一系列的增量备份,每一次增量备份都会比上一次的小,在停机之前,目标数据库中的数据已经非常接近源数据库中的数据。只有最后一次增量备份与导出\导入元数据才需要源数据库停机。

跨平台增量备份功能不会影响XTTS的其它操作所花费的时间,比如元数据导出\导入的时间。因此,数据库有大量元数据(DDL语句)时,像Oracle E-Business Suite与其它的包应用程序,它们将是影响跨平台增量备份传输表空间迁移数据效率的关键,因为这种迁移最终停机时间由于导出\导入元数据操作所决定的,而不是由传输数据文件与转换数据文件而决定的。

只有物理存储在被传输表空间中的数据库对象会被复制到目标系统中。如果需要传输存储在不同表空间中的(比如,pl/sql对象,序列等,存储在system表空间中的对象)其它对象,可以data pump将这些对象复制到目标系统中。

跨平台增量备份传输表空间的主要操作如下:
1.初始化阶段
2.准备阶段(源数据处于online状态)
2.1对被传输的表空间生成(level=0)的备份
2.2传输备份文件与其它需要的配置文件到目标系统中
2.3将数据文件还原到目标系统,并且转换为目标系统所使用的字节序

3.前滚阶段(源数据处于online状态,为了使用目标数据文件的内容接近源数据库的内容可以执行多次前滚操作)
3.1在源系统中创建增量备份
3.2将增量备份文件与其它的配置文件传输到目标系统中
3.3在目标系统中将增量备份文件转换为目标系统所使用的字节序并应用到数据文件副本
3.4在源系统中执行操作来决定下一次增量备份的开始scn(from_scn)
3.5重复该阶段操作直到准备执行传输阶段的操作为止

注意,在版本3的转换脚本中,如果向被传输的表空间增加数据文件,或者向xtt.properties文件中的tablespaces参数增加新的表空间名,将会要执行额外的指令。

4.传输阶段
4.1将源数据库中要被传输的表空间设置为read only状态
4.2执行最后一次前滚操操作,这步操作将使用目标数据库中的数据文件的内容与源数据库中数据文件的内容保持一致。当处理大量数据时,
这步操作所花费的时间要比传统的XTTS方法所用的时间更短,因为增量备份的大小更小。
4.3使用data pump将被传输的表空间所存的对象的元数据导入到目标数据库中
4.4将目标数据库中被传输过来的表空间设置为read write状态

这篇文章提供了一个例子来介绍如何使用跨平台增量备份来减少传输表空间的停机时间。

源系统可以是先决条件所引用的和平台与数据库所满足的列表中所列出任何平台。如果从一种小字节序平台迁移到Oracle Linux,那么最应该考虑的方法是使用Data Guard,可以参考Note 413484.1关于在当前小字节序平台与Oracle Linux之间Data Guard所支持的异构平台。

这里将介绍如何从Aix平台上将表空间cdzj,ldjc使用跨平台增量备份的传输表空间方法来迁移到Oracle Linux平台。在执行完初始化阶段后执行以下三个阶段来执行数据的迁移操作:
准备阶段
在准备阶段,在源系统上会对要被传输的表空间的数据文件生成level=0的备份。备份文件会被传输到目标系统中,然后将数据文件还原并转换后目标系统所使用的字节序。

前滚阶段
在前滚阶段,在准备阶段被转换后的数据文件将会使用来自源数据库的增量备份来进行前滚操作。通过多次执行该阶段的操作,每次成功的增量备份将会更小与更快的应用到数据文件副本,允许目标系统中的数据都是来自源系统中。在执行前滚阶段时应用程序可以完全访问源数据。

传输阶段
在传输阶段,在源数据库中将要被传输的表空间设置为read only状态,并且在源平台上执行最后一次增量备份并且将它传输到目标平台上并应用到数据文件副本,使用目标系统中的数据文件副本与源数据库中的数据文件保护一致。一旦数据文件状态一致,从源数据库中导出所传输表空间所存储对象的元数据,并且在目标平台导入这些元数据。最后在目标数据库中将传输过来的表空间设置为read write状态。在传输阶段应用程序是不能更新源数据的。

跨平台增量备份所支持的脚本
跨平台增量备份的核心功能是基于Oracle 11.2.0.4与之后的版本。这时所介绍的操作只能用于Oracle 12c,12.1及之后的版本,请查看条件与建议部分了解详细信息。。另外有一组支持脚本存储在rman-xttconvert_2.0.zip。其中有两个主要支持的脚本:
.Perl脚本xttdriver.pl 这个脚本用来执行跨平台增量备份传输表空间的主要步骤。
.参数文件xtt.properties 这个文件包含自已平台特定配置

执行跨平台增量备份传输表空间的条件与建议
执行跨平台增量备份传输表空间的条件
在执行跨平台增量备份传输表空间之前需要检查是否满足以下条件:
.传输表空间的限制
.其它必须满足的条件
当前版本不支持windows
源数据库的compatible参数必须设置为12.1.0或更高版本
源数据库的compatible参数必须不能比目标数据库的compatible参数的值大
源数据库必须启用了archivelog模式
源数据库的RMAN不能对DEVICE TYPE DISK使用COMPRESSED配置
目标数据库的compatible参数必须设置为12.1.0或更高版本
源数据库中将要被迁移的表空间必须是online,并且不能包含脱机数据文件。表空间必须为read write状态。表空间为read only那么可以使用正常的XTTS方法进行迁移。
尽管首选目标系统是Linux操作系统(可以是64位的Oracle Linux或者是已经认证的Redhat Linux),但这个过程也可以在其它Unix操作系统中执行。然而,对于任何non-Linux操作系统来说数据库的版本必须是12.1.0.1或更高的版本。
源数据库的版本必须小于或等于目标数据库的版本

.所有步骤中执行操作的用户必须是Oracle用户并且它是OSDBA组的成员。操作系统审计被用来连接源数据库与目标数据库。
.对于备库或快照备库是不支持这种操作的
.这种方法不支持多租户数据库。增强bug 22570430解决了这个限制。

诊断
为了启用诊断模式,可以使用-d参数来执行xttdriver.pl脚本,或者在执行xttdriver.pl脚本之前设置环境变量XTTDEBUG=1。Debug模式会启用额外的屏幕输出并且造成所有RMAN操作使用debug命令行选项。

已知问题
1.如果前滚阶段(xttdriver.pl -r)失败并显示以下错误信息,那么验证RMAN的DEVICE TYPE DISK不能使用COMPRESSED配置

Entering RollForward
After applySetDataFile
Done: applyDataFileTo
Done: RestoreSetPiece
DECLARE
*
ERROR at line 1:
ORA-19624: operation failed, retry possible
ORA-19870: error while restoring backup piece
/dbfs_direct/FS1/xtts/incrementals/xtts_incr_backup
ORA-19608: /dbfs_direct/FS1/xtts/incrementals/xtts_incr_backup is not a backup
piece
ORA-19837: invalid blocksize 0 in backup piece header
ORA-06512: at "SYS.X$DBMS_BACKUP_RESTORE", line 2338
ORA-06512: at line 40

使用跨平台增量备份来减少传输表空间的时间
使用跨平台增量备份来传输表空间主要有以下几个阶段:
1.初始化设置阶段
2.准备阶段
3.前滚阶段
4.最后的增量备份阶段
5.传输阶段导入元数据
6.验证传输的数据
7.清除操作

1.初始化设置阶段
1.1安装目标数据库软件并创建目标数据库
在目标系统上安装目标Oracle数据库软件,版本应该为Oracle12c,操作系统是Linux,我这里都是12.2.0.1。在源数据库中创建了一个要被传输到目标数据库的表空间jy,用户方案jy,源数据库版本也是12.2.0.1,操作系统是Linux。

1.2识别要被传输的表空间
源数据库中要被传输的表空间为jy,用户方案jy。

1.3在源系统上安装xttconvert脚本

[oracle@jytest3 xtts_script]$ unzip rman_xttconvert_v3.zip
Archive:  rman_xttconvert_v3.zip
  inflating: xtt.properties
  inflating: xttcnvrtbkupdest.sql
  inflating: xttdbopen.sql
  inflating: xttdriver.pl
  inflating: xttprep.tmpl
 extracting: xttstartupnomount.sql

1.4 创建需要使用的目录
在源系统中创建目录/ora_xtts/backupformat用来存储源系统中对源数据库生成的备份及增量备份文件,xtt.properties文件中的backupformat参数设置该目录。

[oracle@jytest3 ora_xtts]$ mkdir backupformat

在目标系统中创建目录/tts/backup用来存储手动从源系统中传输过来的备份及增量备份文件,xtt.properties文件中的stageondest参数设置该目录。

[oracle@jytest1 tts]$ mkdir backup

xtt.properties文件中的storageondest参数设置目标数据库最终存储数据文件的目录,这里是+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/目录。

1.5在源系统中配置xtt.properties文件

SQL> select platform_id from v$database;

PLATFORM_ID
-----------
         13


[oracle@jytest3 xtts_script]$ vi xtt.properties
tablespaces=JY
platformid=13
storageondest=+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/
backupformat=/ora_xtts/backupformat
stageondest=/tts/backup
asm_home=/u01/app/product/12.2.0/crs
asm_sid=+ASM1
parallel=4

1.6将源系统中的xttconvert脚本与xtt.properties文件复制到目标系统中
在源系统中以Oracle软件用户来进行复制

[oracle@jytest1 tts]$ scp -r oracle@10.138.130.173:/ora_xtts/xtts_script/ /tts/
The authenticity of host '10.138.130.173 (10.138.130.173)' can't be established.
ECDSA key fingerprint is 67:29:52:b1:c0:74:ff:33:fc:67:63:53:31:14:69:ec.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.138.130.173' (ECDSA) to the list of known hosts.
oracle@10.138.130.173's password:
rman_xttconvert_v3.zip                                                                                                                                                                                    100%   33KB  33.2KB/s   00:00
xttcnvrtbkupdest.sql                                                                                                                                                                                      100% 1390     1.4KB/s   00:00
xttdbopen.sql                                                                                                                                                                                             100%   71     0.1KB/s   00:00
xttdriver.pl                                                                                                                                                                                              100%  136KB 136.1KB/s   00:00
xttprep.tmpl                                                                                                                                                                                              100%   11KB  11.4KB/s   00:00
xttstartupnomount.sql                                                                                                                                                                                     100%   52     0.1KB/s   00:00
xtt.properties.jy                                                                                                                                                                                         100% 7969     7.8KB/s   00:00
xtt.properties                                                                                                                                                                                            100%  217     0.2KB/s   00:00

[oracle@jytest1 tts]$ cd xtts_script
[oracle@jytest1 xtts_script]$ ls -lrt
total 212
-rw-r--r-- 1 oracle oinstall  33949 Aug 18 23:35 rman_xttconvert_v3.zip
-rw-r--r-- 1 oracle oinstall   1390 Aug 18 23:35 xttcnvrtbkupdest.sql
-rw-r--r-- 1 oracle oinstall     71 Aug 18 23:35 xttdbopen.sql
-rw-r--r-- 1 oracle oinstall 139331 Aug 18 23:35 xttdriver.pl
-rw-r--r-- 1 oracle oinstall  11710 Aug 18 23:35 xttprep.tmpl
-rw-r--r-- 1 oracle oinstall     52 Aug 18 23:35 xttstartupnomount.sql
-rw-r--r-- 1 oracle oinstall   7969 Aug 18 23:35 xtt.properties.jy
-rw-r--r-- 1 oracle oinstall    217 Aug 18 23:35 xtt.properties

1.7设置环境变量TMPDIR
在源系统与目标系统中设置环境变量TMPDIR。使用shell来执行Perl脚本xttdriver.pl所生成的文件会存储在$TMPDIR目录中,如果没有设置
TMPDIR环境变量,那么生成的文件会存储在/tmp目录中。

源系统

[oracle@jytest3 ora_xtts]$ export TMPDIR=/ora_xtts/xtts_script

目标系统

[oracle@jytest1 tts]$ export TMPDIR=/tts/xtts_script

2.准备阶段
在准备阶段,要被传输的表空间会在源系统中生成备份,然后将备份传输到目标系统中,并通过执行xttdriver.pl脚本将备份还原。注意,对于要传输大量数据文件,可以使用dbms_file_transfer进行传输(可以参考文档 1389592.1中的准备阶段)会要比手动传输备份文件到目标系统中快很多。这种方法也适用于Oracle 12c,11G – Reduce Transportable Tablespace Downtime using Cross Platform Incremental Backup (Doc ID 1389592.1).

2.1在源系统中对要传输的表空间生成备份
在源系统中,以oracle软件用户登录,并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向源数据库,执行以下命令来生成备份

[oracle@jytest3 xtts_script]$ export ORACLE_HOME=/u01/app/oracle/product/12.2.0/db
[oracle@jytest3 xtts_script]$ export ORACLE_SID=orcl

[oracle@jytest3 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl --backup
============================================================
trace file is /ora_xtts/xtts_script/backup_Aug19_Sat_03_17_33_312//Aug19_Sat_03_17_33_312_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Starting prepare phase
--------------------------------------------------------------------

Prepare source for Tablespaces:
                  'JY'  /tts/backup
xttpreparesrc.sql for 'JY' started at Sat Aug 19 03:17:33 2017
xttpreparesrc.sql for  ended at Sat Aug 19 03:17:34 2017
Prepare source for Tablespaces:
                  ''''  /tts/backup
xttpreparesrc.sql for '''' started at Sat Aug 19 03:17:40 2017
xttpreparesrc.sql for  ended at Sat Aug 19 03:17:40 2017

--------------------------------------------------------------------
Done with prepare phase
--------------------------------------------------------------------


--------------------------------------------------------------------
Find list of datafiles in system
--------------------------------------------------------------------


--------------------------------------------------------------------
Done finding list of datafiles in system
--------------------------------------------------------------------

[oracle@jytest3 backupformat]$ ls -lrt
total 1072
-rw-r-----. 1 oracle asmadmin 1097728 Aug 19 03:17 JY_5_25sc8t6j_1_1.bkp

[oracle@jytest3 xtts_script]$ cat xttplan.txt
JY::::1586999
5
[oracle@jytest3 xtts_script]$ cat tsbkupmap.txt
::5:::1=JY_5_25sc8t6j_1_1.bkp
[oracle@jytest3 xtts_script]$ cat xttnewdatafiles.txt
::JY
5,+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile//JY_5.dbf

2.2将备份文件传输到目标系统
将上一步生成的备份文件从源系统中的backupformat目录(/ora_xtts/backupformat)传输到目标系统中的stageondest目录(/tts/backup)

[oracle@jytest3 backupformat]$ scp /ora_xtts/backupformat/* oracle@10.138.130.171:/tts/backup/
The authenticity of host '10.138.130.171 (10.138.130.171)' can't be established.
ECDSA key fingerprint is 7a:62:58:8b:77:98:52:94:d6:d5:0c:c4:6c:87:a6:7f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.138.130.171' (ECDSA) to the list of known hosts.
oracle@10.138.130.171's password:
JY_5_25sc8t6j_1_1.bkp                                                                                                                                                                                     100% 1072KB   1.1MB/s   00:00

[oracle@jytest1 backup]$ ls -lrt
total 1072
-rw-r----- 1 oracle oinstall 1097728 Aug 18 23:58 JY_5_25sc8t6j_1_1.bkp

将上一步生成的tsbkupmap.txt与xttnewdatafiles.txt文件传到目标系统中的$TMPDIR目录(/tts/xtts_script)

[oracle@jytest3 xtts_script]$ scp /ora_xtts/xtts_script/tsbkupmap.txt oracle@10.138.130.171:/tts/xtts_script
oracle@10.138.130.171's password:
tsbkupmap.txt                                                                                                                                                                                             100%   30     0.0KB/s   00:00
[oracle@jytest3 xtts_script]$ scp /ora_xtts/xtts_script/xttnewdatafiles.txt oracle@10.138.130.171:/tts/xtts_script
oracle@10.138.130.171's password:
xttnewdatafiles.txt                                                                                                                                                                                       100%   68     0.1KB/s   00:00


[oracle@jytest1 xtts_script]$ ls -lrt
total 220
-rw-r--r-- 1 oracle oinstall  33949 Aug 18 23:35 rman_xttconvert_v3.zip
-rw-r--r-- 1 oracle oinstall   1390 Aug 18 23:35 xttcnvrtbkupdest.sql
-rw-r--r-- 1 oracle oinstall     71 Aug 18 23:35 xttdbopen.sql
-rw-r--r-- 1 oracle oinstall 139331 Aug 18 23:35 xttdriver.pl
-rw-r--r-- 1 oracle oinstall  11710 Aug 18 23:35 xttprep.tmpl
-rw-r--r-- 1 oracle oinstall     52 Aug 18 23:35 xttstartupnomount.sql
-rw-r--r-- 1 oracle oinstall   7969 Aug 18 23:35 xtt.properties.jy
-rw-r--r-- 1 oracle oinstall    217 Aug 18 23:35 xtt.properties
-rw-r--r-- 1 oracle oinstall     30 Aug 19 00:02 tsbkupmap.txt
-rw-r--r-- 1 oracle oinstall     68 Aug 19 00:03 xttnewdatafiles.txt

2.3在目标系统中还原数据文件
在目标系统中,以Oracle软件用户登录并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向目标数据库,执行以下还原操作:

[oracle@jytest1 xtts_script]$ export ORACLE_HOME=/u01/app/oracle/product/12.2.0/db
[oracle@jytest1 xtts_script]$ export ORACLE_SID=jy1

[oracle@jytest1 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl --restore
============================================================
trace file is /tts/xtts_script/restore_Aug19_Sat_00_06_38_642//Aug19_Sat_00_06_38_642_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Start restore/recover
--------------------------------------------------------------------


--------------------------------------------------------------------
End of restore/recover phase
--------------------------------------------------------------------

数据文件将会存储到storageondest参数所指定目录中

ASMCMD [+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile] > ls -lt
Type      Redund  Striped  Time             Sys  Name
DATAFILE  UNPROT  COARSE   AUG 19 00:00:00  N    jy_5.dbf => +DATA/jy/4D98CBB596437310E053AD828A0A6B56/DATAFILE/JY.317.952387605

3.前滚阶段
在这个阶段会在源系统中对源数据库创建增量备份,将增量备份文件传输到目标系统并转换为目标系统所使用的字节序,然后将转换后的增量备份应用到数据文件。这个阶段的操作可以执行多次。每一次成功的增量备份所花的时间要比上一次的少,这将使用目标数据库中的数据文件的内容更接近源数据库的内容。在执行这个阶段操作时被传输的数据完全可以被访问。

3.1在源系统中创建增量备份
在源系统中,以oracle软件用户登录,并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向源数据库,执行以下命令来生成增量备份

[oracle@jytest3 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl --bkpinc
============================================================
trace file is /ora_xtts/xtts_script/bkpincr_Aug19_Sat_03_37_38_757//Aug19_Sat_03_37_38_757_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Backup incremental
--------------------------------------------------------------------

Prepare newscn for Tablespaces: 'JY'
Prepare newscn for Tablespaces: ''''

--------------------------------------------------------------------
Starting incremental backup
--------------------------------------------------------------------


--------------------------------------------------------------------
Done backing up incrementals
--------------------------------------------------------------------

上面的操作将会创建增量备份文件,并会创建以下文件

xttplan.txt
tsbkupmap.txt
incrbackups.txt

[oracle@jytest3 xtts_script]$ cat tsbkupmap.txt
JY::5:::1=26sc8uc7_1_1
[oracle@jytest3 xtts_script]$ cat xttplan.txt
JY::::1586999
5
[oracle@jytest3 xtts_script]$ cat incrbackups.txt
/ora_xtts/backupformat/26sc8uc7_1_1

3.2将增量备份文件传输到目标系统中

[oracle@jytest3 xtts_script]$  scp `cat incrbackups.txt` oracle@10.138.130.171:/tts/backup/
oracle@10.138.130.171's password:
26sc8uc7_1_1                                                                                                                                                                                              100%   48KB  48.0KB/s   00:00
[oracle@jytest3 xtts_script]$ scp /ora_xtts/xtts_script/xttplan.txt oracle@10.138.130.171:/tts/xtts_script
oracle@10.138.130.171's password:
xttplan.txt                                                                                                                                                                                               100%   16     0.0KB/s   00:00
[oracle@jytest3 xtts_script]$ scp /ora_xtts/xtts_script/tsbkupmap.txt oracle@10.138.130.171:/tts/xtts_script
oracle@10.138.130.171's password:
tsbkupmap.txt                                                                                                                                                                                             100%   23     0.0KB/s   00:00
[oracle@jytest3 xtts_script]$ scp /ora_xtts/xtts_script/incrbackups.txt oracle@10.138.130.171:/tts/xtts_script
oracle@10.138.130.171's password:
incrbackups.txt                                                                                                                                                                                           100%   36     0.0KB/s   00:00


[oracle@jytest1 backup]$ ls -lrt
total 1120
-rw-r----- 1 oracle oinstall 1097728 Aug 18 23:58 JY_5_25sc8t6j_1_1.bkp
-rw-r----- 1 oracle oinstall   49152 Aug 19 00:18 26sc8uc7_1_1

[oracle@jytest1 xtts_script]$ cat xttplan.txt
JY::::1586999
5
[oracle@jytest1 xtts_script]$ cat tsbkupmap.txt
JY::5:::1=26sc8uc7_1_1
[oracle@jytest1 xtts_script]$ cat incrbackups.txt
/ora_xtts/backupformat/26sc8uc7_1_1

如果源系统中的backupformat目录是目标系统中stageondest目录通过NFS挂载到源系统中的话,那么就不需要复制这些备份文件目标系统就可以使用。然而,(xttplan.txt,tsbkupmap.txt,incrbackups.txt)文件在每次增量备份后都需要传输到目标系统中。

3.3在目标系统将增量备份应用到数据文件
在目标系统中,以Oracle软件用户登录并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向目标数据库,执行以下命令来执行前滚操作:

[oracle@jytest1 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl --recover
============================================================
trace file is /tts/xtts_script/recover_Aug19_Sat_00_25_22_517//Aug19_Sat_00_25_22_517_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Start restore/recover
--------------------------------------------------------------------


--------------------------------------------------------------------
End of restore/recover phase
--------------------------------------------------------------------

3.4生成下一次增量备份需要的from_scn
在源系统中,为了以后生成增量备份,以oracle软件用户登录,并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向源数据库,执行以下命令来生成新的from_scn:

[oracle@jytest3 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -s
============================================================
trace file is /ora_xtts/xtts_script/determinescn_Aug19_Sat_03_51_12_712//Aug19_Sat_03_51_12_712_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

Prepare newscn for Tablespaces: 'JY'
Prepare newscn for Tablespaces: ''''
New /ora_xtts/xtts_script/xttplan.txt with FROM SCN's generated

这步操作会计算新的from_scn,并将其记录到xttplan.txt文件,在下次生成增量备份时将会使用。

[oracle@jytest3 xtts_script]$ cat xttplan.txt
 JY::::1587737
 5

3.5 再次重复前滚阶段或执行传输阶段
这里有两种选择:
1.如果如果将目标数据库中的数据文件与源数据库中的数据文件进行最接近的同步,那么就重复执行前滚操作。
2.如果目标数据库中的数据文件与源数据库中的数据文件已经达到所期望的接近,那么执行传输阶段的操作。

注意:如果从上一次增量备份后增加了一个新的表空间或者一个新的表空间名增加到xtt.properties文件中,那么将会出现以下错误:

Error:
------
The incremental backup was not taken as a datafile has been added to the tablespace:

Please Do the following:
--------------------------
1. Copy fixnewdf.txt from source to destination temp dir

2. Copy backups:

from  to the  in destination

3. On Destination, run $ORACLE_HOME/perl/bin/perl xttdriver.pl --fixnewdf

4. Re-execute the incremental backup in source:
$ORACLE_HOME/perl/bin/perl xttdriver.pl --bkpincr

NOTE: Before running incremental backup, delete FAILED in source temp dir or
run xttdriver.pl with -L option:

$ORACLE_HOME/perl/bin/perl xttdriver.pl -L --bkpincr

These instructions must be followed exactly as listed. The next incremental backup will include the new datafile.

我这里再次执行前滚操作

SQL> select * from jy_test;

no rows selected

SQL> insert into jy_test values(1);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from jy_test;

   USER_ID
----------
         1

在源系统中创建增量备份
在源系统中,以oracle软件用户登录,并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向源数据库,执行以下命令来生成增量备份

[oracle@jytest3 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl --bkpinc
============================================================
trace file is /ora_xtts/xtts_script/bkpincr_Aug19_Sat_03_55_51_357//Aug19_Sat_03_55_51_357_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Backup incremental
--------------------------------------------------------------------

Prepare newscn for Tablespaces: 'JY'
Prepare newscn for Tablespaces: ''''

--------------------------------------------------------------------
Starting incremental backup
--------------------------------------------------------------------


--------------------------------------------------------------------
Done backing up incrementals
--------------------------------------------------------------------

上面的操作将会创建增量备份文件,并会创建以下文件
xttplan.txt
tsbkupmap.txt
incrbackups.txt

[oracle@jytest3 xtts_script]$ cat tsbkupmap.txt
JY::5:::1=27sc8vec_1_1
[oracle@jytest3 xtts_script]$ cat xttplan.txt
 JY::::1587737
 5
[oracle@jytest3 xtts_script]$ cat incrbackups.txt
/ora_xtts/backupformat/27sc8vec_1_1

3.2将增量备份文件传输到目标系统中

[oracle@jytest3 xtts_script]$ scp `cat incrbackups.txt` oracle@10.138.130.171:/tts/backup/
oracle@10.138.130.171's password:
27sc8vec_1_1                                                                                                                                                                                              100%  128KB 128.0KB/s   00:00
[oracle@jytest3 xtts_script]$ scp /ora_xtts/xtts_script/xttplan.txt oracle@10.138.130.171:/tts/xtts_script
oracle@10.138.130.171's password:
xttplan.txt                                                                                                                                                                                               100%   18     0.0KB/s   00:00
[oracle@jytest3 xtts_script]$ scp /ora_xtts/xtts_script/tsbkupmap.txt oracle@10.138.130.171:/tts/xtts_script
oracle@10.138.130.171's password:
tsbkupmap.txt                                                                                                                                                                                             100%   23     0.0KB/s   00:00
[oracle@jytest3 xtts_script]$ scp /ora_xtts/xtts_script/incrbackups.txt oracle@10.138.130.171:/tts/xtts_script
oracle@10.138.130.171's password:
incrbackups.txt                                                                                                                                                                                           100%   36     0.0KB/s   00:00


[oracle@jytest1 backup]$ ls -lrt
total 1248
-rw-r----- 1 oracle oinstall 1097728 Aug 18 23:58 JY_5_25sc8t6j_1_1.bkp
-rw-r----- 1 oracle oinstall   49152 Aug 19 00:18 26sc8uc7_1_1
-rw-r----- 1 oracle oinstall  131072 Aug 19 00:33 27sc8vec_1_1

[oracle@jytest1 xtts_script]$ cat xttplan.txt
 JY::::1587737
 5
[oracle@jytest1 xtts_script]$ cat tsbkupmap.txt
JY::5:::1=27sc8vec_1_1
[oracle@jytest1 xtts_script]$ cat incrbackups.txt
/ora_xtts/backupformat/27sc8vec_1_1

如果源系统中的backupformat目录是目标系统中stageondest目录通过NFS挂载到源系统中的话,那么就不需要复制这些备份文件目标系统就可以使用。然而,(xttplan.txt,tsbkupmap.txt,incrbackups.txt)文件在每次增量备份后都需要传输到目标系统中。

3.3在目标系统将增量备份应用到数据文件
在目标系统中,以Oracle软件用户登录并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向目标数据库,执行以下命令来执行前滚操作:

[oracle@jytest1 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl --recover
============================================================
trace file is /tts/xtts_script/recover_Aug19_Sat_00_35_56_534//Aug19_Sat_00_35_56_534_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Start restore/recover
--------------------------------------------------------------------


--------------------------------------------------------------------
End of restore/recover phase
--------------------------------------------------------------------

3.4生成下一次增量备份需要的from_scn
在源系统中,为了以后生成增量备份,以oracle软件用户登录,并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向源数据库,执行以下命令来生成新的from_scn:

[oracle@jytest3 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -s
============================================================
trace file is /ora_xtts/xtts_script/determinescn_Aug19_Sat_04_00_04_92//Aug19_Sat_04_00_04_92_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

Prepare newscn for Tablespaces: 'JY'
Prepare newscn for Tablespaces: ''''
New /ora_xtts/xtts_script/xttplan.txt with FROM SCN's generated

这步操作会计算新的from_scn,并将其记录到xttplan.txt文件,在下次生成增量备份时将会使用。

[oracle@jytest3 xtts_script]$ cat xttplan.txt
 JY::::1588547
 5

4.最后一次增量备份
在这个阶段,需要将源数据库中要被传输的表空间设置为read only状态,通过创建与应用最后一次增量备份使用目标数据文件与源数据库的内容达到一致状态。然后可以使用正常的传输表空间操作来从源数据库中导出元数据并导入目标数据库,直到这个阶段的操作完成之前源数据库中被传输的表空间会处于read only状态。

4.1 将源数据库中的表空间JY设置为read only状态
在源系统中,以oracle软件用户登录,并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向源数据库,执行以下操作:

SQL> insert into jy_test values(2);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from jy_test;

   USER_ID
----------
         1
         2

SQL> alter tablespace jy read only;

Tablespace altered.

4.2创建最后一次的增量备份并将相关文件传输到目标系统
在源系统中,以oracle软件用户登录,并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向源数据库,执行以下命令来生成最后的增量备份

[oracle@jytest3 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl --bkpexport
============================================================
trace file is /ora_xtts/xtts_script/bkpexport_Aug19_Sat_04_06_32_838//Aug19_Sat_04_06_32_838_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Backup incremental
--------------------------------------------------------------------

============================================================
No new datafiles added
=============================================================
Prepare newscn for Tablespaces: 'JY'
Prepare newscn for Tablespaces: ''''

--------------------------------------------------------------------
Starting incremental backup
--------------------------------------------------------------------


--------------------------------------------------------------------
Done backing up incrementals
--------------------------------------------------------------------

上面的操作将会创建增量备份文件,并会创建以下文件
xttplan.txt
tsbkupmap.txt
incrbackups.txt

[oracle@jytest3 xtts_script]$ cat xttplan.txt
 JY::::1588547
 5
[oracle@jytest3 xtts_script]$ cat tsbkupmap.txt
DMPEXP::29sc9068_1_1
::5:::1=28sc9066_1_1
[oracle@jytest3 xtts_script]$ cat incrbackups.txt
/ora_xtts/backupformat/29sc9068_1_1
/ora_xtts/backupformat/28sc9066_1_1

[oracle@jytest3 xtts_script]$ scp `cat incrbackups.txt` oracle@10.138.130.171:/tts/backup/
oracle@10.138.130.171's password:
29sc9068_1_1                                                                                                                                                                                              100%  192KB 192.0KB/s   00:00
28sc9066_1_1                                                                                                                                                                                              100%  128KB 128.0KB/s   00:00
[oracle@jytest3 xtts_script]$ scp /ora_xtts/xtts_script/xttplan.txt oracle@10.138.130.171:/tts/xtts_script
oracle@10.138.130.171's password:
xttplan.txt                                                                                                                                                                                               100%   18     0.0KB/s   00:00
[oracle@jytest3 xtts_script]$ scp /ora_xtts/xtts_script/tsbkupmap.txt oracle@10.138.130.171:/tts/xtts_script
oracle@10.138.130.171's password:
tsbkupmap.txt                                                                                                                                                                                             100%   42     0.0KB/s   00:00
[oracle@jytest3 xtts_script]$ scp /ora_xtts/xtts_script/incrbackups.txt oracle@10.138.130.171:/tts/xtts_script
oracle@10.138.130.171's password:
incrbackups.txt                                                                                                                                                                                           100%   73     0.1KB/s   00:00


[oracle@jytest1 backup]$ ls -lrt
total 1568
-rw-r----- 1 oracle oinstall 1097728 Aug 18 23:58 JY_5_25sc8t6j_1_1.bkp
-rw-r----- 1 oracle oinstall   49152 Aug 19 00:18 26sc8uc7_1_1
-rw-r----- 1 oracle oinstall  131072 Aug 19 00:33 27sc8vec_1_1
-rw-r----- 1 oracle oinstall  196608 Aug 19 00:47 29sc9068_1_1
-rw-r----- 1 oracle oinstall  131072 Aug 19 00:47 28sc9066_1_1

[oracle@jytest1 xtts_script]$ cat xttplan.txt
 JY::::1588547
 5
[oracle@jytest1 xtts_script]$ cat tsbkupmap.txt
DMPEXP::29sc9068_1_1
::5:::1=28sc9066_1_1
[oracle@jytest1 xtts_script]$ cat incrbackups.txt
/ora_xtts/backupformat/29sc9068_1_1
/ora_xtts/backupformat/28sc9066_1_1

4.3应用最后的增量备份
在目标系统中,以Oracle软件用户登录并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向目标数据库,执行以下命令来应用最后的增量备份

[oracle@jytest1 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl --resincrdmp
============================================================
trace file is /tts/xtts_script/resincrdmp_Aug19_Sat_00_49_56_533//Aug19_Sat_00_49_56_533_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Start restore/recover
--------------------------------------------------------------------


--------------------------------------------------------------------
End of restore/recover phase
--------------------------------------------------------------------


--------------------------------------------------------------------
Start creating dumpfile
--------------------------------------------------------------------


--------------------------------------------------------------------
End of creating dumpfile
--------------------------------------------------------------------


--------------------------------------------------------------------
Generating plugin
--------------------------------------------------------------------


--------------------------------------------------------------------
Done generating plugin file /tts/xtts_script/xttplugin.txt
--------------------------------------------------------------------

上面的操作将会对数据文件应用最后的增量备份。另外,还会还原阶段5A导入元数据所需要的dump文件与xttplugin.txt文件

[oracle@jytest1 xtts_script]$ cat xttplugin.txt
impdp directory= logfile= \
dumpfile=impdp_Aug19_Sat_00_49_56_533.dmp \
transport_datafiles='+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile//JY_5.dbf'
[oracle@jytest1 xtts_script]$ ls -lrt

-rw-r----- 1 oracle asmadmin 167936 Aug 19 00:50 impdp_Aug19_Sat_00_49_56_533.dmp
-rw-r--r-- 1 oracle oinstall    183 Aug 19 00:50 xttplugin.txt

5.传输阶段:将对象元数据导入目标数据库
在这个阶段表空间将会被附加到目标数据库中。这里有两种方法。第一种是使用步骤4.3所创建的dump文件来进行导入。第二种方法是通过连接两个数据库的dblink来进行导入。

5a 通过dump文件导入
5a.1 创建datapump目录并授权

SQL>create directory dpump_tts as '/tts/xtts_script';
SQL>GRANT READ, WRITE ON DIRECTORY dpump_tts TO system;

5a.2 修改导入命令并执行

[oracle@jytest1 xtts_script]$ impdp directory=pump_tts logfile=tts_imp.log
dumpfile=impdp_Aug19_Sat_00_49_56_533.dmp
transport_datafiles='+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile//JY_5.dbf'

5b使用dblink导入元数据
5b.1创建dblink
在目标系统中,以Oracle软件用户登录并设置环境变量(ORACLE_HOME与ORACLE_SID)来指向目标数据库,执行以下命令:

[oracle@jytest1 xtts_script]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -e
============================================================
trace file is /tts/xtts_script/generate_Aug19_Sat_00_58_39_839//Aug19_Sat_00_58_39_839_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Generating plugin
--------------------------------------------------------------------


--------------------------------------------------------------------
Done generating plugin file /tts/xtts_script/xttplugin.txt
--------------------------------------------------------------------

[oracle@jytest1 xtts_script]$ cat xttplugin.txt
impdp directory= logfile= \
network_link= transport_full_check=no \
transport_tablespaces=JY \
transport_datafiles='+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile//JY_5.dbf'

5b.2 在目标数据库中创建dblink

SQL> create public database link ttslink
  2    connect to system identified by "xxzx#7817600"
  3    using '(DESCRIPTION =
  4      (ADDRESS_LIST =
  5        (ADDRESS = (PROTOCOL = TCP)(HOST =10.138.130.173)(PORT = 1521))
  6      )
  7      (CONNECT_DATA =
  8        (SERVER = DEDICATED)
  9        (SERVICE_NAME =orcl)
 10      )
 11    )';

Database link created.

SQL> select name from v$database@ttslink;

NAME
---------
ORCL

5b.3修改导入脚本并执行脚本

SQL> create directory dpump_tts as '/tts/xtts_script';

Directory created.

SQL> GRANT READ, WRITE ON DIRECTORY dpump_tts TO public;

Grant succeeded.


[oracle@jytest1 xtts_script]$ impdp system/abcd@jypdb directory=dpump_tts logfile=tts_imp.log network_link=ttslink transport_full_check=no transport_tablespaces=JY transport_datafiles='+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile//JY_5.dbf' exclude=statistics

Import: Release 12.2.0.1.0 - Production on Sat Aug 19 01:08:07 2017

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

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Starting "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_03":  system/********@jypdb directory=dpump_tts logfile=tts_imp.log network_link=ttslink transport_full_check=no transport_tablespaces=JY transport_datafiles=+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile//JY_5.dbf exclude=statistics
Source time zone is +08:00 and target time zone is +00:00.
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/TABLE_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Job "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_03" successfully completed at Sat Aug 19 01:09:09 2017 elapsed 0 00:00:49


[oracle@jytest1 xtts_script]$ impdp system/abcd@jypdb directory=dpump_tts logfile=ysj.log schemas=jy content=metadata_only exclude=table,index network_link=ttslink

Import: Release 12.2.0.1.0 - Production on Sat Aug 19 01:11:32 2017

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

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01":  system/********@jypdb directory=dpump_tts logfile=ysj.log schemas=jy content=metadata_only exclude=table,index network_link=ttslink
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"JY" already exists

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" completed with 1 error(s) at Sat Aug 19 01:11:55 2017 elapsed 0 00:00:21

6.验证传输数据
6.1检查表空间是否有损坏

[oracle@jytest1 xtts_script]$ rman target sys/abcd@jypdb

Recovery Manager: Release 12.2.0.1.0 - Production on Sat Aug 19 01:17:35 2017

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

connected to target database: JY:JYPDB (DBID=2825277312)

RMAN> validate tablespace jy check logical;

Starting validate at 19-AUG-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1144 instance=jy1 device type=DISK
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00083 name=+DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/jy_5.dbf
channel ORA_DISK_1: validation complete, elapsed time: 00:00:07
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
83   OK     0              1            64001           1590987
  File Name: +DATA/jy/4B2C6373AE2547CCE053AB828A0A7CA3/datafile/jy_5.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              5
  Index      0              0
  Other      0              63994

Finished validate at 19-AUG-17

6.2将目标数据库中的表空间JY修改为read write状态

SQL> alter tablespace jy read write;

Tablespace altered.

7.清除操作
如果使用单独的转换home与实例,那么可以关闭转换实例并删除转换home。还可以删除源系统中创建的backupformat目录,目标系统中创建的bacup目录,源系统与目标系统中设置的环境变量$TMPDIR。

xttdriver.pl脚本选项
–backup:对源数据库中要被传输的表空间创建level 0级备份。这些备份将被写到xtt.properties文件中backupoformat参数所指定的目录中。这些备份需要手动复制到目标系统中stageondest参数所指定的目录中。而且还会生成tsbkupmap.txt与xttnewdatafiles.txt文件并且也需要复制到目标系统中相应目录(TMPDIR变量所指向的目录)

–restore:在目标系统中还原并转换stageondest目录中的数据文件备份的副本。还原的文件将会存储到storageondest参数所指定的目录中

–bkpincr:在源系统中对表空间创建增量备份并存储在backupformat参数所指定的目录中。这步操作还会创建incrbackups.txt文件它列出了所创建的备份。这个文件与tsbkupmap.txt必须复制到目标系统中的stageondest参数所指定的目录中

-recover:将增量备份应用到已经还原的数据文件上

-s:对源数据库判断新的from_scn可以执行一次或多次。这个操作将会计算下一个from_scn,并记录在xttplan.txt文件中,然后使用创建增量备份时会使用。

-bkpexport:将执行最后一次增量备份并且会创建元数据的dump文件用来导入数据文件。增量备份将会存储在backupformat参数所指定的目录中并且会创建incrbckups.txt与tsbkupmaps.txt文件,这些都要复制到目标系统中

–resincrdmp:将恢复最后一次增量备份并应用到数据文件。同时dump文件会被还原到TMPDIR变量所指定的目录中,dump文件可以用来导入

-e:在目标系统中生成传输表空间要导入的元数据脚本

-d debug:为了以debug模式来执行xttdriver.pl 与RMAN脚本。也可以设置环境变量XTTDEBUG=1,debug级别可以为1,2,3,例如xttdriver.pl -3

xtt.properties文件参数说明
tablespaces:用逗号来分隔从源数据库要被传输到目标数据库的表空间列表,例如tablespaces=TS1,TS2

platformid:从v$database.platform_id获得的源数据库的platform id,例如platformid=13

backupformat:源系统中存储备份文件的目录。这个目录必须要有足够的空间来存储所有创建的备份与增量备份文件。这个目录可以是目标系统上通过NFS-mounted文件系统所挂载到源系统中的一个目录,在这种情况下,目标系统中的stageondest参数也引用这个相同的NFS目录。例如,backupformat=/stage_source

stageondest:目标系统中存储从源系统中手动传输过来的数据文件副本。这个目录要有足够的空间来存储数据文件副本。这个目录同时也是用来存储从源系统传输过来的增量备份文件的目录。在目标系统上执行xttdriver.pl -c转换数据文件与执行xttdriver.pl -r前滚数据文件时会从这个目录中读取数据文件副本与增量备份文件。这个目标也可以是一个DBFS-mounted文件系统。个目录可以是源系统上通过NFS-mounted文件系统所挂载到目标系统中的一个目录,在这种情况下,源系统中的backupformat参数与dfcopydir参数就会引用这个相同的NFS目录。可以参考See Note 359515.1 for mount option guidelines。例如stageondest=/stage_dest

storageondest:目标系统中用来存储xttdriver.pl -c转换操作后所生成的数据文件副本的目录,也就是目标数据库最终存储数据文件的目录。这个目录要有足够的空间来永久存储数据文件。这个参数当使用RMAN备份来生成初始化数据文件副本时才使用,例如
storageondest=+DATA或者storageondest=/oradata/test

asm_home:目标系统中ASM实例的ORACLE_HOME。注意如果backupondest设置为文件系统目录,那么就要删除asm_home与asm_sid参数,例如asm_home=/u01/app/11.2.0.4/grid

asm_sid:目标系统中ASM实例的ORACLE_SID。例如asm_sid=+ASM1

parallel:定义rmanconvert.cmd命令文件中rman convert命令的并行度。如果不设置这个参数,那么xttdriver.pl将使用parallel=8的缺省并行度。例如,parallel=3

Proudly powered by WordPress | Indrajeet by Sus Hill.