RMAN同字节序跨平台跨版本迁移数据库(二)

在目标平台执行数据文件转换
将32位windows平台上的数据库jingyong(10.2.0.1)迁移到32位的Linux平台上(10.2.0.5)在目标平台上执行RMAN的convert database操作的步骤如下:
1.将源数据库以只读模式打开

C:\Users\Administrator>sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on 星期二 3月 31 20:30:23 2015

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


连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options


SQL> shutdown immediate
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL> startup mount
ORACLE 例程已经启动。

Total System Global Area  419430400 bytes
Fixed Size                  1249320 bytes
Variable Size             125833176 bytes
Database Buffers          285212672 bytes
Redo Buffers                7135232 bytes
数据库装载完毕。
SQL> alter database open read only;

数据库已更改。

2.对源数据库执行dbms_tdb.check_db检查

SQL> set serveroutput on
SQL> declare
  2   db_ready boolean;
  3  begin
  4   db_ready :=dbms_tdb.check_db('Linux IA (32-bit)',dbms_tdb.skip_readonly);
  5  end;
  6  /

PL/SQL procedure successfully completed

3.对源数据库执行dbms_tdb.check_external来识别外部对象

SQL> set serveroutput on;
SQL> declare
  2    external boolean;
  3  begin
  4    external:=dbms_tdb.check_external;
  5  end;
  6  /

The following external tables exist in the database:
SH.SALES_TRANSACTIONS_EXT
The following directories exist in the database:
SYS.TEST_DUMP, SYS.SUBDIR, SYS.XMLDIR, SYS.MEDIA_DIR, SYS.LOG_FILE_DIR, SYS.DATA_FILE_DIR, SYS.WORK_DIR, SYS.ADMIN_DIR, SYS.DATA_PUMP_DIR
The following BFILEs exist in the database:
PM.PRINT_MEDIA

PL/SQL procedure successfully completed

4.在源平台上执行convert database命令并指定on target platform参数。

C:\Users\Administrator>rman target/

恢复管理器: Release 10.2.0.1.0 - Production on 星期二 3月 31 21:05:58 2015

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

连接到目标数据库: JINGYONG (DBID=3213417256)

RMAN> convert database on target platform
2> convert script 'E:\oradata\convert\convertscript.rman'
3> transport script 'E:\oradata\convert\transportscript.sql'
4> new database 'cs'
5> format 'E:\oradata\convert\%U';

启动 convert 于 31-3月 -15
使用目标数据库控制文件替代恢复目录
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: sid=152 devtype=DISK

在数据库中找到外部表 SH.SALES_TRANSACTIONS_EXT

在数据库中找到目录 SYS.TEST_DUMP
在数据库中找到目录 SYS.SUBDIR
在数据库中找到目录 SYS.XMLDIR
在数据库中找到目录 SYS.MEDIA_DIR
在数据库中找到目录 SYS.LOG_FILE_DIR
在数据库中找到目录 SYS.DATA_FILE_DIR
在数据库中找到目录 SYS.WORK_DIR
在数据库中找到目录 SYS.ADMIN_DIR
在数据库中找到目录 SYS.DATA_PUMP_DIR

在数据库中找到 BFILE PM.PRINT_MEDIA

在口令文件中找到用户 SYS (具有 SYSDBA and SYSOPER 权限)
通道 ORA_DISK_1: 开始检查数据文件
输入数据文件 fno=00001 name=E:\ORADATA\JINGYONG\DATAFILE\O1_MF_SYSTEM_BKLLOT8Z_.
DBF
通道 ORA_DISK_1: 数据文件检查完毕, 用时: 00:00:00
通道 ORA_DISK_1: 开始检查数据文件
输入数据文件 fno=00003 name=E:\ORADATA\JINGYONG\DATAFILE\O1_MF_SYSAUX_BKLLOTFL_.
DBF
通道 ORA_DISK_1: 数据文件检查完毕, 用时: 00:00:01
通道 ORA_DISK_1: 开始检查数据文件
输入数据文件 fno=00005 name=E:\ORADATA\JINGYONG\DATAFILE\O1_MF_EXAMPLE_BKLLRKG2_
.DBF
通道 ORA_DISK_1: 数据文件检查完毕, 用时: 00:00:00
通道 ORA_DISK_1: 开始检查数据文件
输入数据文件 fno=00006 name=E:\ORADATA\JINGYONG\TSPITR01.DBF
通道 ORA_DISK_1: 数据文件检查完毕, 用时: 00:00:00
通道 ORA_DISK_1: 开始检查数据文件
输入数据文件 fno=00007 name=E:\ORADATA\JINGYONG\TEST01.DBF
通道 ORA_DISK_1: 数据文件检查完毕, 用时: 00:00:00
通道 ORA_DISK_1: 开始检查数据文件
输入数据文件 fno=00002 name=E:\ORADATA\JINGYONG\DATAFILE\O1_MF_UNDOTBS1_BKLLOTM0
_.DBF
通道 ORA_DISK_1: 数据文件检查完毕, 用时: 00:00:00
通道 ORA_DISK_1: 开始检查数据文件
输入数据文件 fno=00004 name=E:\ORADATA\JINGYONG\DATAFILE\O1_MF_USERS_BKLLOTM6_.D
BF
通道 ORA_DISK_1: 数据文件检查完毕, 用时: 00:00:01
在目标平台上运行 SQL 脚本 E:\ORADATA\CONVERT\TRANSPORTSCRIPT.SQL 以创建数据库
编辑 init.ora 文件 E:\ORADATA\CONVERT\INIT_00Q3836C_1_0.ORA。此 PFILE 将用于在目
标平台上创建数据库据
在目标平台上运行 RMAN 脚本 E:\ORADATA\CONVERT\CONVERTSCRIPT.RMAN 以转换数据文件
要重新编译所有 PL/SQL 模块, 请在目标平台上运行 utlirp.sql 和 utlrp.sql
要更改内部数据库标识符, 请使用 DBNEWID 实用程序
完成 backup 于 31-3月 -15

与在源平台执行convert database命令一样,convert database on target platform会生成可以在目标平台上创建新数据库的传输脚本和包含与源数据库有相同参数设置的PFILE参数文件。convert database on target platform也会生成一个包含对源数据库每个数据文件执行convert datafile命令的转换脚本。源数据库的数据文件必须在不被转换的情况下传输到目标主机相应的目录中,并对转换脚本做相应的修改,转换脚本内容如下:

RUN {

  CONVERT DATAFILE 'E:\ORADATA\JINGYONG\DATAFILE\O1_MF_SYSTEM_BKLLOT8Z_.DBF'
  FROM PLATFORM 'Microsoft Windows IA (32-bit)'
  FORMAT 'E:\ORADATA\CONVERT\DATA_D-JINGYONG_I-3213417256_TS-SYSTEM_FNO-1_08Q3836D';


  CONVERT DATAFILE 'E:\ORADATA\JINGYONG\DATAFILE\O1_MF_SYSAUX_BKLLOTFL_.DBF'
  FROM PLATFORM 'Microsoft Windows IA (32-bit)'
  FORMAT 'E:\ORADATA\CONVERT\DATA_D-JINGYONG_I-3213417256_TS-SYSAUX_FNO-3_09Q3836D';


  CONVERT DATAFILE 'E:\ORADATA\JINGYONG\DATAFILE\O1_MF_EXAMPLE_BKLLRKG2_.DBF'
  FROM PLATFORM 'Microsoft Windows IA (32-bit)'
  FORMAT 'E:\ORADATA\CONVERT\DATA_D-JINGYONG_I-3213417256_TS-EXAMPLE_FNO-5_0AQ3836E';


  CONVERT DATAFILE 'E:\ORADATA\JINGYONG\TSPITR01.DBF'
  FROM PLATFORM 'Microsoft Windows IA (32-bit)'
  FORMAT 'E:\ORADATA\CONVERT\DATA_D-JINGYONG_I-3213417256_TS-TSPITR_FNO-6_0BQ3836E';


  CONVERT DATAFILE 'E:\ORADATA\JINGYONG\TEST01.DBF'
  FROM PLATFORM 'Microsoft Windows IA (32-bit)'
  FORMAT 'E:\ORADATA\CONVERT\DATA_D-JINGYONG_I-3213417256_TS-TEST_FNO-7_0CQ3836E';


  CONVERT DATAFILE 'E:\ORADATA\JINGYONG\DATAFILE\O1_MF_UNDOTBS1_BKLLOTM0_.DBF'
  FROM PLATFORM 'Microsoft Windows IA (32-bit)'
  FORMAT 'E:\ORADATA\CONVERT\DATA_D-JINGYONG_I-3213417256_TS-UNDOTBS1_FNO-2_0DQ3836E';


  CONVERT DATAFILE 'E:\ORADATA\JINGYONG\DATAFILE\O1_MF_USERS_BKLLOTM6_.DBF'
  FROM PLATFORM 'Microsoft Windows IA (32-bit)'
  FORMAT 'E:\ORADATA\CONVERT\DATA_D-JINGYONG_I-3213417256_TS-USERS_FNO-4_0EQ3836F';


}

5.在源数据库为只读状态时将数据文件与传输脚本,转换脚本与PFILE参数文件复制到目标主机对应的目录中。

ftp> put CONVERTSCRIPT.RMAN
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 1462 字节,用时 0.00秒 1462000.00千字节/秒。
ftp> put INIT_00Q3836C_1_0.ORA
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 1309 字节,用时 0.00秒 1309.00千字节/秒。
ftp> TRANSPORTSCRIPT.SQL
无效命令。
ftp> put TRANSPORTSCRIPT.SQL
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 2739 字节,用时 0.00秒 2739.00千字节/秒。
ftp> lcd E:\oradata\JINGYONG
目前的本地目录 E:\oradata\JINGYONG。
ftp> bin
200 Switching to Binary mode.
ftp> put TEST01.dbf
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 52436992 字节,用时 2.55秒 20555.47千字节/秒。
ftp> put TSPITR01.dbf
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 52436992 字节,用时 6.71秒 7819.41千字节/秒。
ftp> lcd E:\oradata\JINGYONG\DATAFILE
目前的本地目录 E:\oradata\JINGYONG\DATAFILE。
ftp> bin
200 Switching to Binary mode.
ftp> put O1_MF_SYSTEM_BKLLOT8Z_.
O1_MF_SYSTEM_BKLLOT8Z_.: ftp> DBF
无效命令。
ftp> put O1_MF_EXAMPLE_BKLLRKG2_.DBF
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 104865792 字节,用时 12.16秒 8620.29千字节/秒。
ftp> put O1_MF_SYSAUX_BKLLOTFL_.DBF
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 251666432 字节,用时 25.59秒 9835.71千字节/秒。
ftp> put O1_MF_SYSTEM_BKLLOT8Z_.DBF
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 503324672 字节,用时 60.46秒 8325.06千字节/秒。
ftp> put O1_MF_UNDOTBS1_BKLLOTM0_.DBF
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 31465472 字节,用时 6.67秒 4718.17千字节/秒。
ftp> put O1_MF_USERS_BKLLOTM6_.DBF
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 5251072 字节,用时 0.42秒 12355.46千字节/秒。


[oracle@oracle11g cs]$ ls -lrt
total 978980
-rwxrwxrwx 1 oracle oinstall      1462 Mar 31 21:22 CONVERTSCRIPT.RMAN
-rwxrwxrwx 1 oracle oinstall      1309 Mar 31 21:22 INIT_00Q3836C_1_0.ORA
-rwxrwxrwx 1 oracle oinstall      2739 Mar 31 21:22 TRANSPORTSCRIPT.SQL
-rwxrwxrwx 1 oracle oinstall  52436992 Mar 31 21:23 TEST01.DBF
-rwxrwxrwx 1 oracle oinstall  52436992 Mar 31 21:23 TSPITR01.DBF
-rwxrwxrwx 1 oracle oinstall 104865792 Mar 31 21:24 O1_MF_EXAMPLE_BKLLRKG2_.DBF
-rwxrwxrwx 1 oracle oinstall 251666432 Mar 31 21:25 O1_MF_SYSAUX_BKLLOTFL_.DBF
-rwxrwxrwx 1 oracle oinstall 503324672 Mar 31 21:26 O1_MF_SYSTEM_BKLLOT8Z_.DBF
-rwxrwxrwx 1 oracle oinstall  31465472 Mar 31 21:27 O1_MF_UNDOTBS1_BKLLOTM0_.DBF
-rwxrwxrwx 1 oracle oinstall   5251072 Mar 31 21:27 O1_MF_USERS_BKLLOTM6_.DBF

6.创建新数据库cs相关目录,并修改PFILE参数文件,传输脚本与转换脚本中的相关路径信息,因为convert database on target platform命令并不会生成转换后的数据文件副本。当目标主机数据文件存储路径与源数据库数据文件存储路径完全相同时,可以直接执行转换脚本,但这里由于目标主机存储数据文件的路径与源数据库存储数据文件的路径不相同,需要对转换脚本做相应修改,也需要对用来创建新数据库的传输脚本做修改。

创建相关目录

[oracle@oracle11g dbs]$ mkdir -p /u01/app/oracle/admin/cs/adump
[oracle@oracle11g dbs]$ mkdir -p /u01/app/oracle/admin/cs/bdump
[oracle@oracle11g dbs]$ mkdir -p /u01/app/oracle/admin/cs/cdump
[oracle@oracle11g dbs]$ mkdir -p /u01/app/oracle/admin/cs/udump
[oracle@oracle11g dbs]$ chmod -R 777 /u01/app/oracle/admin/cs*

修改PFILE参数文件

[oracle@oracle11g cs]$ mv INIT_00Q3836C_1_0.ORA initcs.ora
[oracle@oracle11g cs]$ vi initcs.ora
  __shared_pool_size       = 113246208

  __large_pool_size        = 4194304

  __java_pool_size         = 4194304

  __streams_pool_size      = 4194304

  __db_cache_size          = 285212672

  remote_login_passwordfile= "EXCLUSIVE"

  db_domain                = ""
  db_create_file_dest      = "E:\ORADATA\CONVERT\oradata"
# Please change the values of the following parameters:


  audit_file_dest          = '/u01/app/oracle/admin/cs/adump'

  background_dump_dest     = '/u01/app/oracle/admin/cs/bdump'

  user_dump_dest           = '/u01/app/oracle/admin/cs/udump'

  core_dump_dest           = '/u01/app/oracle/admin/cs/cdump'

  db_name                  = "CS"

  control_files='/u02/cs/control01.ctl'

# Please review the values of the following parameters:


  dispatchers              = "(PROTOCOL=TCP) (SERVICE=csXDB)"



# The values of the following parameters are from source database:

  processes                = 150

  nls_language             = "SIMPLIFIED CHINESE"

  nls_territory            = "CHINA"

  sga_target               = 130M

  db_block_size            = 8192

  compatible               = "10.2.0.1.0"

  db_file_multiblock_read_count= 16

  undo_management          = "AUTO"

  undo_tablespace          = "UNDOTBS1"

  job_queue_processes      = 10

  open_cursors             = 300

  pga_aggregate_target     = 32M

"initcs.ora" 48L, 990C written
[oracle@oracle11g cs]$ cp initcs.ora $ORACLE_HOME/dbs

修改转换脚本

[oracle@oracle11g cs]$ vi CONVERTSCRIPT.RMAN
RUN {

  CONVERT DATAFILE '/u02/cs/O1_MF_SYSTEM_BKLLOT8Z_.DBF'
  FROM PLATFORM 'Microsoft Windows IA (32-bit)'
  FORMAT '/u02/cs/datafiles/system01.dbf';


  CONVERT DATAFILE '/u02/cs/O1_MF_SYSAUX_BKLLOTFL_.DBF'
  FROM PLATFORM 'Microsoft Windows IA (32-bit)'
  FORMAT '/u02/cs/datafiles/sysaux01.dbf';


  CONVERT DATAFILE '/u02/cs/O1_MF_EXAMPLE_BKLLRKG2_.DBF'
  FROM PLATFORM 'Microsoft Windows IA (32-bit)'
  FORMAT '/u02/cs/datafiles/example01.dbf';


  CONVERT DATAFILE '/u02/cs/TSPITR01.DBF'
  FROM PLATFORM 'Microsoft Windows IA (32-bit)'
  FORMAT '/u02/cs/datafiles/tspitr01.dbf';


  CONVERT DATAFILE '/u02/cs/TEST01.DBF'
  FROM PLATFORM 'Microsoft Windows IA (32-bit)'
  FORMAT '/u02/cs/datafiles/test01.dbf';


  CONVERT DATAFILE '/u02/cs/O1_MF_UNDOTBS1_BKLLOTM0_.DBF'
  FROM PLATFORM 'Microsoft Windows IA (32-bit)'
  FORMAT '/u02/cs/datafiles/undotsb1.dbf';


  CONVERT DATAFILE '/u02/cs/O1_MF_USERS_BKLLOTM6_.DBF'
  FROM PLATFORM 'Microsoft Windows IA (32-bit)'
  FORMAT '/u02/cs/datafiles/users01.dbf';


}

修改用来创建新数据库的传输脚本

[oracle@oracle11g cs]$ vi TRANSPORTSCRIPT.SQL
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- The contents of online logs will be lost and all backups will
-- be invalidated. Use this only if online logs are damaged.

-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE

STARTUP NOMOUNT PFILE='/u01/app/oracle/10.2.0/db/dbs/initcs.ora'

-- Create SPFILE
CREATE SPFILE FROM PFILE = '/u01/app/oracle/10.2.0/db/dbs/initcs.ora';


STARTUP FORCE NOMOUNT
CREATE CONTROLFILE REUSE SET DATABASE "CS" RESETLOGS  NOARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u02/cs/datafiles/redo01.log' SIZE 50M,
  GROUP 2 '/u02/cs/datafiles/redo02.log' SIZE 50M,
  GROUP 3 '/u02/cs/datafiles/redo03.log' SIZE 50M
DATAFILE
  '/u02/cs/datafiles/system01.dbf',
  '/u02/cs/datafiles/sysaux01.dbf',
  '/u02/cs/datafiles/example01.dbf',
  '/u02/cs/datafiles/tspitr01.dbf',
  '/u02/cs/datafiles/test01.dbf',
  '/u02/cs/datafiles/undotsb1.dbf',
  '/u02/cs/datafiles/users01.dbf'
CHARACTER SET ZHS16GBK
;

-- Database can now be opened zeroing the online logs.
ALTER DATABASE OPEN RESETLOGS;

-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/u02/cs/datafiles/temp01.dbf'
     SIZE 50M  AUTOEXTEND OFF;
-- End of tempfile additions.
--

set echo off
prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prompt * Your database has been created successfully!
prompt * There are many things to think about for the new database. Here
prompt * is a checklist to help you stay on track:
prompt * 1. You may want to redefine the location of the directory objects.
prompt * 2. You may want to change the internal database identifier (DBID)
prompt *    or the global database name for this database. Use the
prompt *    NEWDBID Utility (nid).
prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SHUTDOWN IMMEDIATE
STARTUP UPGRADE
@@ ?/rdbms/admin/utlirp.sql
SHUTDOWN IMMEDIATE
STARTUP
-- The following step will recompile all PL/SQL modules.
-- It may take serveral hours to complete.
@@ ?/rdbms/admin/utlrp.sql

7.在目标主机上执行转换脚本

[oracle@oracle11g admin]$ rman target/

Recovery Manager: Release 10.2.0.5.0 - Production on Tue Mar 31 21:55:50 2015

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

connected to target database: JINGYONG (DBID=3213417256)

RMAN> run
2> {
3> CONVERT DATAFILE '/u02/cs/O1_MF_SYSTEM_BKLLOT8Z_.DBF'
4>   FROM PLATFORM 'Microsoft Windows IA (32-bit)'
5>   FORMAT '/u02/cs/datafiles/system01.dbf';
6>
7>   CONVERT DATAFILE '/u02/cs/O1_MF_SYSAUX_BKLLOTFL_.DBF'
8>   FROM PLATFORM 'Microsoft Windows IA (32-bit)'
9>   FORMAT '/u02/cs/datafiles/sysaux01.dbf';
10>
11>   CONVERT DATAFILE '/u02/cs/O1_MF_EXAMPLE_BKLLRKG2_.DBF'
12>   FROM PLATFORM 'Microsoft Windows IA (32-bit)'
13>   FORMAT '/u02/cs/datafiles/example01.dbf';
14>
15>   CONVERT DATAFILE '/u02/cs/TSPITR01.DBF'
16>   FROM PLATFORM 'Microsoft Windows IA (32-bit)'
17>   FORMAT '/u02/cs/datafiles/tspitr01.dbf';
18>
19>   CONVERT DATAFILE '/u02/cs/TEST01.DBF'
20>   FROM PLATFORM 'Microsoft Windows IA (32-bit)'
21>   FORMAT '/u02/cs/datafiles/test01.dbf';
22>
23>   CONVERT DATAFILE '/u02/cs/O1_MF_UNDOTBS1_BKLLOTM0_.DBF'
24>   FROM PLATFORM 'Microsoft Windows IA (32-bit)'
25>   FORMAT '/u02/cs/datafiles/undotsb1.dbf';
26>
27>   CONVERT DATAFILE '/u02/cs/O1_MF_USERS_BKLLOTM6_.DBF'
28>   FROM PLATFORM 'Microsoft Windows IA (32-bit)'
29>   FORMAT '/u02/cs/datafiles/users01.dbf';
30> }

Starting backup at 31-MAR-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=160 devtype=DISK
channel ORA_DISK_1: starting datafile conversion
input filename=/u02/cs/O1_MF_SYSTEM_BKLLOT8Z_.DBF
converted datafile=/u02/cs/datafiles/system01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:55
Finished backup at 31-MAR-15

Starting backup at 31-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile conversion
input filename=/u02/cs/O1_MF_SYSAUX_BKLLOTFL_.DBF
converted datafile=/u02/cs/datafiles/sysaux01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:25
Finished backup at 31-MAR-15

Starting backup at 31-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile conversion
input filename=/u02/cs/O1_MF_EXAMPLE_BKLLRKG2_.DBF
converted datafile=/u02/cs/datafiles/example01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:15
Finished backup at 31-MAR-15

Starting backup at 31-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile conversion
input filename=/u02/cs/TSPITR01.DBF
converted datafile=/u02/cs/datafiles/tspitr01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:07
Finished backup at 31-MAR-15

Starting backup at 31-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile conversion
input filename=/u02/cs/TEST01.DBF
converted datafile=/u02/cs/datafiles/test01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:07
Finished backup at 31-MAR-15

Starting backup at 31-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile conversion
input filename=/u02/cs/O1_MF_UNDOTBS1_BKLLOTM0_.DBF
converted datafile=/u02/cs/datafiles/undotsb1.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:03
Finished backup at 31-MAR-15

Starting backup at 31-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile conversion
input filename=/u02/cs/O1_MF_USERS_BKLLOTM6_.DBF
converted datafile=/u02/cs/datafiles/users01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:01
Finished backup at 31-MAR-15

8.执行传输脚本中的内容来创建新数据库(也可以直接执行传输脚本)

[oracle@oracle11g admin]$ export ORACLE_SID=cs
[oracle@oracle11g admin]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 31 22:01:12 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> STARTUP NOMOUNT PFILE='/u01/app/oracle/10.2.0/db/dbs/initcs.ora'
ORACLE instance started.

Total System Global Area  138412032 bytes
Fixed Size                  1272432 bytes
Variable Size              62915984 bytes
Database Buffers           71303168 bytes
Redo Buffers                2920448 bytes

SQL> CREATE CONTROLFILE REUSE SET DATABASE "CS" RESETLOGS  NOARCHIVELOG
  2      MAXLOGFILES 16
  3      MAXLOGMEMBERS 3
  4      MAXDATAFILES 100
  5      MAXINSTANCES 8
  6      MAXLOGHISTORY 292
  7  LOGFILE
  8    GROUP 1 '/u02/cs/datafiles/redo01.log' SIZE 50M,
  9    GROUP 2 '/u02/cs/datafiles/redo02.log' SIZE 50M,
 10    GROUP 3 '/u02/cs/datafiles/redo03.log' SIZE 50M
 11  DATAFILE
 12    '/u02/cs/datafiles/system01.dbf',
 13    '/u02/cs/datafiles/sysaux01.dbf',
 14    '/u02/cs/datafiles/example01.dbf',
 15    '/u02/cs/datafiles/tspitr01.dbf',
 16    '/u02/cs/datafiles/test01.dbf',
 17    '/u02/cs/datafiles/undotsb1.dbf',
 18    '/u02/cs/datafiles/users01.dbf'
 19  CHARACTER SET ZHS16GBK
 20  ;

Control file created.


SQL> ALTER DATABASE OPEN RESETLOGS;
ALTER DATABASE OPEN RESETLOGS
*
ERROR at line 1:
ORA-01092: ORACLE instance terminated. Disconnection forced

在执行恢复后正常打开数据库实例被终止,在alert.log中的错误信息如下:

Errors in file /u01/app/oracle/admin/cs/udump/cs_ora_6458.trc:
ORA-00704: bootstrap process failure
ORA-39700: database must be opened with UPGRADE option
Tue Mar 31 22:04:28 CST 2015
Error 704 happened during db open, shutting down database
USER: terminating instance due to error 704
Instance terminated by USER, pid = 6458
ORA-1092 signalled during: ALTER DATABASE OPEN RESETLOGS...

错误信息指示需要以升级模式来启动数据库,因为迁移过来的源数据库的版本是10.2.0.1,而目标主机上的数据库版本是10.2.0.5。

以升级模式启动数据库

[oracle@oracle11g admin]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 31 22:06:55 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup upgrade
ORACLE instance started.

Total System Global Area  138412032 bytes
Fixed Size                  1272432 bytes
Variable Size              62915984 bytes
Database Buffers           71303168 bytes
Redo Buffers                2920448 bytes
Database mounted.
ORA-01113: file 1 needs media recovery if it was restored from backup, or END
BACKUP if it was not
ORA-01110: data file 1: '/u02/cs/datafiles/system01.dbf'

执行恢复并关闭数据库

SQL> recover database;
Media recovery complete.
SQL> shutdown immediate;
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.

再次以升级模式启动数据库

SQL> startup upgrade;
ORACLE instance started.

Total System Global Area  138412032 bytes
Fixed Size                  1272432 bytes
Variable Size              62915984 bytes
Database Buffers           71303168 bytes
Redo Buffers                2920448 bytes
Database mounted.
Database opened.

创建临时表空间

SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '/u02/cs/datafiles/temp01.dbf'
  2       SIZE 50M  AUTOEXTEND OFF;

Tablespace altered.

SQL>@$ORACLE_HOME/rdbms/admin/utlirp.sql
省略...
SQL>
SQL> Rem Continue even if there are SQL errors
SQL> WHENEVER SQLERROR CONTINUE;
SQL>
SQL> Rem ===========================================================================
SQL> Rem END utlip.sql
SQL> Rem ===========================================================================
SQL>
SQL> DOC
DOC>#######################################################################
DOC>#######################################################################
DOC>   utlirp.sql completed successfully. All PL/SQL objects in the
DOC>   database have been invalidated.
DOC>
DOC>   Shut down and restart the database in normal mode and run utlrp.sql to
DOC>   recompile invalid objects.
DOC>#######################################################################
DOC>#######################################################################
DOC>#

上面的输出信息说在以正常模式重启数据库后执行utlrp.sql脚本来编译无效对象。由于这里源数据库是10.2.0.1,而目标主机数据库的版本是10.2.0.5,在重启数据库仍然需要以升级模式来启动并执行utlrp.sql脚本

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup upgrade
ORACLE instance started.

Total System Global Area  138412032 bytes
Fixed Size                  1272432 bytes
Variable Size              62915984 bytes
Database Buffers           71303168 bytes
Redo Buffers                2920448 bytes
Database mounted.
Database opened.
SQL> @$ORACLE_HOME/rdbms/admin/utlrp.sql
SQL> Rem ===========================================================================
SQL> Rem BEGIN utlrp.sql
SQL> Rem ===========================================================================
省略...

PL/SQL procedure successfully completed.

SQL> SET serveroutput off
SQL>
SQL>
SQL> Rem ===========================================================================
SQL> Rem END utlrp.sql
SQL> Rem ===========================================================================

执行和数据库升级相关的脚本catupgrade.sql

SQL> @$ORACLE_HOME/rdbms/admin/catupgrd.sql
省略...
TIMESTAMP
--------------------------------------------------------------------------------
COMP_TIMESTAMP UPGRD_END  2015-03-31 23:04:46
.
Oracle Database 10.2 Upgrade Status Utility           03-31-2015 23:04:46
.
Component                                Status         Version  HH:MM:SS
Oracle Database Server                    VALID      10.2.0.5.0  00:18:17
JServer JAVA Virtual Machine              VALID      10.2.0.5.0  00:04:52
Oracle XDK                                VALID      10.2.0.5.0  00:00:49
Oracle Database Java Packages             VALID      10.2.0.5.0  00:00:32
Oracle Text                               VALID      10.2.0.5.0  00:00:56
Oracle XML Database                       VALID      10.2.0.5.0  00:02:33
Oracle Workspace Manager                  VALID      10.2.0.5.0  00:01:05
Oracle Data Mining                      INVALID      10.2.0.5.0  00:00:30
OLAP Analytic Workspace                   VALID      10.2.0.5.0  00:01:07
OLAP Catalog                              VALID      10.2.0.5.0  00:01:32
Oracle OLAP API                           VALID      10.2.0.5.0  00:01:08
Oracle interMedia                         VALID      10.2.0.5.0  00:05:11
Spatial                                   VALID      10.2.0.5.0  00:06:40
Oracle Expression Filter                INVALID      10.2.0.5.0  00:00:25
Oracle Enterprise Manager                 VALID      10.2.0.5.0  00:02:50
Oracle Rule Manager                     INVALID      10.2.0.5.0  00:00:20
.
Total Upgrade Time: 00:51:07
DOC>#######################################################################
DOC>#######################################################################
DOC>
DOC>   The above PL/SQL lists the SERVER components in the upgraded
DOC>   database, along with their current version and status.
DOC>
DOC>   Please review the status and version columns and look for
DOC>   any errors in the spool log file.  If there are errors in the spool
DOC>   file, or any components are not VALID or not the current version,
DOC>   consult the Oracle Database Upgrade Guide for troubleshooting
DOC>   recommendations.
DOC>
DOC>   Next shutdown immediate, restart for normal operation, and then
DOC>   run utlrp.sql to recompile any invalid application objects.
DOC>
DOC>#######################################################################
DOC>#######################################################################
DOC>

再次运行utlrp.sql脚本来进行编译无效对象

SQL> @$ORACLE_HOME/rdbms/admin/utlrp.sql
TIMESTAMP
--------------------------------------------------------------------------------
COMP_TIMESTAMP UTLRP_BGN  2015-03-31 23:05:21
DOC>   The following PL/SQL block invokes UTL_RECOMP to recompile invalid
DOC>   objects in the database. Recompilation time is proportional to the
DOC>   number of invalid objects in the database, so this command may take
DOC>   a long time to execute on a database with a large number of invalid
DOC>   objects.
DOC>
DOC>   Use the following queries to track recompilation progress:
DOC>
DOC>   1. Query returning the number of invalid objects remaining. This
DOC>      number should decrease with time.
DOC>         SELECT COUNT(*) FROM obj$ WHERE status IN (4, 5, 6);
DOC>
DOC>   2. Query returning the number of objects compiled so far. This number
DOC>      should increase with time.
DOC>         SELECT COUNT(*) FROM UTL_RECOMP_COMPILED;
DOC>
DOC>   This script automatically chooses serial or parallel recompilation
DOC>   based on the number of CPUs available (parameter cpu_count) multiplied
DOC>   by the number of threads per CPU (parameter parallel_threads_per_cpu).
DOC>   On RAC, this number is added across all RAC nodes.
DOC>
DOC>   UTL_RECOMP uses DBMS_SCHEDULER to create jobs for parallel
DOC>   recompilation. Jobs are created without instance affinity so that they
DOC>   can migrate across RAC nodes. Use the following queries to verify
DOC>   whether UTL_RECOMP jobs are being created and run correctly:
DOC>
DOC>   1. Query showing jobs created by UTL_RECOMP
DOC>         SELECT job_name FROM dba_scheduler_jobs
DOC>            WHERE job_name like 'UTL_RECOMP_SLAVE_%';
DOC>
DOC>   2. Query showing UTL_RECOMP jobs that are running
DOC>         SELECT job_name FROM dba_scheduler_running_jobs
DOC>            WHERE job_name like 'UTL_RECOMP_SLAVE_%';
DOC>#

TIMESTAMP
--------------------------------------------------------------------------------
COMP_TIMESTAMP UTLRP_END  2015-03-31 23:07:54
DOC> The following query reports the number of objects that have compiled
DOC> with errors (objects that compile with errors have status set to 3 in
DOC> obj$). If the number is higher than expected, please examine the error
DOC> messages reported with each object (using SHOW ERRORS) to see if they
DOC> point to system misconfiguration or resource constraints that must be
DOC> fixed before attempting to recompile these objects.
DOC>#

OBJECTS WITH ERRORS
-------------------
                  5
DOC> The following query reports the number of errors caught during
DOC> recompilation. If this number is non-zero, please query the error
DOC> messages in the table UTL_RECOMP_ERRORS to see if any of these errors
DOC> are due to misconfiguration or resource constraints that must be
DOC> fixed before objects can compile successfully.
DOC>#

ERRORS DURING RECOMPILATION
---------------------------
                          0
SQL> column comp_name format a35
SQL> SELECT comp_name, status, substr(version,1,10) as version from dba_server_registry order by modified;

COMP_NAME                           STATUS                 VERSION
----------------------------------- ---------------------- --------------------
Oracle Enterprise Manager           VALID                  10.2.0.5.0
Oracle Database Packages and Types  VALID                  10.2.0.5.0
Oracle Workspace Manager            VALID                  10.2.0.5.0
JServer JAVA Virtual Machine        VALID                  10.2.0.5.0
Oracle Database Java Packages       VALID                  10.2.0.5.0
Oracle Database Catalog Views       VALID                  10.2.0.5.0
Oracle XDK                          VALID                  10.2.0.5.0
Oracle Expression Filter            VALID                  10.2.0.5.0
Oracle Data Mining                  VALID                  10.2.0.5.0
Oracle Text                         VALID                  10.2.0.5.0
Oracle Rule Manager                 VALID                  10.2.0.5.0
Oracle interMedia                   VALID                  10.2.0.5.0
Oracle XML Database                 VALID                  10.2.0.5.0
OLAP Analytic Workspace             VALID                  10.2.0.5.0
Oracle OLAP API                     VALID                  10.2.0.5.0
OLAP Catalog                        VALID                  10.2.0.5.0
Spatial                             VALID                  10.2.0.5.0

RMAN同字节序跨平台跨版本迁移数据库(一)

跨平台传输数据库
RMAN的convert database命令被用来将整个数据库从一个平台移动到另一个平台。当源平台与目标平台字节序相同时,RMAN会在目标平台自动完成创建新数据库的大部分操作。当跨平台传输数据库时convertdatabase命令的处理过程将会很长。与传输表空间一样,RMAN的convert database命令可以在源平台或目标平台执行。

当跨平台传输数据库时文件会自动被传输到目标平台,这些文件包括:
1.属于永久表空间的数据文件,注意,不管源平台与目标平吧的字节序是否相同,传输数据库的数据文件必须要进行转换不能简单的从一个平台复制到另一个平台。与跨平台传输表空间不一样,传输整个数据库要求特定类型的数据块,比如undo段,要被重新格式化确保与目标平台兼容

2.如果使用PFILE,PFILE文件会被传输。如果使用SPFILE,会基于SPFILE生成PFILE并将其传输,并在目标平基于PFILE来生成新的SPFILE。注意,在大多数情况下,PFILE文件中的有些参数对于新数据库需要手动修改。例如db_name,control_files

跨平台传输数据库的限制
跨平台传输数据库的主要限制是源平台与目标平台必须有相同的字节序。例如,当将数据库从Windows平台传输到Linux平台(都是小字节序)或者从HP-UX到AIX(都是大字节序),不能将整个数据库从HP-UX传输到Linux平台上。然而,可以在目标平台上创建一个新数据库,并使用表空间传输功能将需要的表空间从源数据库中使用跨平台与跨字节序传输到目标数据库中。

在源平台执行转换
将32位windows平台上的数据库jingyong(10.2.0.1)迁移到32位的Linux平台上(10.2.0.5)。在源平台上执行RMAN的convert database操作的步骤如下:
1.将源数据库以只读模式打开

C:\Users\Administrator>sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on 星期二 3月 31 15:08:36 2015

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


连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> shutdown immediate
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL> startup mount
ORACLE 例程已经启动。

Total System Global Area  419430400 bytes
Fixed Size                  1249320 bytes
Variable Size             125833176 bytes
Database Buffers          285212672 bytes
Redo Buffers                7135232 bytes
数据库装载完毕。
SQL> alter database open read only;

数据库已更改。

2.对源数据库执行dbms_tdb.check_db检查

SQL> set serveroutput on
SQL> declare
  2   db_ready boolean;
  3  begin
  4   db_ready :=dbms_tdb.check_db('Linux IA (32-bit)',dbms_tdb.skip_readonly);
  5  end;
  6  /

PL/SQL procedure successfully completed

3.对源数据库执行dbms_tdb.check_external来识别外部对象

SQL> set serveroutput on;
SQL> declare
  2    external boolean;
  3  begin
  4    external:=dbms_tdb.check_external;
  5  end;
  6  /

The following external tables exist in the database:
SH.SALES_TRANSACTIONS_EXT
The following directories exist in the database:
SYS.TEST_DUMP, SYS.SUBDIR, SYS.XMLDIR, SYS.MEDIA_DIR, SYS.LOG_FILE_DIR, SYS.DATA_FILE_DIR, SYS.WORK_DIR, SYS.ADMIN_DIR, SYS.DATA_PUMP_DIR
The following BFILEs exist in the database:
PM.PRINT_MEDIA

PL/SQL procedure successfully completed

4.执行convert database命令,指定目标平台和输出文件名称。RMAN会生成需要移动到目标平台上的文件,包含以下文件:
–数据库完整的数据文件副本
–在目标平台使用的新的PFILE参数文件,包含来自源数据库PFILE或SPFILE中的设置。在目标平台使用之前需要进行相应修改
–传输脚本,包含在目标平台创建新数据库的SQL语句

RMAN> convert database new database 'jingyong'
2> transport script 'E:\oradata\transport\transport_db_script.sql'
3> to platform 'Linux IA (32-bit)'
4> db_file_name_convert('E:\oradata\JINGYONG\DATAFILE', 'E:\oradata\transport','
E:\oradata\JINGYONG', 'E:\oradata\transport');

启动 convert 于 31-3月 -15
使用目标数据库控制文件替代恢复目录
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: sid=152 devtype=DISK

在数据库中找到外部表 SH.SALES_TRANSACTIONS_EXT

在数据库中找到目录 SYS.TEST_DUMP
在数据库中找到目录 SYS.SUBDIR
在数据库中找到目录 SYS.XMLDIR
在数据库中找到目录 SYS.MEDIA_DIR
在数据库中找到目录 SYS.LOG_FILE_DIR
在数据库中找到目录 SYS.DATA_FILE_DIR
在数据库中找到目录 SYS.WORK_DIR
在数据库中找到目录 SYS.ADMIN_DIR
在数据库中找到目录 SYS.DATA_PUMP_DIR

在数据库中找到 BFILE PM.PRINT_MEDIA

在口令文件中找到用户 SYS (具有 SYSDBA and SYSOPER 权限)
通道 ORA_DISK_1: 启动数据文件转换
输入数据文件 fno=00001 name=E:\ORADATA\JINGYONG\DATAFILE\O1_MF_SYSTEM_BKLLOT8Z_.
DBF
已转换的数据文件 = E:\ORADATA\TRANSPORT\O1_MF_SYSTEM_BKLLOT8Z_.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:25
通道 ORA_DISK_1: 启动数据文件转换
输入数据文件 fno=00003 name=E:\ORADATA\JINGYONG\DATAFILE\O1_MF_SYSAUX_BKLLOTFL_.
DBF
已转换的数据文件 = E:\ORADATA\TRANSPORT\O1_MF_SYSAUX_BKLLOTFL_.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:16
通道 ORA_DISK_1: 启动数据文件转换
输入数据文件 fno=00005 name=E:\ORADATA\JINGYONG\DATAFILE\O1_MF_EXAMPLE_BKLLRKG2_
.DBF
已转换的数据文件 = E:\ORADATA\TRANSPORT\O1_MF_EXAMPLE_BKLLRKG2_.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:07
通道 ORA_DISK_1: 启动数据文件转换
输入数据文件 fno=00006 name=E:\ORADATA\JINGYONG\TSPITR01.DBF
已转换的数据文件 = E:\ORADATA\TRANSPORT\TSPITR01.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:03
通道 ORA_DISK_1: 启动数据文件转换
输入数据文件 fno=00007 name=E:\ORADATA\JINGYONG\TEST01.DBF
已转换的数据文件 = E:\ORADATA\TRANSPORT\TEST01.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:03
通道 ORA_DISK_1: 启动数据文件转换
输入数据文件 fno=00002 name=E:\ORADATA\JINGYONG\DATAFILE\O1_MF_UNDOTBS1_BKLLOTM0
_.DBF
已转换的数据文件 = E:\ORADATA\TRANSPORT\O1_MF_UNDOTBS1_BKLLOTM0_.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:03
通道 ORA_DISK_1: 启动数据文件转换
输入数据文件 fno=00004 name=E:\ORADATA\JINGYONG\DATAFILE\O1_MF_USERS_BKLLOTM6_.D
BF
已转换的数据文件 = E:\ORADATA\TRANSPORT\O1_MF_USERS_BKLLOTM6_.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:01
在目标平台上运行 SQL 脚本 E:\ORADATA\TRANSPORT\TRANSPORT_DB_SCRIPT.SQL 以创建数
据库
编辑 init.ora 文件 D:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\INIT_00Q37GUS_1_0.ORA
。此 PFILE 将用于在目标平台上创建数据库据
要重新编译所有 PL/SQL 模块, 请在目标平台上运行 utlirp.sql 和 utlrp.sql
要更改内部数据库标识符, 请使用 DBNEWID 实用程序
完成 backup 于 31-3月 -15

5.将转换操作生成的所有文件传输到目标主机上存储数据库文件的目录中当convert database执行完成后,源数据库可以以读写模式打开,生成的所有文件都要被传输到目标主机上。

ftp> put INIT_00Q37GUS_1_0.ORA
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 1415 字节,用时 0.00秒 1415.00千字节/秒。
ftp> put O1_MF_EXAMPLE_BKLLRKG2_.DBF
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 104865792 字节,用时 8.57秒 12233.53千字节/秒。
ftp> put O1_MF_SYSTEM_BKLLOT8Z_.DBF
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 503324672 字节,用时 49.54秒 10160.38千字节/秒。
ftp> put TSPITR01.DBF
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 52436992 字节,用时 4.46秒 11762.45千字节/秒。
ftp> put TEST01.DBF
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 52436992 字节,用时 3.48秒 15050.80千字节/秒。
ftp> put O1_MF_UNDOTBS1_BKLLOTM0_.DBF
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 31465472 字节,用时 2.05秒 15341.53千字节/秒。
ftp> put O1_MF_USERS_BKLLOTM6_.DBF
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 5251072 字节,用时 0.20秒 26520.57千字节/秒。
ftp> put TRANSPORT_DB_SCRIPT.SQL
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 2582 字节,用时 0.00秒 2582000.00千字节/秒。
ftp> put O1_MF_SYSAUX_BKLLOTFL_.DBF
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 251666432 字节,用时 19.63秒 12817.89千字节/秒。


[oracle@oracle11g jingyong]$ ls -lrt
total 978976
-rwxrwxrwx 1 oracle oinstall      1415 Mar 31 16:18 INIT_00Q37GUS_1_0.ORA
-rwxrwxrwx 1 oracle oinstall 104865792 Mar 31 16:18 O1_MF_EXAMPLE_BKLLRKG2_.DBF
-rwxrwxrwx 1 oracle oinstall 503324672 Mar 31 16:20 O1_MF_SYSTEM_BKLLOT8Z_.DBF
-rwxrwxrwx 1 oracle oinstall  52436992 Mar 31 16:21 TSPITR01.DBF
-rwxrwxrwx 1 oracle oinstall  52436992 Mar 31 16:21 TEST01.DBF
-rwxrwxrwx 1 oracle oinstall  31465472 Mar 31 16:22 O1_MF_UNDOTBS1_BKLLOTM0_.DBF
-rwxrwxrwx 1 oracle oinstall   5251072 Mar 31 16:22 O1_MF_USERS_BKLLOTM6_.DBF
-rwxrwxrwx 1 oracle oinstall      2582 Mar 31 16:23 TRANSPORT_DB_SCRIPT.SQL
-rwxrwxrwx 1 oracle oinstall 251666432 Mar 31 16:24 O1_MF_SYSAUX_BKLLOTFL_.DBF

6.在目标主机上创建数据库需要的目录,并修改PFILE参数文件中的相关参数,并修改传输脚本中指示数据文件的位置。

创建相关目录

[oracle@oracle11g dbs]$ mkdir -p /u01/app/oracle/admin/jingyong/adump
[oracle@oracle11g dbs]$ mkdir -p /u01/app/oracle/admin/jingyong/bdump
[oracle@oracle11g dbs]$ mkdir -p /u01/app/oracle/admin/jingyong/cdump
[oracle@oracle11g dbs]$ mkdir -p /u01/app/oracle/admin/jingyong/udump
[oracle@oracle11g dbs]$ chmod -R 777 /u01/app/oracle/admin/jingyong*

修改PFILE参数文件

[oracle@oracle11g jingyong]$ vi initjingyong.ora
# Please change the values of the following parameters:


  audit_file_dest          = '/u01/app/oracle/admin/jingyong/adump'

  background_dump_dest     = '/u01/app/oracle/admin/jingyong/bdump'

  user_dump_dest           = '/u01/app/oracle/admin/jingyong/udump'

  core_dump_dest           = '/u01/app/oracle/admin/jingyong/udump'

  db_name                  = "JINGYONG"
  control_files='/u01/app/oracle/oradata/test/control01.ctl'


# Please review the values of the following parameters:


  dispatchers              = "(PROTOCOL=TCP) (SERVICE=jingyongXDB)"



# The values of the following parameters are from source database:

  processes                = 150

  nls_language             = "SIMPLIFIED CHINESE"

  nls_territory            = "CHINA"

  sga_target               = 130M

  db_block_size            = 8192

  compatible               = "10.2.0.1.0"

  db_file_multiblock_read_count= 16

  undo_management          = "AUTO"

  undo_tablespace          = "UNDOTBS1"

  job_queue_processes      = 10

  open_cursors             = 300

  pga_aggregate_target     = 32M

修改convert database命令生成的传输脚本

[oracle@oracle11g jingyong]$ vi TRANSPORT_DB_SCRIPT.SQL
-- The contents of online logs will be lost and all backups will
-- be invalidated. Use this only if online logs are damaged.

-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE

STARTUP NOMOUNT PFILE='/u01/app/oracle/10.2.0/db/dbs/initjingyong.ora'

-- Create SPFILE
CREATE SPFILE FROM PFILE = '/u01/app/oracle/10.2.0/db/dbs/initjingyong.ora';


STARTUP FORCE NOMOUNT
CREATE CONTROLFILE REUSE SET DATABASE "JINGYONG" RESETLOGS  NOARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u02/jingyong/redo01.log' SIZE 50M,
  GROUP 2 '/u02/jingyong/redo02.log' SIZE 50M,
  GROUP 3 '/u02/jingyong/redo03.log' SIZE 50M
DATAFILE
  '/u02/jingyong/O1_MF_SYSTEM_BKLLOT8Z_.DBF',
  '/u02/jingyong/O1_MF_UNDOTBS1_BKLLOTM0_.DBF',
  '/u02/jingyong/O1_MF_SYSAUX_BKLLOTFL_.DBF',
  '/u02/jingyong/O1_MF_USERS_BKLLOTM6_.DBF',
  '/u02/jingyong/O1_MF_EXAMPLE_BKLLRKG2_.DBF',
  '/u02/jingyong/TSPITR01.DBF',
  '/u02/jingyong/TEST01.DBF'
CHARACTER SET ZHS16GBK
;

-- Database can now be opened zeroing the online logs.
ALTER DATABASE OPEN RESETLOGS;

-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/u02/jingyong/temp01.dbf'
     SIZE 50M  AUTOEXTEND OFF;
-- End of tempfile additions.
--

set echo off
prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prompt * Your database has been created successfully!
prompt * There are many things to think about for the new database. Here
prompt * is a checklist to help you stay on track:
prompt * 1. You may want to redefine the location of the directory objects.
prompt * 2. You may want to change the internal database identifier (DBID)
prompt *    or the global database name for this database. Use the
prompt *    NEWDBID Utility (nid).
prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SHUTDOWN IMMEDIATE
STARTUP UPGRADE
@@ ?/rdbms/admin/utlirp.sql
SHUTDOWN IMMEDIATE
STARTUP
-- The following step will recompile all PL/SQL modules.
-- It may take serveral hours to complete.
@@ ?/rdbms/admin/utlrp.sql



7.使用SQL*Plus来执行传输脚本中的内容在目标主机上创建新的数据库

[oracle@oracle11g jingyong]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 31 18:11:36 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> STARTUP NOMOUNT PFILE='/u01/app/oracle/10.2.0/db/dbs/initjingyong.ora'
ORACLE instance started.

Total System Global Area  138412032 bytes
Fixed Size                  1272432 bytes
Variable Size              62915984 bytes
Database Buffers           71303168 bytes
Redo Buffers                2920448 bytes
SQL> CREATE CONTROLFILE REUSE SET DATABASE "JINGYONG" RESETLOGS  NOARCHIVELOG
  2      MAXLOGFILES 16
  3      MAXLOGMEMBERS 3
  4      MAXDATAFILES 100
  5      MAXINSTANCES 8
  6      MAXLOGHISTORY 292
  7  LOGFILE
  8    GROUP 1 '/u02/jingyong/redo01.log' SIZE 50M,
  9    GROUP 2 '/u02/jingyong/redo02.log' SIZE 50M,
 10    GROUP 3 '/u02/jingyong/redo03.log' SIZE 50M
 11  DATAFILE
 12    '/u02/jingyong/O1_MF_SYSTEM_BKLLOT8Z_.DBF',
 13    '/u02/jingyong/O1_MF_UNDOTBS1_BKLLOTM0_.DBF',
 14    '/u02/jingyong/O1_MF_SYSAUX_BKLLOTFL_.DBF',
 15    '/u02/jingyong/O1_MF_USERS_BKLLOTM6_.DBF',
 16    '/u02/jingyong/O1_MF_EXAMPLE_BKLLRKG2_.DBF',
 17    '/u02/jingyong/TSPITR01.DBF',
 18    '/u02/jingyong/TEST01.DBF'
 19  CHARACTER SET ZHS16GBK
 20  ;

Control file created.

SQL> ALTER DATABASE OPEN RESETLOGS;
ALTER DATABASE OPEN RESETLOGS
*
ERROR at line 1:
ORA-01092: ORACLE instance terminated. Disconnection forced

在以open resetlogs方式打开数据库是出错了,alert.log中的错误信息如下所示:

Errors in file /u01/app/oracle/admin/jingyong/udump/jingyong_ora_5406.trc:
ORA-00704: bootstrap process failure
ORA-39700: database must be opened with UPGRADE option
Error 704 happened during db open, shutting down database
USER: terminating instance due to error 704
Instance terminated by USER, pid = 5406
ORA-1092 signalled during: alter database open...

错误信息指示需要以升级模式来启动数据库,因为迁移过来的源数据库的版本是10.2.0.1,而目标主机上的数据库版本是10.2.0.5。

以升级模式启动数据库

[oracle@oracle11g jingyong]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 31 18:11:36 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup upgrade;
ORACLE instance started.

Total System Global Area  138412032 bytes
Fixed Size                  1272432 bytes
Variable Size              62915984 bytes
Database Buffers           71303168 bytes
Redo Buffers                2920448 bytes
Database mounted.
ORA-01113: file 1 needs media recovery if it was restored from backup, or END
BACKUP if it was not
ORA-01110: data file 1: '/u02/jingyong/O1_MF_SYSTEM_BKLLOT8Z_.DBF'

执行恢复并关闭数据库

SQL> recover database;
Media recovery complete.
SQL> shutdown immediate;
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.

再次以升级模式启动数据库

SQL> startup upgrade;
ORACLE instance started.

Total System Global Area  138412032 bytes
Fixed Size                  1272432 bytes
Variable Size              62915984 bytes
Database Buffers           71303168 bytes
Redo Buffers                2920448 bytes
Database mounted.
Database opened.

创建临时表空间

SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '/u02/jingyong/temp01.dbf'
  2       SIZE 50M  AUTOEXTEND OFF;

SQL>@$ORACLE_HOME//rdbms/admin/utlirp.sql
省略...
SQL>
SQL> Rem Continue even if there are SQL errors
SQL> WHENEVER SQLERROR CONTINUE;
SQL>
SQL> Rem ===========================================================================
SQL> Rem END utlip.sql
SQL> Rem ===========================================================================
SQL>
SQL> DOC
DOC>#######################################################################
DOC>#######################################################################
DOC>   utlirp.sql completed successfully. All PL/SQL objects in the
DOC>   database have been invalidated.
DOC>
DOC>   Shut down and restart the database in normal mode and run utlrp.sql to
DOC>   recompile invalid objects.
DOC>#######################################################################
DOC>#######################################################################
DOC>#

上面的输出信息说在以正常模式重启数据库后执行utlrp.sql脚本来编译无效对象。由于这里源数据库是10.2.0.1,而目标主机数据库的版本是10.2.0.5,在重启数据库仍然需要以升级模式来启动并执行utlrp.sql脚本

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup upgrade
ORACLE instance started.

Total System Global Area  138412032 bytes
Fixed Size                  1272432 bytes
Variable Size              62915984 bytes
Database Buffers           71303168 bytes
Redo Buffers                2920448 bytes
Database mounted.
Database opened.
SQL> @$ORACLE_HOME/rdbms/admin/utlrp.sql
SQL> Rem ===========================================================================
SQL> Rem BEGIN utlrp.sql
SQL> Rem ===========================================================================
省略...

PL/SQL procedure successfully completed.

SQL> SET serveroutput off
SQL>
SQL>
SQL> Rem ===========================================================================
SQL> Rem END utlrp.sql
SQL> Rem ===========================================================================

执行和数据库升级相关的脚本catupgrade.sql

SQL> @$ORACLE_HOME/rdbms/admin/catupgrd.sql
省略...
COMP_TIMESTAMP UPGRD_END  2015-03-31 20:42:53
.
Oracle Database 10.2 Upgrade Status Utility           03-31-2015 20:42:54
.
Component                                Status         Version  HH:MM:SS
Oracle Database Server                    VALID      10.2.0.5.0  00:18:20
JServer JAVA Virtual Machine              VALID      10.2.0.5.0  00:05:21
Oracle XDK                                VALID      10.2.0.5.0  00:00:49
Oracle Database Java Packages             VALID      10.2.0.5.0  00:00:37
Oracle Text                               VALID      10.2.0.5.0  00:01:02
Oracle XML Database                       VALID      10.2.0.5.0  00:02:47
Oracle Workspace Manager                  VALID      10.2.0.5.0  00:01:39
Oracle Data Mining                        VALID      10.2.0.5.0  00:00:39
OLAP Analytic Workspace                   VALID      10.2.0.5.0  00:00:52
OLAP Catalog                              VALID      10.2.0.5.0  00:01:24
Oracle OLAP API                           VALID      10.2.0.5.0  00:01:08
Oracle interMedia                         VALID      10.2.0.5.0  00:05:22
Spatial                                   VALID      10.2.0.5.0  00:07:20
Oracle Expression Filter                  VALID      10.2.0.5.0  00:00:26
Oracle Enterprise Manager                 VALID      10.2.0.5.0  00:02:56
Oracle Rule Manager                       VALID      10.2.0.5.0  00:00:27
.
Total Upgrade Time: 00:53:45
DOC>#######################################################################
DOC>#######################################################################
DOC>
DOC>   The above PL/SQL lists the SERVER components in the upgraded
DOC>   database, along with their current version and status.
DOC>
DOC>   Please review the status and version columns and look for
DOC>   any errors in the spool log file.  If there are errors in the spool
DOC>   file, or any components are not VALID or not the current version,
DOC>   consult the Oracle Database Upgrade Guide for troubleshooting
DOC>   recommendations.
DOC>
DOC>   Next shutdown immediate, restart for normal operation, and then
DOC>   run utlrp.sql to recompile any invalid application objects.
DOC>
DOC>#######################################################################
DOC>#######################################################################

再次运行utlrp.sql脚本来进行编译无效对象

SQL> @$ORACLE_HOME/rdbms/admin/utlrp.sql

TIMESTAMP
--------------------------------------------------------------------------------
COMP_TIMESTAMP UTLRP_BGN  2015-03-31 20:50:46
DOC>   The following PL/SQL block invokes UTL_RECOMP to recompile invalid
DOC>   objects in the database. Recompilation time is proportional to the
DOC>   number of invalid objects in the database, so this command may take
DOC>   a long time to execute on a database with a large number of invalid
DOC>   objects.
DOC>
DOC>   Use the following queries to track recompilation progress:
DOC>
DOC>   1. Query returning the number of invalid objects remaining. This
DOC>      number should decrease with time.
DOC>         SELECT COUNT(*) FROM obj$ WHERE status IN (4, 5, 6);
DOC>
DOC>   2. Query returning the number of objects compiled so far. This number
DOC>      should increase with time.
DOC>         SELECT COUNT(*) FROM UTL_RECOMP_COMPILED;
DOC>
DOC>   This script automatically chooses serial or parallel recompilation
DOC>   based on the number of CPUs available (parameter cpu_count) multiplied
DOC>   by the number of threads per CPU (parameter parallel_threads_per_cpu).
DOC>   On RAC, this number is added across all RAC nodes.
DOC>
DOC>   UTL_RECOMP uses DBMS_SCHEDULER to create jobs for parallel
DOC>   recompilation. Jobs are created without instance affinity so that they
DOC>   can migrate across RAC nodes. Use the following queries to verify
DOC>   whether UTL_RECOMP jobs are being created and run correctly:
DOC>
DOC>   1. Query showing jobs created by UTL_RECOMP
DOC>         SELECT job_name FROM dba_scheduler_jobs
DOC>            WHERE job_name like 'UTL_RECOMP_SLAVE_%';
DOC>
DOC>   2. Query showing UTL_RECOMP jobs that are running
DOC>         SELECT job_name FROM dba_scheduler_running_jobs
DOC>            WHERE job_name like 'UTL_RECOMP_SLAVE_%';
DOC>#

TIMESTAMP
--------------------------------------------------------------------------------
COMP_TIMESTAMP UTLRP_END  2015-03-31 20:53:25
DOC> The following query reports the number of objects that have compiled
DOC> with errors (objects that compile with errors have status set to 3 in
DOC> obj$). If the number is higher than expected, please examine the error
DOC> messages reported with each object (using SHOW ERRORS) to see if they
DOC> point to system misconfiguration or resource constraints that must be
DOC> fixed before attempting to recompile these objects.
DOC>#

OBJECTS WITH ERRORS
-------------------
                 53
DOC> The following query reports the number of errors caught during
DOC> recompilation. If this number is non-zero, please query the error
DOC> messages in the table UTL_RECOMP_ERRORS to see if any of these errors
DOC> are due to misconfiguration or resource constraints that must be
DOC> fixed before objects can compile successfully.
DOC>#

ERRORS DURING RECOMPILATION
---------------------------
                          0

RMAN使用备份传输表空间的各种自定义操作

执行传输表空间时指定Data Pump文件目录
可以修改传输表空间集的Data Pump导出的dump文件名,示例脚本名和日志文件名。缺省情况下这些文件
存储在表空间目录中且缺省名称如下:
.Data Pump导出的dump文件名为dmpfile.dmp
.导出日志文件explog.log
.示例脚本impscrpt.sql

可以通过指定datapump directory子句来指定dump文件和导出日志文件的存储目录,datapumpdirectory子句使用的是数据库目录对象名,不是文件系统目录的目录路径。

下面的例子将使用指定datapump directory,dump file,export log和import script文件名的transport tablespace命令来执行表空间传输。

1.确认源数据库与目标数据库所在平台是不是传输表空间所支持的操作系统平台。
确认源数据库操作系统平台:

SQL> select d.platform_name,endian_format from v$transportable_platform tp,v$database d
  2  where tp.platform_name=d.platform_name ;

PLATFORM_NAME                                                                                         ENDIAN_FORMAT
----------------------------------------------------------------------------------------------------- --------------
Linux IA (32-bit)                                                                                     Little

确认目数据库操作系统平台:

SQL> select d.platform_name,endian_format from v$transportable_platform tp,v$database d
  2  where tp.platform_name=d.platform_name ;

PLATFORM_NAME                                                                                         ENDIAN_FORMAT
----------------------------------------------------------------------------------------------------- --------------
Linux IA (32-bit)                                                                                     Little

这里操作系统平台都是Linux

2.确认要被传输的表空间是否是自包含表空间(TSPITR,TEST):

SQL> exec sys.dbms_tts.transport_set_check('TSPITR',true);

PL/SQL procedure successfully completed.


SQL> exec sys.dbms_tts.transport_set_check('TEST',true);

PL/SQL procedure successfully completed.

SQL> select * from sys.transport_set_violations;

no rows selected

如果没有行选择,表示该表空间只包含表数据,可以传输。

SQL> select count(*) from tspitr.tspitr;

  COUNT(*)
----------
         0

SQL> select count(*) from test.test;

  COUNT(*)
----------
     50683

3.对源数据库执行备份,在执行备份时一定要加上include current controlfile否则执行transport tablespace命令时会出现以下错误信息:

Automatic instance removed
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of tranport tablespace command at 03/26/2015 20:24:22
RMAN-03015: error occurred in stored script Memory Script
RMAN-06026: some targets not found - aborting restore
RMAN-06024: no backup or copy of the control file found to restore

[oracle@oracle11g admin]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@oracle11g admin]$ rman target sys/zzh_2046@test  catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Thu Mar 26 20:01:33 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database

RMAN> backup as backupset database include current controlfile plus archivelog;


Starting backup at 2015-03-26 20:32:19
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=68 recid=75 stamp=875286167
input archive log thread=1 sequence=69 recid=76 stamp=875291999
input archive log thread=1 sequence=70 recid=77 stamp=875302397
input archive log thread=1 sequence=71 recid=78 stamp=875308491
input archive log thread=1 sequence=72 recid=79 stamp=875350203
input archive log thread=1 sequence=73 recid=80 stamp=875351397
input archive log thread=1 sequence=74 recid=81 stamp=875390545
input archive log thread=1 sequence=75 recid=82 stamp=875390643
input archive log thread=1 sequence=76 recid=83 stamp=875391627
input archive log thread=1 sequence=77 recid=84 stamp=875391661
input archive log thread=1 sequence=78 recid=85 stamp=875391764
input archive log thread=1 sequence=79 recid=86 stamp=875392340
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:32:22
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:32:29
piece handle=/u02/ora_test875392341_991 tag=TAG20150326T203220 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:08
Finished backup at 2015-03-26 20:32:29

Starting backup at 2015-03-26 20:32:29
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/test/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/test/example01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/test/tspitr01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/test/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/test/users01.dbf
input datafile fno=00007 name=/u01/app/oracle/oradata/test/test01.dbf
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:32:30
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:33:45
piece handle=/u02/ora_test875392350_1001 tag=TAG20150326T203229 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:33:46
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:33:47
piece handle=/u02/ora_test875392425_1011 tag=TAG20150326T203229 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 2015-03-26 20:33:47

Starting backup at 2015-03-26 20:33:47
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=80 recid=87 stamp=875392427
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:33:49
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:33:50
piece handle=/u02/ora_test875392428_1021 tag=TAG20150326T203348 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 2015-03-26 20:33:50

Starting Control File and SPFILE Autobackup at 2015-03-26 20:33:50
piece handle=/u02/c-2168949517-20150326-07 comment=NONE
Finished Control File and SPFILE Autobackup at 2015-03-26 20:33:54

RMAN> list backup;


List of Backup Sets
===================

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
6565    56.14M     DISK        00:00:07     2015-03-26 20:32:28
        BP Key: 6566   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203220
        Piece Name: /u02/ora_test875392341_991

  List of Archived Logs in backup set 6565
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    68      1040304    2015-03-25 09:33:41 1064641    2015-03-25 15:02:45
  1    69      1064641    2015-03-25 15:02:45 1067420    2015-03-25 16:39:58
  1    70      1067420    2015-03-25 16:39:58 1090668    2015-03-25 19:33:17
  1    71      1090668    2015-03-25 19:33:17 1093434    2015-03-25 21:14:51
  1    72      1093434    2015-03-25 21:14:51 1125870    2015-03-26 08:50:00
  1    73      1125870    2015-03-26 08:50:00 1126817    2015-03-26 09:09:56
  1    74      1126817    2015-03-26 09:09:56 1144051    2015-03-26 20:02:21
  1    75      1144051    2015-03-26 20:02:21 1144106    2015-03-26 20:04:02
  1    76      1144106    2015-03-26 20:04:02 1144862    2015-03-26 20:20:27
  1    77      1144862    2015-03-26 20:20:27 1144893    2015-03-26 20:21:00
  1    78      1144893    2015-03-26 20:21:00 1144980    2015-03-26 20:22:44
  1    79      1144980    2015-03-26 20:22:44 1145259    2015-03-26 20:32:19

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6607    Full    640.39M    DISK        00:01:08     2015-03-26 20:33:38
        BP Key: 6621   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203229
        Piece Name: /u02/ora_test875392350_1001
  List of Datafiles in backup set 6607
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  1       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/system01.dbf
  2       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/undotbs01.dbf
  3       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/sysaux01.dbf
  4       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/users01.dbf
  5       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/example01.dbf
  6       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/tspitr01.dbf
  7       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/test01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6608    Full    7.02M      DISK        00:00:01     2015-03-26 20:33:46
        BP Key: 6622   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203229
        Piece Name: /u02/ora_test875392425_1011
  Control File Included: Ckp SCN: 1145304      Ckp time: 2015-03-26 20:33:45

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
6658    2.50K      DISK        00:00:01     2015-03-26 20:33:49
        BP Key: 6660   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203348
        Piece Name: /u02/ora_test875392428_1021

  List of Archived Logs in backup set 6658
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    80      1145259    2015-03-26 20:32:19 1145307    2015-03-26 20:33:47

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6689    Full    7.05M      DISK        00:00:01     2015-03-26 20:33:52
        BP Key: 6691   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203351
        Piece Name: /u02/c-2168949517-20150326-07
  Control File Included: Ckp SCN: 1145329      Ckp time: 2015-03-26 20:33:51
  SPFILE Included: Modification time: 2015-03-26 19:31:13

4.创建一个数据库目录对象用来执行Data Pump导出

SQL> create or replace directory test_dump as '/u02/dump_test';

Directory created.

SQL> grant read,write on directory test_dump to public;

Grant succeeded.

RMAN> transport tablespace "TSPITR","TEST"
tablespace destination '/u02/transport'
auxiliary destination '/u02/transport'
2> 3> 4> datapump directory test_dump
5> dump file 'test.dmp'
6> import script 'importtest.sql'
7> export log 'testexport.log';


Creating automatic instance, with SID='meiB'

initialization parameters used for automatic instance:
db_name=TEST
compatible=10.2.0.5.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_TEST_meiB
sga_target=180M
processes=50
#No auxiliary parameter file used
db_create_file_dest=/u02/transport
control_files=/u02/transport/cntrl_tspitr_TEST_meiB.f


starting up automatic instance TEST

Oracle instance started

Total System Global Area     188743680 bytes

Fixed Size                     1272720 bytes
Variable Size                 62915696 bytes
Database Buffers             121634816 bytes
Redo Buffers                   2920448 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until  scn 1202258;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log for tspitr to a resent until time
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
# resync catalog after controlfile restore
resync catalog;
}
executing Memory Script

executing command: SET until clause

Starting restore at 28-MAR-15
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=47 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u02/c-2168949517-20150326-07
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/c-2168949517-20150326-07 tag=TAG20150326T203351
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
output filename=/u02/transport/cntrl_tspitr_TEST_meiB.f
Finished restore at 28-MAR-15

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

starting full resync of recovery catalog
full resync complete

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  scn 1202258;
# set an omf destination filename for restore
set newname for clone datafile  1 to new;
# set an omf destination filename for restore
set newname for clone datafile  2 to new;
# set an omf destination filename for restore
set newname for clone datafile  3 to new;
# set an omf destination tempfile
set newname for clone tempfile  1 to new;
# set a destination filename for restore
set newname for datafile  6 to
 "/u02/transport/tspitr01.dbf";
# set a destination filename for restore
set newname for datafile  7 to
 "/u02/transport/test01.dbf";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 3, 6, 7;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile  1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  3 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  6 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  7 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  "TSPITR", "TEST", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
#           datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed temporary file 1 to /u02/transport/TSPITR_TEST_MEIB/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 28-MAR-15
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u02/transport/TSPITR_TEST_MEIB/datafile/o1_mf_system_%u_.dbf
restoring datafile 00002 to /u02/transport/TSPITR_TEST_MEIB/datafile/o1_mf_undotbs1_%u_.dbf
restoring datafile 00003 to /u02/transport/TSPITR_TEST_MEIB/datafile/o1_mf_sysaux_%u_.dbf
restoring datafile 00006 to /u02/transport/tspitr01.dbf
restoring datafile 00007 to /u02/transport/test01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875392350_1001
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875392350_1001 tag=TAG20150326T203229
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:45
Finished restore at 28-MAR-15

datafile 1 switched to datafile copy
input datafile copy recid=22 stamp=875560079 filename=/u02/transport/TSPITR_TEST_MEIB/datafile/o1_mf_system_bkf2s69f_.dbf
datafile 2 switched to datafile copy
input datafile copy recid=23 stamp=875560079 filename=/u02/transport/TSPITR_TEST_MEIB/datafile/o1_mf_undotbs1_bkf2s6b2_.dbf
datafile 3 switched to datafile copy
input datafile copy recid=24 stamp=875560079 filename=/u02/transport/TSPITR_TEST_MEIB/datafile/o1_mf_sysaux_bkf2s69q_.dbf
datafile 6 switched to datafile copy
input datafile copy recid=25 stamp=875560079 filename=/u02/transport/tspitr01.dbf
datafile 7 switched to datafile copy
input datafile copy recid=26 stamp=875560079 filename=/u02/transport/test01.dbf

sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  6 online

sql statement: alter database datafile  7 online

Starting recover at 28-MAR-15
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 80 is already on disk as file /u02/1_80_870806981.dbf
archive log thread 1 sequence 81 is already on disk as file /u02/1_81_870806981.dbf
archive log thread 1 sequence 82 is already on disk as file /u02/1_82_870806981.dbf
archive log thread 1 sequence 83 is already on disk as file /u02/1_83_870806981.dbf
archive log thread 1 sequence 84 is already on disk as file /u02/1_84_870806981.dbf
archive log thread 1 sequence 85 is already on disk as file /u02/1_85_870806981.dbf
archive log thread 1 sequence 86 is already on disk as file /u02/1_86_870806981.dbf
archive log thread 1 sequence 87 is already on disk as file /u02/1_87_870806981.dbf
archive log filename=/u02/1_80_870806981.dbf thread=1 sequence=80
archive log filename=/u02/1_81_870806981.dbf thread=1 sequence=81
archive log filename=/u02/1_82_870806981.dbf thread=1 sequence=82
archive log filename=/u02/1_83_870806981.dbf thread=1 sequence=83
archive log filename=/u02/1_84_870806981.dbf thread=1 sequence=84
archive log filename=/u02/1_85_870806981.dbf thread=1 sequence=85
archive log filename=/u02/1_86_870806981.dbf thread=1 sequence=86
archive log filename=/u02/1_87_870806981.dbf thread=1 sequence=87
media recovery complete, elapsed time: 00:00:43
Finished recover at 28-MAR-15

database opened

contents of Memory Script:
{
#mark read only the tablespace that will be exported
sql clone "alter tablespace TSPITR read only";
#mark read only the tablespace that will be exported
sql clone "alter tablespace TEST read only";
# export the tablespaces in the recovery set
host 'expdp userid=\"/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle\)\(ARGV0=oraclemeiB\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=meiB^'\)\)\(CONNECT_DATA=\(SID=meiB\)\)\) as sysdba\" transport_tablespaces=
 TSPITR,
 TEST dumpfile=
test.dmp directory=
test_dump logfile=
testexport.log';
}
executing Memory Script

sql statement: alter tablespace TSPITR read only

sql statement: alter tablespace TEST read only


Export: Release 10.2.0.5.0 - Production on Saturday, 28 March, 2015 19:09:17

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TRANSPORTABLE_01":  userid="/********@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle)(ARGV0=oraclemeiB)(ARGS=\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\))(ENVS=ORACLE_SID=meiB))(CONNECT_DATA=(SID=meiB))) AS SYSDBA" transport_tablespaces= TSPITR, TEST dumpfile=test.dmp directory=test_dump logfile=testexport.log
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
Master table "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TRANSPORTABLE_01 is:
  /u02/dump_test/test.dmp
Job "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 19:10:21

host command complete
/*
   The following command may be used to import the tablespaces.
   Substitute values for  and .
   impdp  directory= dumpfile= 'test.dmp' transport_datafiles= /u02/transport/tspitr01.dbf, /u02/transport/test01.dbf
*/
--------------------------------------------------------------
-- Start of sample PL/SQL script for importing the tablespaces
--------------------------------------------------------------
-- creating directory objects
CREATE DIRECTORY STREAMS$DIROBJ$1 AS  '/u02/transport/';
/* PL/SQL Script to import the exported tablespaces */
DECLARE
  -- the datafiles
  tbs_files     dbms_streams_tablespace_adm.file_set;
  cvt_files     dbms_streams_tablespace_adm.file_set;
  -- the dumpfile to import
  dump_file     dbms_streams_tablespace_adm.file;
  dp_job_name   VARCHAR2(30) := NULL;
  -- names of tablespaces that were imported
  ts_names       dbms_streams_tablespace_adm.tablespace_set;
BEGIN
  -- dump file name and location
  dump_file.file_name :=  'test.dmp';
  dump_file.directory_object := 'test_dump';
  -- forming list of datafiles for import
  tbs_files( 1).file_name :=  'tspitr01.dbf';
  tbs_files( 1).directory_object :=  'STREAMS$DIROBJ$1';
  tbs_files( 2).file_name :=  'test01.dbf';
  tbs_files( 2).directory_object :=  'STREAMS$DIROBJ$1';
  -- import tablespaces
  dbms_streams_tablespace_adm.attach_tablespaces(
    datapump_job_name      => dp_job_name,
    dump_file              => dump_file,
    tablespace_files       => tbs_files,
    converted_files        => cvt_files,
    tablespace_names       => ts_names);
  -- output names of imported tablespaces
  IF ts_names IS NOT NULL AND ts_names.first IS NOT NULL THEN
    FOR i IN ts_names.first .. ts_names.last LOOP
      dbms_output.put_line('imported tablespace '|| ts_names(i));
    END LOOP;
  END IF;
END;
/
-- dropping directory objects
DROP DIRECTORY STREAMS$DIROBJ$1;
--------------------------------------------------------------
-- End of sample PL/SQL script
--------------------------------------------------------------

Removing automatic instance
shutting down automatic instance
Oracle instance shut down
Automatic instance removed
auxiliary instance file /u02/transport/cntrl_tspitr_TEST_meiB.f deleted
auxiliary instance file /u02/transport/TSPITR_TEST_MEIB/datafile/o1_mf_system_bkf2s69f_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_MEIB/datafile/o1_mf_undotbs1_bkf2s6b2_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_MEIB/datafile/o1_mf_sysaux_bkf2s69q_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_MEIB/datafile/o1_mf_temp_bkf2ydmv_.tmp deleted
auxiliary instance file /u02/transport/TSPITR_TEST_MEIB/onlinelog/o1_mf_1_bkf2xxxc_.log deleted
auxiliary instance file /u02/transport/TSPITR_TEST_MEIB/onlinelog/o1_mf_2_bkf2xzww_.log deleted
auxiliary instance file /u02/transport/TSPITR_TEST_MEIB/onlinelog/o1_mf_3_bkf2y2qn_.log deleted

[oracle@oracle11g transport]$ ls -lrt
total 112784
drwxr-x--- 4 oracle oinstall      4096 Mar 28 19:06 TSPITR_TEST_MEIB
-rw-r----- 1 oracle oinstall 104865792 Mar 28 19:09 tspitr01.dbf
-rw-r----- 1 oracle oinstall  10493952 Mar 28 19:09 test01.dbf
-rw-r--r-- 1 oracle oinstall      2065 Mar 28 19:10 importtest.sql

[oracle@oracle11g dump_test]$ ls -lrt
total 104
-rw-r--r-- 1 oracle oinstall  1242 Mar 28 19:10 testexport.log
-rw-r----- 1 oracle oinstall 98304 Mar 28 19:10 test.dmp

从上面的结果可以看到data pump导出文件为test.dmp,导出日志文件为testexport.log,示例导入脚本为importtest.sql,与指定的名称一样。

5.将步骤4生成的传输表空间的数据文件tspitr01.dbf,test01.dbf和Data Pump导出文件dmpfile拷贝到目标主机上的/u02目录中

[oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u02/transport/tspitr01.dbf /u02
oracle@192.168.56.2's password:
tspitr01.dbf                                                                                                                         100%  100MB   7.1MB/s   00:14
[oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u02/transport/test01.dbf /u02
oracle@192.168.56.2's password:
test01.dbf                                                                                                                           100%   10MB  10.0MB/s   00:00
[oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u02/dump_test/dmpfile.dmp /u02
oracle@192.168.56.2's password:
dmpfile.dmp                                                                                                                          100%   96KB  96.0KB/s   00:00
[oracle@jingyong1 u02]$ ls -lrt
total 112876
-rw-r----- 1 oracle oinstall 104865792 Mar 27 17:54 tspitr01.dbf
-rw-r----- 1 oracle oinstall  10493952 Mar 27 18:22 test01.dbf
-rw-r----- 1 oracle oinstall     98304 Mar 27 18:22 dmpfile.dmp

6.在目录主机上创建相关用户及Data Pump目录并将表空间附加到目标数据库中

SQL> create user tspitr identified by "tspitr";

User created.

SQL> grant dba,connect,resource to tspitr;

Grant succeeded.

SQL> create user test identified by "test";

User created.

SQL> grant dba,connect,resource to test;

Grant succeeded.

SQL> create directory mytest as '/u02';

Directory created.

SQL> grant read,write on directory mytest to public;

Grant succeeded.

最后就可以执行导入过程了

[oracle@jingyong1 ~]$ export ORACLE_SID=jy
[oracle@jingyong1 ~]$ export NLS_DATE_FORMATE='yyyy-mm-dd hh24:mi:ss'
[oracle@jingyong1 ~]$ impdp test/test directory=mytest dumpfile=dmpfile.dmp logfile=testtransport.log transport_datafiles= /u02/tspitr01.dbf, /u02/test01.dbf

Import: Release 10.2.0.5.0 - Production on Friday, 27 March, 2015 20:28:39

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "TEST"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded
Starting "TEST"."SYS_IMPORT_TRANSPORTABLE_01":  test/******** directory=mytest dumpfile=dmpfile.dmp logfile=testtransport.log transport_datafiles= /u02/tspitr01.dbf, /u02/test01.dbf
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 "TEST"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at 20:28:55

进入数据库中检查一下

SQL> select count(*) from tspitr.tspitr;

  COUNT(*)
----------
     0

SQL> select count(*) from test.test;

  COUNT(*)
----------
     50683

与表空间传输之前的状态一致

使用自定义参数执行表空间传输
对于所有的transport tablespace命令来说,RMAN都会使用缺省参数来创建辅助实例。transport tablespace命令也可以使用辅助参数文件来创建辅助实例,而不是使用缺省参数来创建。使用辅助实例参数文件有以下三个原因:
.为了管理辅助实例数据文件目录(例如,不想让所有的辅助实例数据文件存储在相同磁盘目录中,但不想为每个单独的数据文件指定目录)

.为了使用log_file_name_convert来控制联机重做日志的文件名

.为了Data Pump导出增大shared_pool_size的大小

RMAN传输表空间的缺省辅助实例参数
对于自动地辅助实例RMAN定义了以下基本参数:
.db_name,与源数据库的db_name相同
.compatible,与源数据库的设置相同
.db_unique_name,基于db_name来创建,且唯一
.db_files,与源数据库的db_files相同
.shared_pool_size,国灰Data Pump Export可能要求更多的空间设置为110M
.large_pool_size,设置为1M
如果使用auxiliary destination参数,RMAN也会定义:
.db_create_file_dest,设置辅助目录
.control_files,在辅助目录中生成控制文件

创建一个参数文件/u02/initaux.ora,并设置以下参数

[oracle@oracle11g u02]$ vi initaux.ora

shared_pool_size=150M

RMAN> run
2> {
3> set auxiliary instance parameter file to '/u02/initaux.ora';
4> transport tablespace "TSPITR","TEST"
5> tablespace destination '/u02/transport'
6> auxiliary destination '/u02/transport' ;
7> }

executing command: SET auxiliary parameter file


Creating automatic instance, with SID='ndyc'
using contents of file /u02/initaux.ora

initialization parameters used for automatic instance:
db_name=TEST
compatible=10.2.0.5.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_TEST_ndyc
sga_target=180M
processes=50
ifile=/u02/initaux.ora
db_create_file_dest=/u02/transport
control_files=/u02/transport/cntrl_tspitr_TEST_ndyc.f


starting up automatic instance TEST

Oracle instance started

Total System Global Area     188743680 bytes

Fixed Size                     1272720 bytes
Variable Size                167773296 bytes
Database Buffers              16777216 bytes
Redo Buffers                   2920448 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until  scn 1202636;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log for tspitr to a resent until time
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
# resync catalog after controlfile restore
resync catalog;
}
executing Memory Script

executing command: SET until clause

Starting restore at 28-MAR-15
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=47 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u02/c-2168949517-20150326-07
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/c-2168949517-20150326-07 tag=TAG20150326T203351
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:09
output filename=/u02/transport/cntrl_tspitr_TEST_ndyc.f
Finished restore at 28-MAR-15

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

starting full resync of recovery catalog
full resync complete

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  scn 1202636;
# set an omf destination filename for restore
set newname for clone datafile  1 to new;
# set an omf destination filename for restore
set newname for clone datafile  2 to new;
# set an omf destination filename for restore
set newname for clone datafile  3 to new;
# set an omf destination tempfile
set newname for clone tempfile  1 to new;
# set a destination filename for restore
set newname for datafile  6 to
 "/u02/transport/tspitr01.dbf";
# set a destination filename for restore
set newname for datafile  7 to
 "/u02/transport/test01.dbf";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 3, 6, 7;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile  1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  3 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  6 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  7 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  "TSPITR", "TEST", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
#           datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed temporary file 1 to /u02/transport/TSPITR_TEST_NDYC/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 28-MAR-15
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u02/transport/TSPITR_TEST_NDYC/datafile/o1_mf_system_%u_.dbf
restoring datafile 00002 to /u02/transport/TSPITR_TEST_NDYC/datafile/o1_mf_undotbs1_%u_.dbf
restoring datafile 00003 to /u02/transport/TSPITR_TEST_NDYC/datafile/o1_mf_sysaux_%u_.dbf
restoring datafile 00006 to /u02/transport/tspitr01.dbf
restoring datafile 00007 to /u02/transport/test01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875392350_1001
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875392350_1001 tag=TAG20150326T203229
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:25
Finished restore at 28-MAR-15

datafile 1 switched to datafile copy
input datafile copy recid=22 stamp=875563331 filename=/u02/transport/TSPITR_TEST_NDYC/datafile/o1_mf_system_bkf5zggf_.dbf
datafile 2 switched to datafile copy
input datafile copy recid=23 stamp=875563331 filename=/u02/transport/TSPITR_TEST_NDYC/datafile/o1_mf_undotbs1_bkf5zgjg_.dbf
datafile 3 switched to datafile copy
input datafile copy recid=24 stamp=875563331 filename=/u02/transport/TSPITR_TEST_NDYC/datafile/o1_mf_sysaux_bkf5zggr_.dbf
datafile 6 switched to datafile copy
input datafile copy recid=25 stamp=875563331 filename=/u02/transport/tspitr01.dbf
datafile 7 switched to datafile copy
input datafile copy recid=26 stamp=875563331 filename=/u02/transport/test01.dbf

sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  6 online

sql statement: alter database datafile  7 online

Starting recover at 28-MAR-15
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 80 is already on disk as file /u02/1_80_870806981.dbf
archive log thread 1 sequence 81 is already on disk as file /u02/1_81_870806981.dbf
archive log thread 1 sequence 82 is already on disk as file /u02/1_82_870806981.dbf
archive log thread 1 sequence 83 is already on disk as file /u02/1_83_870806981.dbf
archive log thread 1 sequence 84 is already on disk as file /u02/1_84_870806981.dbf
archive log thread 1 sequence 85 is already on disk as file /u02/1_85_870806981.dbf
archive log thread 1 sequence 86 is already on disk as file /u02/1_86_870806981.dbf
archive log thread 1 sequence 87 is already on disk as file /u02/1_87_870806981.dbf
archive log thread 1 sequence 88 is already on disk as file /u02/1_88_870806981.dbf
archive log filename=/u02/1_80_870806981.dbf thread=1 sequence=80
archive log filename=/u02/1_81_870806981.dbf thread=1 sequence=81
archive log filename=/u02/1_82_870806981.dbf thread=1 sequence=82
archive log filename=/u02/1_83_870806981.dbf thread=1 sequence=83
archive log filename=/u02/1_84_870806981.dbf thread=1 sequence=84
archive log filename=/u02/1_85_870806981.dbf thread=1 sequence=85
archive log filename=/u02/1_86_870806981.dbf thread=1 sequence=86
archive log filename=/u02/1_87_870806981.dbf thread=1 sequence=87
archive log filename=/u02/1_88_870806981.dbf thread=1 sequence=88
media recovery complete, elapsed time: 00:00:55
Finished recover at 28-MAR-15

database opened

contents of Memory Script:
{
#mark read only the tablespace that will be exported
sql clone "alter tablespace TSPITR read only";
#mark read only the tablespace that will be exported
sql clone "alter tablespace TEST read only";
# create directory for datapump export
sql clone "create or replace directory STREAMS_DIROBJ_DPDIR as ''
/u02/transport''";
# export the tablespaces in the recovery set
host 'expdp userid=\"/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle\)\(ARGV0=oraclendyc\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=ndyc^'\)\)\(CONNECT_DATA=\(SID=ndyc\)\)\) as sysdba\" transport_tablespaces=
 TSPITR,
 TEST dumpfile=
dmpfile.dmp directory=
STREAMS_DIROBJ_DPDIR logfile=
explog.log';
}
executing Memory Script

sql statement: alter tablespace TSPITR read only

sql statement: alter tablespace TEST read only

sql statement: create or replace directory STREAMS_DIROBJ_DPDIR as ''/u02/transport''


Export: Release 10.2.0.5.0 - Production on Saturday, 28 March, 2015 20:03:36

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TRANSPORTABLE_01":  userid="/********@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle)(ARGV0=oraclendyc)(ARGS=\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\))(ENVS=ORACLE_SID=ndyc))(CONNECT_DATA=(SID=ndyc))) AS SYSDBA" transport_tablespaces= TSPITR, TEST dumpfile=dmpfile.dmp directory=STREAMS_DIROBJ_DPDIR logfile=explog.log
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
Master table "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TRANSPORTABLE_01 is:
  /u02/transport/dmpfile.dmp
Job "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 20:04:38

host command complete
/*
   The following command may be used to import the tablespaces.
   Substitute values for  and .
   impdp  directory= dumpfile= 'dmpfile.dmp' transport_datafiles= /u02/transport/tspitr01.dbf, /u02/transport/test01.dbf
*/
--------------------------------------------------------------
-- Start of sample PL/SQL script for importing the tablespaces
--------------------------------------------------------------
-- creating directory objects
CREATE DIRECTORY STREAMS$DIROBJ$1 AS  '/u02/transport/';
CREATE DIRECTORY STREAMS$DIROBJ$DPDIR AS  '/u02/transport';
/* PL/SQL Script to import the exported tablespaces */
DECLARE
  -- the datafiles
  tbs_files     dbms_streams_tablespace_adm.file_set;
  cvt_files     dbms_streams_tablespace_adm.file_set;
  -- the dumpfile to import
  dump_file     dbms_streams_tablespace_adm.file;
  dp_job_name   VARCHAR2(30) := NULL;
  -- names of tablespaces that were imported
  ts_names       dbms_streams_tablespace_adm.tablespace_set;
BEGIN
  -- dump file name and location
  dump_file.file_name :=  'dmpfile.dmp';
  dump_file.directory_object := 'STREAMS$DIROBJ$DPDIR';
  -- forming list of datafiles for import
  tbs_files( 1).file_name :=  'tspitr01.dbf';
  tbs_files( 1).directory_object :=  'STREAMS$DIROBJ$1';
  tbs_files( 2).file_name :=  'test01.dbf';
  tbs_files( 2).directory_object :=  'STREAMS$DIROBJ$1';
  -- import tablespaces
  dbms_streams_tablespace_adm.attach_tablespaces(
    datapump_job_name      => dp_job_name,
    dump_file              => dump_file,
    tablespace_files       => tbs_files,
    converted_files        => cvt_files,
    tablespace_names       => ts_names);
  -- output names of imported tablespaces
  IF ts_names IS NOT NULL AND ts_names.first IS NOT NULL THEN
    FOR i IN ts_names.first .. ts_names.last LOOP
      dbms_output.put_line('imported tablespace '|| ts_names(i));
    END LOOP;
  END IF;
END;
/
-- dropping directory objects
DROP DIRECTORY STREAMS$DIROBJ$1;
DROP DIRECTORY STREAMS$DIROBJ$DPDIR;
--------------------------------------------------------------
-- End of sample PL/SQL script
--------------------------------------------------------------

Removing automatic instance
shutting down automatic instance
Oracle instance shut down
Automatic instance removed
auxiliary instance file /u02/transport/cntrl_tspitr_TEST_ndyc.f deleted
auxiliary instance file /u02/transport/TSPITR_TEST_NDYC/datafile/o1_mf_system_bkf5zggf_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_NDYC/datafile/o1_mf_undotbs1_bkf5zgjg_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_NDYC/datafile/o1_mf_sysaux_bkf5zggr_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_NDYC/datafile/o1_mf_temp_bkf6487l_.tmp deleted
auxiliary instance file /u02/transport/TSPITR_TEST_NDYC/onlinelog/o1_mf_1_bkf63x6t_.log deleted
auxiliary instance file /u02/transport/TSPITR_TEST_NDYC/onlinelog/o1_mf_2_bkf63z8n_.log deleted
auxiliary instance file /u02/transport/TSPITR_TEST_NDYC/onlinelog/o1_mf_3_bkf641h8_.log deleted

使用自定义辅助控制文件来执行表空间传输

[oracle@oracle11g u02]$ vi  initaux.ora

shared_pool_size=150M
control_files=('/u02/transport/control01.ctl')

RMAN> run
2> {
3> set auxiliary instance parameter file to '/u02/initaux.ora';
4> transport tablespace "TSPITR","TEST"
5> tablespace destination '/u02/transport'
6> auxiliary destination '/u02/transport' ;
7> }

executing command: SET auxiliary parameter file


Creating automatic instance, with SID='EmBb'
using contents of file /u02/initaux.ora

initialization parameters used for automatic instance:
db_name=TEST
compatible=10.2.0.5.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_TEST_EmBb
sga_target=180M
processes=50
ifile=/u02/initaux.ora
db_create_file_dest=/u02/transport
control_files=/u02/transport/cntrl_tspitr_TEST_EmBb.f


starting up automatic instance TEST

Oracle instance started

Total System Global Area     188743680 bytes

Fixed Size                     1272720 bytes
Variable Size                167773296 bytes
Database Buffers              16777216 bytes
Redo Buffers                   2920448 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until  scn 1204101;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log for tspitr to a resent until time
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
# resync catalog after controlfile restore
resync catalog;
}
executing Memory Script

executing command: SET until clause

Starting restore at 28-MAR-15
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=47 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u02/c-2168949517-20150326-07
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/c-2168949517-20150326-07 tag=TAG20150326T203351
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output filename=/u02/transport/cntrl_tspitr_TEST_EmBb.f
Finished restore at 28-MAR-15

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

starting full resync of recovery catalog
full resync complete

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  scn 1204101;
# set an omf destination filename for restore
set newname for clone datafile  1 to new;
# set an omf destination filename for restore
set newname for clone datafile  2 to new;
# set an omf destination filename for restore
set newname for clone datafile  3 to new;
# set an omf destination tempfile
set newname for clone tempfile  1 to new;
# set a destination filename for restore
set newname for datafile  6 to
 "/u02/transport/tspitr01.dbf";
# set a destination filename for restore
set newname for datafile  7 to
 "/u02/transport/test01.dbf";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 3, 6, 7;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile  1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  3 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  6 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  7 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  "TSPITR", "TEST", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
#           datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed temporary file 1 to /u02/transport/TSPITR_TEST_EMBB/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 28-MAR-15
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u02/transport/TSPITR_TEST_EMBB/datafile/o1_mf_system_%u_.dbf
restoring datafile 00002 to /u02/transport/TSPITR_TEST_EMBB/datafile/o1_mf_undotbs1_%u_.dbf
restoring datafile 00003 to /u02/transport/TSPITR_TEST_EMBB/datafile/o1_mf_sysaux_%u_.dbf
restoring datafile 00006 to /u02/transport/tspitr01.dbf
restoring datafile 00007 to /u02/transport/test01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875392350_1001
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875392350_1001 tag=TAG20150326T203229
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:35
Finished restore at 28-MAR-15

datafile 1 switched to datafile copy
input datafile copy recid=22 stamp=875563883 filename=/u02/transport/TSPITR_TEST_EMBB/datafile/o1_mf_system_bkf6jddz_.dbf
datafile 2 switched to datafile copy
input datafile copy recid=23 stamp=875563883 filename=/u02/transport/TSPITR_TEST_EMBB/datafile/o1_mf_undotbs1_bkf6jdmt_.dbf
datafile 3 switched to datafile copy
input datafile copy recid=24 stamp=875563883 filename=/u02/transport/TSPITR_TEST_EMBB/datafile/o1_mf_sysaux_bkf6jdfc_.dbf
datafile 6 switched to datafile copy
input datafile copy recid=25 stamp=875563883 filename=/u02/transport/tspitr01.dbf
datafile 7 switched to datafile copy
input datafile copy recid=26 stamp=875563883 filename=/u02/transport/test01.dbf

sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  6 online

sql statement: alter database datafile  7 online

Starting recover at 28-MAR-15
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 80 is already on disk as file /u02/1_80_870806981.dbf
archive log thread 1 sequence 81 is already on disk as file /u02/1_81_870806981.dbf
archive log thread 1 sequence 82 is already on disk as file /u02/1_82_870806981.dbf
archive log thread 1 sequence 83 is already on disk as file /u02/1_83_870806981.dbf
archive log thread 1 sequence 84 is already on disk as file /u02/1_84_870806981.dbf
archive log thread 1 sequence 85 is already on disk as file /u02/1_85_870806981.dbf
archive log thread 1 sequence 86 is already on disk as file /u02/1_86_870806981.dbf
archive log thread 1 sequence 87 is already on disk as file /u02/1_87_870806981.dbf
archive log thread 1 sequence 88 is already on disk as file /u02/1_88_870806981.dbf
archive log thread 1 sequence 89 is already on disk as file /u02/1_89_870806981.dbf
archive log filename=/u02/1_80_870806981.dbf thread=1 sequence=80
archive log filename=/u02/1_81_870806981.dbf thread=1 sequence=81
archive log filename=/u02/1_82_870806981.dbf thread=1 sequence=82
archive log filename=/u02/1_83_870806981.dbf thread=1 sequence=83
archive log filename=/u02/1_84_870806981.dbf thread=1 sequence=84
archive log filename=/u02/1_85_870806981.dbf thread=1 sequence=85
archive log filename=/u02/1_86_870806981.dbf thread=1 sequence=86
archive log filename=/u02/1_87_870806981.dbf thread=1 sequence=87
archive log filename=/u02/1_88_870806981.dbf thread=1 sequence=88
archive log filename=/u02/1_89_870806981.dbf thread=1 sequence=89
media recovery complete, elapsed time: 00:00:57
Finished recover at 28-MAR-15

database opened

contents of Memory Script:
{
#mark read only the tablespace that will be exported
sql clone "alter tablespace TSPITR read only";
#mark read only the tablespace that will be exported
sql clone "alter tablespace TEST read only";
# create directory for datapump export
sql clone "create or replace directory STREAMS_DIROBJ_DPDIR as ''
/u02/transport''";
# export the tablespaces in the recovery set
host 'expdp userid=\"/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle\)\(ARGV0=oracleEmBb\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=EmBb^'\)\)\(CONNECT_DATA=\(SID=EmBb\)\)\) as sysdba\" transport_tablespaces=
 TSPITR,
 TEST dumpfile=
dmpfile.dmp directory=
STREAMS_DIROBJ_DPDIR logfile=
explog.log';
}
executing Memory Script

sql statement: alter tablespace TSPITR read only

sql statement: alter tablespace TEST read only

sql statement: create or replace directory STREAMS_DIROBJ_DPDIR as ''/u02/transport''


Export: Release 10.2.0.5.0 - Production on Saturday, 28 March, 2015 20:13:04

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TRANSPORTABLE_01":  userid="/********@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle)(ARGV0=oracleEmBb)(ARGS=\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\))(ENVS=ORACLE_SID=EmBb))(CONNECT_DATA=(SID=EmBb))) AS SYSDBA" transport_tablespaces= TSPITR, TEST dumpfile=dmpfile.dmp directory=STREAMS_DIROBJ_DPDIR logfile=explog.log
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
Master table "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TRANSPORTABLE_01 is:
  /u02/transport/dmpfile.dmp
Job "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 20:14:05

host command complete
/*
   The following command may be used to import the tablespaces.
   Substitute values for  and .
   impdp  directory= dumpfile= 'dmpfile.dmp' transport_datafiles= /u02/transport/tspitr01.dbf, /u02/transport/test01.dbf
*/
--------------------------------------------------------------
-- Start of sample PL/SQL script for importing the tablespaces
--------------------------------------------------------------
-- creating directory objects
CREATE DIRECTORY STREAMS$DIROBJ$1 AS  '/u02/transport/';
CREATE DIRECTORY STREAMS$DIROBJ$DPDIR AS  '/u02/transport';
/* PL/SQL Script to import the exported tablespaces */
DECLARE
  -- the datafiles
  tbs_files     dbms_streams_tablespace_adm.file_set;
  cvt_files     dbms_streams_tablespace_adm.file_set;
  -- the dumpfile to import
  dump_file     dbms_streams_tablespace_adm.file;
  dp_job_name   VARCHAR2(30) := NULL;
  -- names of tablespaces that were imported
  ts_names       dbms_streams_tablespace_adm.tablespace_set;
BEGIN
  -- dump file name and location
  dump_file.file_name :=  'dmpfile.dmp';
  dump_file.directory_object := 'STREAMS$DIROBJ$DPDIR';
  -- forming list of datafiles for import
  tbs_files( 1).file_name :=  'tspitr01.dbf';
  tbs_files( 1).directory_object :=  'STREAMS$DIROBJ$1';
  tbs_files( 2).file_name :=  'test01.dbf';
  tbs_files( 2).directory_object :=  'STREAMS$DIROBJ$1';
  -- import tablespaces
  dbms_streams_tablespace_adm.attach_tablespaces(
    datapump_job_name      => dp_job_name,
    dump_file              => dump_file,
    tablespace_files       => tbs_files,
    converted_files        => cvt_files,
    tablespace_names       => ts_names);
  -- output names of imported tablespaces
  IF ts_names IS NOT NULL AND ts_names.first IS NOT NULL THEN
    FOR i IN ts_names.first .. ts_names.last LOOP
      dbms_output.put_line('imported tablespace '|| ts_names(i));
    END LOOP;
  END IF;
END;
/
-- dropping directory objects
DROP DIRECTORY STREAMS$DIROBJ$1;
DROP DIRECTORY STREAMS$DIROBJ$DPDIR;
--------------------------------------------------------------
-- End of sample PL/SQL script
--------------------------------------------------------------

Removing automatic instance
shutting down automatic instance
Oracle instance shut down
Automatic instance removed
auxiliary instance file /u02/transport/cntrl_tspitr_TEST_EmBb.f deleted
auxiliary instance file /u02/transport/TSPITR_TEST_EMBB/datafile/o1_mf_system_bkf6jddz_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_EMBB/datafile/o1_mf_undotbs1_bkf6jdmt_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_EMBB/datafile/o1_mf_sysaux_bkf6jdfc_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_EMBB/datafile/o1_mf_temp_bkf6owoz_.tmp deleted
auxiliary instance file /u02/transport/TSPITR_TEST_EMBB/onlinelog/o1_mf_1_bkf6o7p5_.log deleted
auxiliary instance file /u02/transport/TSPITR_TEST_EMBB/onlinelog/o1_mf_2_bkf6ochy_.log deleted
auxiliary instance file /u02/transport/TSPITR_TEST_EMBB/onlinelog/o1_mf_3_bkf6ogqc_.log deleted

执行表空间传输时为辅助数据文件设置新文件名(set newname)
可以在RUN块中使用set newname命令来为transport tablespace命令指定文件:


RMAN> run
2> {
3> set newname for datafile '/u01/app/oracle/oradata/test/tspitr01.dbf'
to '/u02/transport/tspitr01.dbf';
4> 5> set newname for datafile '/u01/app/oracle/oradata/test/test01.dbf'
6> to '/u02/transport/test01.dbf';
7> transport tablespace "TSPITR","TEST"
8> tablespace destination '/u02/transport'
9> auxiliary destination '/u02/transport' ;
10> }

executing command: SET NEWNAME

executing command: SET NEWNAME


Creating automatic instance, with SID='Fmly'
using contents of file /u02/initaux.ora

initialization parameters used for automatic instance:
db_name=TEST
compatible=10.2.0.5.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_TEST_Fmly
sga_target=180M
processes=50
ifile=/u02/initaux.ora
db_create_file_dest=/u02/transport
control_files=/u02/transport/cntrl_tspitr_TEST_Fmly.f


starting up automatic instance TEST

Oracle instance started

Total System Global Area     188743680 bytes

Fixed Size                     1272720 bytes
Variable Size                167773296 bytes
Database Buffers              16777216 bytes
Redo Buffers                   2920448 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until  scn 1204365;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log for tspitr to a resent until time
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
# resync catalog after controlfile restore
resync catalog;
}
executing Memory Script

executing command: SET until clause

Starting restore at 28-MAR-15
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=47 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u02/c-2168949517-20150326-07
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/c-2168949517-20150326-07 tag=TAG20150326T203351
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output filename=/u02/transport/cntrl_tspitr_TEST_Fmly.f
Finished restore at 28-MAR-15

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

starting full resync of recovery catalog
full resync complete

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  scn 1204365;
# set an omf destination filename for restore
set newname for clone datafile  1 to new;
# set an omf destination filename for restore
set newname for clone datafile  2 to new;
# set an omf destination filename for restore
set newname for clone datafile  3 to new;
# set an omf destination tempfile
set newname for clone tempfile  1 to new;
# set a destination filename for restore
set newname for datafile  6 to
 "/u02/transport/tspitr01.dbf";
# set a destination filename for restore
set newname for datafile  7 to
 "/u02/transport/test01.dbf";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 3, 6, 7;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile  1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  3 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  6 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  7 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  "TSPITR", "TEST", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
#           datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed temporary file 1 to /u02/transport/TSPITR_TEST_FMLY/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 28-MAR-15
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u02/transport/TSPITR_TEST_FMLY/datafile/o1_mf_system_%u_.dbf
restoring datafile 00002 to /u02/transport/TSPITR_TEST_FMLY/datafile/o1_mf_undotbs1_%u_.dbf
restoring datafile 00003 to /u02/transport/TSPITR_TEST_FMLY/datafile/o1_mf_sysaux_%u_.dbf
restoring datafile 00006 to /u02/transport/tspitr01.dbf
restoring datafile 00007 to /u02/transport/test01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875392350_1001
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875392350_1001 tag=TAG20150326T203229
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:26
Finished restore at 28-MAR-15

datafile 6 switched to datafile copy
input datafile copy recid=22 stamp=875564535 filename=/u02/transport/tspitr01.dbf
datafile 7 switched to datafile copy
input datafile copy recid=23 stamp=875564535 filename=/u02/transport/test01.dbf
datafile 1 switched to datafile copy
input datafile copy recid=24 stamp=875564535 filename=/u02/transport/TSPITR_TEST_FMLY/datafile/o1_mf_system_bkf7513q_.dbf
datafile 2 switched to datafile copy
input datafile copy recid=25 stamp=875564535 filename=/u02/transport/TSPITR_TEST_FMLY/datafile/o1_mf_undotbs1_bkf7514q_.dbf
datafile 3 switched to datafile copy
input datafile copy recid=26 stamp=875564535 filename=/u02/transport/TSPITR_TEST_FMLY/datafile/o1_mf_sysaux_bkf75143_.dbf

sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  6 online

sql statement: alter database datafile  7 online

Starting recover at 28-MAR-15
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 80 is already on disk as file /u02/1_80_870806981.dbf
archive log thread 1 sequence 81 is already on disk as file /u02/1_81_870806981.dbf
archive log thread 1 sequence 82 is already on disk as file /u02/1_82_870806981.dbf
archive log thread 1 sequence 83 is already on disk as file /u02/1_83_870806981.dbf
archive log thread 1 sequence 84 is already on disk as file /u02/1_84_870806981.dbf
archive log thread 1 sequence 85 is already on disk as file /u02/1_85_870806981.dbf
archive log thread 1 sequence 86 is already on disk as file /u02/1_86_870806981.dbf
archive log thread 1 sequence 87 is already on disk as file /u02/1_87_870806981.dbf
archive log thread 1 sequence 88 is already on disk as file /u02/1_88_870806981.dbf
archive log thread 1 sequence 89 is already on disk as file /u02/1_89_870806981.dbf
archive log thread 1 sequence 90 is already on disk as file /u02/1_90_870806981.dbf
archive log filename=/u02/1_80_870806981.dbf thread=1 sequence=80
archive log filename=/u02/1_81_870806981.dbf thread=1 sequence=81
archive log filename=/u02/1_82_870806981.dbf thread=1 sequence=82
archive log filename=/u02/1_83_870806981.dbf thread=1 sequence=83
archive log filename=/u02/1_84_870806981.dbf thread=1 sequence=84
archive log filename=/u02/1_85_870806981.dbf thread=1 sequence=85
archive log filename=/u02/1_86_870806981.dbf thread=1 sequence=86
archive log filename=/u02/1_87_870806981.dbf thread=1 sequence=87
archive log filename=/u02/1_88_870806981.dbf thread=1 sequence=88
archive log filename=/u02/1_89_870806981.dbf thread=1 sequence=89
archive log filename=/u02/1_90_870806981.dbf thread=1 sequence=90
media recovery complete, elapsed time: 00:00:56
Finished recover at 28-MAR-15

database opened

contents of Memory Script:
{
#mark read only the tablespace that will be exported
sql clone "alter tablespace TSPITR read only";
#mark read only the tablespace that will be exported
sql clone "alter tablespace TEST read only";
# create directory for datapump export
sql clone "create or replace directory STREAMS_DIROBJ_DPDIR as ''
/u02/transport''";
# export the tablespaces in the recovery set
host 'expdp userid=\"/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle\)\(ARGV0=oracleFmly\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=Fmly^'\)\)\(CONNECT_DATA=\(SID=Fmly\)\)\) as sysdba\" transport_tablespaces=
 TSPITR,
 TEST dumpfile=
dmpfile.dmp directory=
STREAMS_DIROBJ_DPDIR logfile=
explog.log';
}
executing Memory Script

sql statement: alter tablespace TSPITR read only

sql statement: alter tablespace TEST read only

sql statement: create or replace directory STREAMS_DIROBJ_DPDIR as ''/u02/transport''


Export: Release 10.2.0.5.0 - Production on Saturday, 28 March, 2015 20:23:43

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TRANSPORTABLE_01":  userid="/********@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle)(ARGV0=oracleFmly)(ARGS=\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\))(ENVS=ORACLE_SID=Fmly))(CONNECT_DATA=(SID=Fmly))) AS SYSDBA" transport_tablespaces= TSPITR, TEST dumpfile=dmpfile.dmp directory=STREAMS_DIROBJ_DPDIR logfile=explog.log
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
Master table "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TRANSPORTABLE_01 is:
  /u02/transport/dmpfile.dmp
Job "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 20:24:34

host command complete
/*
   The following command may be used to import the tablespaces.
   Substitute values for  and .
   impdp  directory= dumpfile= 'dmpfile.dmp' transport_datafiles= /u02/transport/tspitr01.dbf, /u02/transport/test01.dbf
*/
--------------------------------------------------------------
-- Start of sample PL/SQL script for importing the tablespaces
--------------------------------------------------------------
-- creating directory objects
CREATE DIRECTORY STREAMS$DIROBJ$1 AS  '/u02/transport/';
CREATE DIRECTORY STREAMS$DIROBJ$DPDIR AS  '/u02/transport';
/* PL/SQL Script to import the exported tablespaces */
DECLARE
  -- the datafiles
  tbs_files     dbms_streams_tablespace_adm.file_set;
  cvt_files     dbms_streams_tablespace_adm.file_set;
  -- the dumpfile to import
  dump_file     dbms_streams_tablespace_adm.file;
  dp_job_name   VARCHAR2(30) := NULL;
  -- names of tablespaces that were imported
  ts_names       dbms_streams_tablespace_adm.tablespace_set;
BEGIN
  -- dump file name and location
  dump_file.file_name :=  'dmpfile.dmp';
  dump_file.directory_object := 'STREAMS$DIROBJ$DPDIR';
  -- forming list of datafiles for import
  tbs_files( 1).file_name :=  'tspitr01.dbf';
  tbs_files( 1).directory_object :=  'STREAMS$DIROBJ$1';
  tbs_files( 2).file_name :=  'test01.dbf';
  tbs_files( 2).directory_object :=  'STREAMS$DIROBJ$1';
  -- import tablespaces
  dbms_streams_tablespace_adm.attach_tablespaces(
    datapump_job_name      => dp_job_name,
    dump_file              => dump_file,
    tablespace_files       => tbs_files,
    converted_files        => cvt_files,
    tablespace_names       => ts_names);
  -- output names of imported tablespaces
  IF ts_names IS NOT NULL AND ts_names.first IS NOT NULL THEN
    FOR i IN ts_names.first .. ts_names.last LOOP
      dbms_output.put_line('imported tablespace '|| ts_names(i));
    END LOOP;
  END IF;
END;
/
-- dropping directory objects
DROP DIRECTORY STREAMS$DIROBJ$1;
DROP DIRECTORY STREAMS$DIROBJ$DPDIR;
--------------------------------------------------------------
-- End of sample PL/SQL script
--------------------------------------------------------------

Removing automatic instance
shutting down automatic instance
Oracle instance shut down
Automatic instance removed
auxiliary instance file /u02/transport/cntrl_tspitr_TEST_Fmly.f deleted
auxiliary instance file /u02/transport/TSPITR_TEST_FMLY/datafile/o1_mf_system_bkf7513q_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_FMLY/datafile/o1_mf_undotbs1_bkf7514q_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_FMLY/datafile/o1_mf_sysaux_bkf75143_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_FMLY/datafile/o1_mf_temp_bkf79xd1_.tmp deleted
auxiliary instance file /u02/transport/TSPITR_TEST_FMLY/onlinelog/o1_mf_1_bkf79khg_.log deleted
auxiliary instance file /u02/transport/TSPITR_TEST_FMLY/onlinelog/o1_mf_2_bkf79ncf_.log deleted
auxiliary instance file /u02/transport/TSPITR_TEST_FMLY/onlinelog/o1_mf_3_bkf79q23_.log deleted

执行表空间传输时为辅助数据文件设置新文件名(configure auxname)
可以在RUN块中使用configure auxname命令来为辅助数据文件指定持久的存储目录:

RMAN> run
2> {
3> configure auxname for datafile '/u01/app/oracle/oradata/test/tspitr01.dbf'
4> to '/u02/transport/tspitr01.dbf';
5> configure auxname for datafile '/u01/app/oracle/oradata/test/test01.dbf'
6> to '/u02/transport/test01.dbf';
7> transport tablespace "TSPITR","TEST"
8> tablespace destination '/u02/transport'
9> auxiliary destination '/u02/transport' ;
10> }

auxiliary name for datafile 6 set to: /u02/transport/tspitr01.dbf
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

auxiliary name for datafile 7 set to: /u02/transport/test01.dbf
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete


Creating automatic instance, with SID='qsdg'
using contents of file /u02/initaux.ora

initialization parameters used for automatic instance:
db_name=TEST
compatible=10.2.0.5.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_TEST_qsdg
sga_target=180M
processes=50
ifile=/u02/initaux.ora
db_create_file_dest=/u02/transport
control_files=/u02/transport/cntrl_tspitr_TEST_qsdg.f


starting up automatic instance TEST

Oracle instance started

Total System Global Area     188743680 bytes

Fixed Size                     1272720 bytes
Variable Size                167773296 bytes
Database Buffers              16777216 bytes
Redo Buffers                   2920448 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until  scn 1204735;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log for tspitr to a resent until time
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
# resync catalog after controlfile restore
resync catalog;
}
executing Memory Script

executing command: SET until clause

Starting restore at 28-MAR-15
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=47 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u02/c-2168949517-20150326-07
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/c-2168949517-20150326-07 tag=TAG20150326T203351
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
output filename=/u02/transport/cntrl_tspitr_TEST_qsdg.f
Finished restore at 28-MAR-15

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

starting full resync of recovery catalog
full resync complete

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  scn 1204735;
# set an omf destination filename for restore
set newname for clone datafile  1 to new;
# set an omf destination filename for restore
set newname for clone datafile  2 to new;
# set an omf destination filename for restore
set newname for clone datafile  3 to new;
# set an omf destination tempfile
set newname for clone tempfile  1 to new;
# set a destination filename for restore
set newname for datafile  6 to
 "/u02/transport/tspitr01.dbf";
# set a destination filename for restore
set newname for datafile  7 to
 "/u02/transport/test01.dbf";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 3, 6, 7;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile  1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  3 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  6 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  7 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  "TSPITR", "TEST", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
#           datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed temporary file 1 to /u02/transport/TSPITR_TEST_QSDG/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 28-MAR-15
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u02/transport/TSPITR_TEST_QSDG/datafile/o1_mf_system_%u_.dbf
restoring datafile 00002 to /u02/transport/TSPITR_TEST_QSDG/datafile/o1_mf_undotbs1_%u_.dbf
restoring datafile 00003 to /u02/transport/TSPITR_TEST_QSDG/datafile/o1_mf_sysaux_%u_.dbf
restoring datafile 00006 to /u02/transport/tspitr01.dbf
restoring datafile 00007 to /u02/transport/test01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875392350_1001
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875392350_1001 tag=TAG20150326T203229
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:25
Finished restore at 28-MAR-15

datafile 1 switched to datafile copy
input datafile copy recid=22 stamp=875565174 filename=/u02/transport/TSPITR_TEST_QSDG/datafile/o1_mf_system_bkf7s1mn_.dbf
datafile 2 switched to datafile copy
input datafile copy recid=23 stamp=875565174 filename=/u02/transport/TSPITR_TEST_QSDG/datafile/o1_mf_undotbs1_bkf7s1n9_.dbf
datafile 3 switched to datafile copy
input datafile copy recid=24 stamp=875565174 filename=/u02/transport/TSPITR_TEST_QSDG/datafile/o1_mf_sysaux_bkf7s1mz_.dbf
datafile 6 switched to datafile copy
input datafile copy recid=25 stamp=875565174 filename=/u02/transport/tspitr01.dbf
datafile 7 switched to datafile copy
input datafile copy recid=26 stamp=875565174 filename=/u02/transport/test01.dbf

sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  6 online

sql statement: alter database datafile  7 online

Starting recover at 28-MAR-15
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 80 is already on disk as file /u02/1_80_870806981.dbf
archive log thread 1 sequence 81 is already on disk as file /u02/1_81_870806981.dbf
archive log thread 1 sequence 82 is already on disk as file /u02/1_82_870806981.dbf
archive log thread 1 sequence 83 is already on disk as file /u02/1_83_870806981.dbf
archive log thread 1 sequence 84 is already on disk as file /u02/1_84_870806981.dbf
archive log thread 1 sequence 85 is already on disk as file /u02/1_85_870806981.dbf
archive log thread 1 sequence 86 is already on disk as file /u02/1_86_870806981.dbf
archive log thread 1 sequence 87 is already on disk as file /u02/1_87_870806981.dbf
archive log thread 1 sequence 88 is already on disk as file /u02/1_88_870806981.dbf
archive log thread 1 sequence 89 is already on disk as file /u02/1_89_870806981.dbf
archive log thread 1 sequence 90 is already on disk as file /u02/1_90_870806981.dbf
archive log thread 1 sequence 91 is already on disk as file /u02/1_91_870806981.dbf
archive log filename=/u02/1_80_870806981.dbf thread=1 sequence=80
archive log filename=/u02/1_81_870806981.dbf thread=1 sequence=81
archive log filename=/u02/1_82_870806981.dbf thread=1 sequence=82
archive log filename=/u02/1_83_870806981.dbf thread=1 sequence=83
archive log filename=/u02/1_84_870806981.dbf thread=1 sequence=84
archive log filename=/u02/1_85_870806981.dbf thread=1 sequence=85
archive log filename=/u02/1_86_870806981.dbf thread=1 sequence=86
archive log filename=/u02/1_87_870806981.dbf thread=1 sequence=87
archive log filename=/u02/1_88_870806981.dbf thread=1 sequence=88
archive log filename=/u02/1_89_870806981.dbf thread=1 sequence=89
archive log filename=/u02/1_90_870806981.dbf thread=1 sequence=90
archive log filename=/u02/1_91_870806981.dbf thread=1 sequence=91
media recovery complete, elapsed time: 00:01:03
Finished recover at 28-MAR-15

database opened

contents of Memory Script:
{
#mark read only the tablespace that will be exported
sql clone "alter tablespace TSPITR read only";
#mark read only the tablespace that will be exported
sql clone "alter tablespace TEST read only";
# create directory for datapump export
sql clone "create or replace directory STREAMS_DIROBJ_DPDIR as ''
/u02/transport''";
# export the tablespaces in the recovery set
host 'expdp userid=\"/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle\)\(ARGV0=oracleqsdg\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=qsdg^'\)\)\(CONNECT_DATA=\(SID=qsdg\)\)\) as sysdba\" transport_tablespaces=
 TSPITR,
 TEST dumpfile=
dmpfile.dmp directory=
STREAMS_DIROBJ_DPDIR logfile=
explog.log';
}
executing Memory Script

sql statement: alter tablespace TSPITR read only

sql statement: alter tablespace TEST read only

sql statement: create or replace directory STREAMS_DIROBJ_DPDIR as ''/u02/transport''


Export: Release 10.2.0.5.0 - Production on Saturday, 28 March, 2015 20:34:37

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TRANSPORTABLE_01":  userid="/********@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle)(ARGV0=oracleqsdg)(ARGS=\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\))(ENVS=ORACLE_SID=qsdg))(CONNECT_DATA=(SID=qsdg))) AS SYSDBA" transport_tablespaces= TSPITR, TEST dumpfile=dmpfile.dmp directory=STREAMS_DIROBJ_DPDIR logfile=explog.log
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
Master table "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TRANSPORTABLE_01 is:
  /u02/transport/dmpfile.dmp
Job "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 20:35:50

host command complete
/*
   The following command may be used to import the tablespaces.
   Substitute values for  and .
   impdp  directory= dumpfile= 'dmpfile.dmp' transport_datafiles= /u02/transport/tspitr01.dbf, /u02/transport/test01.dbf
*/
--------------------------------------------------------------
-- Start of sample PL/SQL script for importing the tablespaces
--------------------------------------------------------------
-- creating directory objects
CREATE DIRECTORY STREAMS$DIROBJ$1 AS  '/u02/transport/';
CREATE DIRECTORY STREAMS$DIROBJ$DPDIR AS  '/u02/transport';
/* PL/SQL Script to import the exported tablespaces */
DECLARE
  -- the datafiles
  tbs_files     dbms_streams_tablespace_adm.file_set;
  cvt_files     dbms_streams_tablespace_adm.file_set;
  -- the dumpfile to import
  dump_file     dbms_streams_tablespace_adm.file;
  dp_job_name   VARCHAR2(30) := NULL;
  -- names of tablespaces that were imported
  ts_names       dbms_streams_tablespace_adm.tablespace_set;
BEGIN
  -- dump file name and location
  dump_file.file_name :=  'dmpfile.dmp';
  dump_file.directory_object := 'STREAMS$DIROBJ$DPDIR';
  -- forming list of datafiles for import
  tbs_files( 1).file_name :=  'tspitr01.dbf';
  tbs_files( 1).directory_object :=  'STREAMS$DIROBJ$1';
  tbs_files( 2).file_name :=  'test01.dbf';
  tbs_files( 2).directory_object :=  'STREAMS$DIROBJ$1';
  -- import tablespaces
  dbms_streams_tablespace_adm.attach_tablespaces(
    datapump_job_name      => dp_job_name,
    dump_file              => dump_file,
    tablespace_files       => tbs_files,
    converted_files        => cvt_files,
    tablespace_names       => ts_names);
  -- output names of imported tablespaces
  IF ts_names IS NOT NULL AND ts_names.first IS NOT NULL THEN
    FOR i IN ts_names.first .. ts_names.last LOOP
      dbms_output.put_line('imported tablespace '|| ts_names(i));
    END LOOP;
  END IF;
END;
/
-- dropping directory objects
DROP DIRECTORY STREAMS$DIROBJ$1;
DROP DIRECTORY STREAMS$DIROBJ$DPDIR;
--------------------------------------------------------------
-- End of sample PL/SQL script
--------------------------------------------------------------

Removing automatic instance
shutting down automatic instance
Oracle instance shut down
Automatic instance removed
auxiliary instance file /u02/transport/cntrl_tspitr_TEST_qsdg.f deleted
auxiliary instance file /u02/transport/TSPITR_TEST_QSDG/datafile/o1_mf_system_bkf7s1mn_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_QSDG/datafile/o1_mf_undotbs1_bkf7s1n9_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_QSDG/datafile/o1_mf_sysaux_bkf7s1mz_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_QSDG/datafile/o1_mf_temp_bkf7ycqg_.tmp deleted
auxiliary instance file /u02/transport/TSPITR_TEST_QSDG/onlinelog/o1_mf_1_bkf7xw77_.log deleted
auxiliary instance file /u02/transport/TSPITR_TEST_QSDG/onlinelog/o1_mf_2_bkf7xz96_.log deleted
auxiliary instance file /u02/transport/TSPITR_TEST_QSDG/onlinelog/o1_mf_3_bkf7y29x_.log deleted

使用初始化参数来对传输表空间命名辅助数据文件
可以在辅助实例参数文件中使用log_file_name_convert和db_file_name_convert参数来控制辅助实例的联机重做日志和其它数据文件的文件名

[oracle@oracle11g u02]$ vi initaux.ora

shared_pool_size=150M
control_files=('/u02/transport/control01.ctl')
db_file_name_convert=('/u01/app/oracle/oradata/test/','/u02/transport/')
log_file_name_convert=('/u01/app/oracle/oradata/test/','/u02/transport/')

RMAN> run
2> {
3> set auxiliary instance parameter file to '/u02/initaux.ora';
4> transport tablespace "TSPITR","TEST"
5> tablespace destination '/u02/transport';
}6>

executing command: SET auxiliary parameter file


Creating automatic instance, with SID='psnl'
using contents of file /u02/initaux.ora

initialization parameters used for automatic instance:
db_name=TEST
compatible=10.2.0.5.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_TEST_psnl
sga_target=180M
processes=50
ifile=/u02/initaux.ora
#No auxiliary destination in use
#Use default controlfile


starting up automatic instance TEST

Oracle instance started

Total System Global Area     188743680 bytes

Fixed Size                     1272720 bytes
Variable Size                167773296 bytes
Database Buffers              16777216 bytes
Redo Buffers                   2920448 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until  scn 1205073;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log for tspitr to a resent until time
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
# resync catalog after controlfile restore
resync catalog;
}
executing Memory Script

executing command: SET until clause

Starting restore at 28-MAR-15
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=47 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u02/c-2168949517-20150326-07
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/c-2168949517-20150326-07 tag=TAG20150326T203351
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
output filename=/u02/transport/control01.ctl
Finished restore at 28-MAR-15

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

starting full resync of recovery catalog
full resync complete

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  scn 1205073;
# set a destination filename for restore
set newname for datafile  1 to
 "/u02/transport/system01.dbf";
# set a destination filename for restore
set newname for datafile  2 to
 "/u02/transport/undotbs01.dbf";
# set a destination filename for restore
set newname for datafile  3 to
 "/u02/transport/sysaux01.dbf";
# set a destination tempfile
set newname for tempfile  1 to
 "/u02/transport/temp01.dbf";
# set a destination filename for restore
set newname for datafile  6 to
 "/u02/transport/tspitr01.dbf";
# set a destination filename for restore
set newname for datafile  7 to
 "/u02/transport/test01.dbf";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 3, 6, 7;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile  1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  3 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  6 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  7 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  "TSPITR", "TEST", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
#           datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME


Starting restore at 28-MAR-15
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u02/transport/system01.dbf
restoring datafile 00002 to /u02/transport/undotbs01.dbf
restoring datafile 00003 to /u02/transport/sysaux01.dbf
restoring datafile 00006 to /u02/transport/tspitr01.dbf
restoring datafile 00007 to /u02/transport/test01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875392350_1001
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875392350_1001 tag=TAG20150326T203229
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:45
Finished restore at 28-MAR-15


sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  6 online

sql statement: alter database datafile  7 online

Starting recover at 28-MAR-15
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 80 is already on disk as file /u02/1_80_870806981.dbf
archive log thread 1 sequence 81 is already on disk as file /u02/1_81_870806981.dbf
archive log thread 1 sequence 82 is already on disk as file /u02/1_82_870806981.dbf
archive log thread 1 sequence 83 is already on disk as file /u02/1_83_870806981.dbf
archive log thread 1 sequence 84 is already on disk as file /u02/1_84_870806981.dbf
archive log thread 1 sequence 85 is already on disk as file /u02/1_85_870806981.dbf
archive log thread 1 sequence 86 is already on disk as file /u02/1_86_870806981.dbf
archive log thread 1 sequence 87 is already on disk as file /u02/1_87_870806981.dbf
archive log thread 1 sequence 88 is already on disk as file /u02/1_88_870806981.dbf
archive log thread 1 sequence 89 is already on disk as file /u02/1_89_870806981.dbf
archive log thread 1 sequence 90 is already on disk as file /u02/1_90_870806981.dbf
archive log thread 1 sequence 91 is already on disk as file /u02/1_91_870806981.dbf
archive log thread 1 sequence 92 is already on disk as file /u02/1_92_870806981.dbf
archive log filename=/u02/1_80_870806981.dbf thread=1 sequence=80
archive log filename=/u02/1_81_870806981.dbf thread=1 sequence=81
archive log filename=/u02/1_82_870806981.dbf thread=1 sequence=82
archive log filename=/u02/1_83_870806981.dbf thread=1 sequence=83
archive log filename=/u02/1_84_870806981.dbf thread=1 sequence=84
archive log filename=/u02/1_85_870806981.dbf thread=1 sequence=85
archive log filename=/u02/1_86_870806981.dbf thread=1 sequence=86
archive log filename=/u02/1_87_870806981.dbf thread=1 sequence=87
archive log filename=/u02/1_88_870806981.dbf thread=1 sequence=88
archive log filename=/u02/1_89_870806981.dbf thread=1 sequence=89
archive log filename=/u02/1_90_870806981.dbf thread=1 sequence=90
archive log filename=/u02/1_91_870806981.dbf thread=1 sequence=91
archive log filename=/u02/1_92_870806981.dbf thread=1 sequence=92
media recovery complete, elapsed time: 00:01:06
Finished recover at 28-MAR-15

database opened

contents of Memory Script:
{
#mark read only the tablespace that will be exported
sql clone "alter tablespace TSPITR read only";
#mark read only the tablespace that will be exported
sql clone "alter tablespace TEST read only";
# create directory for datapump export
sql clone "create or replace directory STREAMS_DIROBJ_DPDIR as ''
/u02/transport''";
# export the tablespaces in the recovery set
host 'expdp userid=\"/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle\)\(ARGV0=oraclepsnl\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=psnl^'\)\)\(CONNECT_DATA=\(SID=psnl\)\)\) as sysdba\" transport_tablespaces=
 TSPITR,
 TEST dumpfile=
dmpfile.dmp directory=
STREAMS_DIROBJ_DPDIR logfile=
explog.log';
}
executing Memory Script

sql statement: alter tablespace TSPITR read only

sql statement: alter tablespace TEST read only

sql statement: create or replace directory STREAMS_DIROBJ_DPDIR as ''/u02/transport''


Export: Release 10.2.0.5.0 - Production on Saturday, 28 March, 2015 20:48:44

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TRANSPORTABLE_01":  userid="/********@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle)(ARGV0=oraclepsnl)(ARGS=\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\))(ENVS=ORACLE_SID=psnl))(CONNECT_DATA=(SID=psnl))) AS SYSDBA" transport_tablespaces= TSPITR, TEST dumpfile=dmpfile.dmp directory=STREAMS_DIROBJ_DPDIR logfile=explog.log
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
Master table "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TRANSPORTABLE_01 is:
  /u02/transport/dmpfile.dmp
Job "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 20:49:41

host command complete
/*
   The following command may be used to import the tablespaces.
   Substitute values for  and .
   impdp  directory= dumpfile= 'dmpfile.dmp' transport_datafiles= /u02/transport/tspitr01.dbf, /u02/transport/test01.dbf
*/
--------------------------------------------------------------
-- Start of sample PL/SQL script for importing the tablespaces
--------------------------------------------------------------
-- creating directory objects
CREATE DIRECTORY STREAMS$DIROBJ$1 AS  '/u02/transport/';
CREATE DIRECTORY STREAMS$DIROBJ$DPDIR AS  '/u02/transport';
/* PL/SQL Script to import the exported tablespaces */
DECLARE
  -- the datafiles
  tbs_files     dbms_streams_tablespace_adm.file_set;
  cvt_files     dbms_streams_tablespace_adm.file_set;
  -- the dumpfile to import
  dump_file     dbms_streams_tablespace_adm.file;
  dp_job_name   VARCHAR2(30) := NULL;
  -- names of tablespaces that were imported
  ts_names       dbms_streams_tablespace_adm.tablespace_set;
BEGIN
  -- dump file name and location
  dump_file.file_name :=  'dmpfile.dmp';
  dump_file.directory_object := 'STREAMS$DIROBJ$DPDIR';
  -- forming list of datafiles for import
  tbs_files( 1).file_name :=  'tspitr01.dbf';
  tbs_files( 1).directory_object :=  'STREAMS$DIROBJ$1';
  tbs_files( 2).file_name :=  'test01.dbf';
  tbs_files( 2).directory_object :=  'STREAMS$DIROBJ$1';
  -- import tablespaces
  dbms_streams_tablespace_adm.attach_tablespaces(
    datapump_job_name      => dp_job_name,
    dump_file              => dump_file,
    tablespace_files       => tbs_files,
    converted_files        => cvt_files,
    tablespace_names       => ts_names);
  -- output names of imported tablespaces
  IF ts_names IS NOT NULL AND ts_names.first IS NOT NULL THEN
    FOR i IN ts_names.first .. ts_names.last LOOP
      dbms_output.put_line('imported tablespace '|| ts_names(i));
    END LOOP;
  END IF;
END;
/
-- dropping directory objects
DROP DIRECTORY STREAMS$DIROBJ$1;
DROP DIRECTORY STREAMS$DIROBJ$DPDIR;
--------------------------------------------------------------
-- End of sample PL/SQL script
--------------------------------------------------------------

Removing automatic instance
shutting down automatic instance
Oracle instance shut down
Automatic instance removed
auxiliary instance file /u02/transport/control01.ctl deleted
auxiliary instance file /u02/transport/system01.dbf deleted
auxiliary instance file /u02/transport/undotbs01.dbf deleted
auxiliary instance file /u02/transport/sysaux01.dbf deleted
auxiliary instance file /u02/transport/temp01.dbf deleted
auxiliary instance file /u02/transport/redo01.log deleted
auxiliary instance file /u02/transport/redo02.log deleted
auxiliary instance file /u02/transport/redo03.log deleted

RMAN使用备份按时间点传输表空间

使用until time或者SCN来执行transport tablespace
如果在执行传输表空间操作时,对transport tablespace命令指定了目标时间,那么RMAN将在辅助实例中使用备份将表空间还原到目标时间之前并执行按时间点恢复将辅助数据库恢复到指定的目标时间点。(对于按时间点恢复所需要的备份和重做日志必须可以使用)
恢复的目标时间可以使用SCN(包括当前incarnation或ancestors incarnation),日志序列号,还原点或时间表达式。

使用SCN来执行transport tablespace
1.确认源数据库与目标数据库所在平台是不是传输表空间所支持的操作系统平台。确认源数据库操作系统平台:

SQL> select d.platform_name,endian_format from v$transportable_platform tp,v$database d
  2  where tp.platform_name=d.platform_name ;

PLATFORM_NAME                                                                                         ENDIAN_FORMAT
----------------------------------------------------------------------------------------------------- --------------
Linux IA (32-bit)                                                                                     Little

确认目数据库操作系统平台:

SQL> select d.platform_name,endian_format from v$transportable_platform tp,v$database d
  2  where tp.platform_name=d.platform_name ;

PLATFORM_NAME                                                                                         ENDIAN_FORMAT
----------------------------------------------------------------------------------------------------- --------------
Linux IA (32-bit)                                                                                     Little

这里操作系统平台都是Linux

2.确认要被传输的表空间是否是自包含表空间(TSPITR,TEST):

SQL> exec sys.dbms_tts.transport_set_check('TSPITR',true);

PL/SQL procedure successfully completed.


SQL> exec sys.dbms_tts.transport_set_check('TEST',true);

PL/SQL procedure successfully completed.

SQL> select * from sys.transport_set_violations;

no rows selected

如果没有行选择,表示该表空间只包含表数据,可以传输。

修改表tspitr与test中的记录,在修改之前记录当前的SCN,在执行传输表空间时指定这个SCN

SQL> conn tspitr/tspitr
Connected.
SQL> select current_scn from v$database;

CURRENT_SCN
-----------
    1167731

SQL> select to_char(scn_to_timestamp(1167731),'yyyy-mm-dd hh24:mi:ss') from dual;

TO_CHAR(SCN_TO_TIME
-------------------
2015-03-27 16:48:29


SQL> insert into tspitr select * from tspitr;

50641 rows created.

SQL> commit;

Commit complete.

SQL> select count(*) from tspitr

  COUNT(*)
----------
    101282


SQL> conn test/test
Connected.
SQL> select count(*) from test;

  COUNT(*)
----------
     50680
SQL> delete from test;

50680 rows deleted.

SQL> commit;

Commit complete.

SQL> select count(*) from test;

  COUNT(*)
----------
         0

在SCN=1167731之后,表tspitr中的记录数为101282,表test的记录数为0,SCN=1167731之前,表tspitr中的记录数为50641,表test的记录数为50680

3.对源数据库执行备份,在执行备份时一定要加上include current controlfile否则执行transport tablespace命令时会出现以下错误信息:

Automatic instance removed
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of tranport tablespace command at 03/26/2015 20:24:22
RMAN-03015: error occurred in stored script Memory Script
RMAN-06026: some targets not found - aborting restore
RMAN-06024: no backup or copy of the control file found to restore


[oracle@oracle11g admin]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@oracle11g admin]$ rman target sys/zzh_2046@test  catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Thu Mar 26 20:01:33 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database

RMAN> backup as backupset database include current controlfile plus archivelog;


Starting backup at 2015-03-26 20:32:19
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=68 recid=75 stamp=875286167
input archive log thread=1 sequence=69 recid=76 stamp=875291999
input archive log thread=1 sequence=70 recid=77 stamp=875302397
input archive log thread=1 sequence=71 recid=78 stamp=875308491
input archive log thread=1 sequence=72 recid=79 stamp=875350203
input archive log thread=1 sequence=73 recid=80 stamp=875351397
input archive log thread=1 sequence=74 recid=81 stamp=875390545
input archive log thread=1 sequence=75 recid=82 stamp=875390643
input archive log thread=1 sequence=76 recid=83 stamp=875391627
input archive log thread=1 sequence=77 recid=84 stamp=875391661
input archive log thread=1 sequence=78 recid=85 stamp=875391764
input archive log thread=1 sequence=79 recid=86 stamp=875392340
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:32:22
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:32:29
piece handle=/u02/ora_test875392341_991 tag=TAG20150326T203220 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:08
Finished backup at 2015-03-26 20:32:29

Starting backup at 2015-03-26 20:32:29
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/test/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/test/example01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/test/tspitr01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/test/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/test/users01.dbf
input datafile fno=00007 name=/u01/app/oracle/oradata/test/test01.dbf
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:32:30
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:33:45
piece handle=/u02/ora_test875392350_1001 tag=TAG20150326T203229 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:33:46
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:33:47
piece handle=/u02/ora_test875392425_1011 tag=TAG20150326T203229 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 2015-03-26 20:33:47

Starting backup at 2015-03-26 20:33:47
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=80 recid=87 stamp=875392427
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:33:49
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:33:50
piece handle=/u02/ora_test875392428_1021 tag=TAG20150326T203348 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 2015-03-26 20:33:50

Starting Control File and SPFILE Autobackup at 2015-03-26 20:33:50
piece handle=/u02/c-2168949517-20150326-07 comment=NONE
Finished Control File and SPFILE Autobackup at 2015-03-26 20:33:54

RMAN> list backup;


List of Backup Sets
===================

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
6565    56.14M     DISK        00:00:07     2015-03-26 20:32:28
        BP Key: 6566   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203220
        Piece Name: /u02/ora_test875392341_991

  List of Archived Logs in backup set 6565
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    68      1040304    2015-03-25 09:33:41 1064641    2015-03-25 15:02:45
  1    69      1064641    2015-03-25 15:02:45 1067420    2015-03-25 16:39:58
  1    70      1067420    2015-03-25 16:39:58 1090668    2015-03-25 19:33:17
  1    71      1090668    2015-03-25 19:33:17 1093434    2015-03-25 21:14:51
  1    72      1093434    2015-03-25 21:14:51 1125870    2015-03-26 08:50:00
  1    73      1125870    2015-03-26 08:50:00 1126817    2015-03-26 09:09:56
  1    74      1126817    2015-03-26 09:09:56 1144051    2015-03-26 20:02:21
  1    75      1144051    2015-03-26 20:02:21 1144106    2015-03-26 20:04:02
  1    76      1144106    2015-03-26 20:04:02 1144862    2015-03-26 20:20:27
  1    77      1144862    2015-03-26 20:20:27 1144893    2015-03-26 20:21:00
  1    78      1144893    2015-03-26 20:21:00 1144980    2015-03-26 20:22:44
  1    79      1144980    2015-03-26 20:22:44 1145259    2015-03-26 20:32:19

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6607    Full    640.39M    DISK        00:01:08     2015-03-26 20:33:38
        BP Key: 6621   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203229
        Piece Name: /u02/ora_test875392350_1001
  List of Datafiles in backup set 6607
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  1       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/system01.dbf
  2       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/undotbs01.dbf
  3       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/sysaux01.dbf
  4       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/users01.dbf
  5       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/example01.dbf
  6       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/tspitr01.dbf
  7       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/test01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6608    Full    7.02M      DISK        00:00:01     2015-03-26 20:33:46
        BP Key: 6622   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203229
        Piece Name: /u02/ora_test875392425_1011
  Control File Included: Ckp SCN: 1145304      Ckp time: 2015-03-26 20:33:45

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
6658    2.50K      DISK        00:00:01     2015-03-26 20:33:49
        BP Key: 6660   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203348
        Piece Name: /u02/ora_test875392428_1021

  List of Archived Logs in backup set 6658
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    80      1145259    2015-03-26 20:32:19 1145307    2015-03-26 20:33:47

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6689    Full    7.05M      DISK        00:00:01     2015-03-26 20:33:52
        BP Key: 6691   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203351
        Piece Name: /u02/c-2168949517-20150326-07
  Control File Included: Ckp SCN: 1145329      Ckp time: 2015-03-26 20:33:51
  SPFILE Included: Modification time: 2015-03-26 19:31:13

4.在这里指定了auxiliary destination子句让RMAN使用缺省值来管理辅助实例。只指定必须的选项。Oracle建议transport tablespace命令使用辅助目录秋简化辅助实例文件的管理。下面来执transport tablespace命令来传输tspitr,test两个表空间:

[oracle@oracle11g ~]$ export NLS_DATE_FORMATE='yyyy-mm-dd hh24:mi:ss';
[oracle@oracle11g ~]$ rman target sys/zzh_2046@test catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Fri Mar 27 17:09:07 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database

RMAN> transport tablespace "TSPITR","TEST" tablespace destination '/u02/transport' auxiliary destination '/u02/transport' until scn 1167731;


Creating automatic instance, with SID='kayd'

initialization parameters used for automatic instance:
db_name=TEST
compatible=10.2.0.5.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_TEST_kayd
sga_target=180M
processes=50
#No auxiliary parameter file used
db_create_file_dest=/u02/transport
control_files=/u02/transport/cntrl_tspitr_TEST_kayd.f


starting up automatic instance TEST

Oracle instance started

Total System Global Area     188743680 bytes

Fixed Size                     1272720 bytes
Variable Size                 62915696 bytes
Database Buffers             121634816 bytes
Redo Buffers                   2920448 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until  scn 1167731;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log for tspitr to a resent until time
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
# resync catalog after controlfile restore
resync catalog;
}
executing Memory Script

executing command: SET until clause

Starting restore at 27-MAR-15
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=47 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u02/c-2168949517-20150326-07
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/c-2168949517-20150326-07 tag=TAG20150326T203351
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output filename=/u02/transport/cntrl_tspitr_TEST_kayd.f
Finished restore at 27-MAR-15

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

starting full resync of recovery catalog
full resync complete

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  scn 1167731;
# set an omf destination filename for restore
set newname for clone datafile  1 to new;
# set an omf destination filename for restore
set newname for clone datafile  2 to new;
# set an omf destination filename for restore
set newname for clone datafile  3 to new;
# set an omf destination tempfile
set newname for clone tempfile  1 to new;
# set a destination filename for restore
set newname for datafile  6 to
 "/u02/transport/tspitr01.dbf";
# set a destination filename for restore
set newname for datafile  7 to
 "/u02/transport/test01.dbf";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 3, 6, 7;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile  1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  3 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  6 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  7 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  "TSPITR", "TEST", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
#           datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed temporary file 1 to /u02/transport/TSPITR_TEST_KAYD/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 27-MAR-15
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u02/transport/TSPITR_TEST_KAYD/datafile/o1_mf_system_%u_.dbf
restoring datafile 00002 to /u02/transport/TSPITR_TEST_KAYD/datafile/o1_mf_undotbs1_%u_.dbf
restoring datafile 00003 to /u02/transport/TSPITR_TEST_KAYD/datafile/o1_mf_sysaux_%u_.dbf
restoring datafile 00006 to /u02/transport/tspitr01.dbf
restoring datafile 00007 to /u02/transport/test01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875392350_1001
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875392350_1001 tag=TAG20150326T203229
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:02:05
Finished restore at 27-MAR-15

datafile 1 switched to datafile copy
input datafile copy recid=22 stamp=875466695 filename=/u02/transport/TSPITR_TEST_KAYD/datafile/o1_mf_system_bkb7lb6k_.dbf
datafile 2 switched to datafile copy
input datafile copy recid=23 stamp=875466695 filename=/u02/transport/TSPITR_TEST_KAYD/datafile/o1_mf_undotbs1_bkb7lbfr_.dbf
datafile 3 switched to datafile copy
input datafile copy recid=24 stamp=875466695 filename=/u02/transport/TSPITR_TEST_KAYD/datafile/o1_mf_sysaux_bkb7lb6y_.dbf
datafile 6 switched to datafile copy
input datafile copy recid=25 stamp=875466695 filename=/u02/transport/tspitr01.dbf
datafile 7 switched to datafile copy
input datafile copy recid=26 stamp=875466695 filename=/u02/transport/test01.dbf

sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  6 online

sql statement: alter database datafile  7 online

Starting recover at 27-MAR-15
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 80 is already on disk as file /u02/1_80_870806981.dbf
archive log thread 1 sequence 81 is already on disk as file /u02/1_81_870806981.dbf
archive log thread 1 sequence 82 is already on disk as file /u02/1_82_870806981.dbf
archive log thread 1 sequence 83 is already on disk as file /u02/1_83_870806981.dbf
archive log filename=/u02/1_80_870806981.dbf thread=1 sequence=80
archive log filename=/u02/1_81_870806981.dbf thread=1 sequence=81
archive log filename=/u02/1_82_870806981.dbf thread=1 sequence=82
archive log filename=/u02/1_83_870806981.dbf thread=1 sequence=83
media recovery complete, elapsed time: 00:00:08
Finished recover at 27-MAR-15

database opened

contents of Memory Script:
{
#mark read only the tablespace that will be exported
sql clone "alter tablespace TSPITR read only";
#mark read only the tablespace that will be exported
sql clone "alter tablespace TEST read only";
# create directory for datapump export
sql clone "create or replace directory STREAMS_DIROBJ_DPDIR as ''
/u02/transport''";
# export the tablespaces in the recovery set
host 'expdp userid=\"/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle\)\(ARGV0=oraclekayd\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=kayd^'\)\)\(CONNECT_DATA=\(SID=kayd\)\)\) as sysdba\" transport_tablespaces=
 TSPITR,
 TEST dumpfile=
dmpfile.dmp directory=
STREAMS_DIROBJ_DPDIR logfile=
explog.log';
}
executing Memory Script

sql statement: alter tablespace TSPITR read only

sql statement: alter tablespace TEST read only

sql statement: create or replace directory STREAMS_DIROBJ_DPDIR as ''/u02/transport''


Export: Release 10.2.0.5.0 - Production on Friday, 27 March, 2015 17:12:19

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TRANSPORTABLE_01":  userid="/********@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle)(ARGV0=oraclekayd)(ARGS=\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\))(ENVS=ORACLE_SID=kayd))(CONNECT_DATA=(SID=kayd))) AS SYSDBA" transport_tablespaces= TSPITR, TEST dumpfile=dmpfile.dmp directory=STREAMS_DIROBJ_DPDIR logfile=explog.log
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
Master table "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TRANSPORTABLE_01 is:
  /u02/transport/dmpfile.dmp
Job "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 17:13:05

host command complete
/*
   The following command may be used to import the tablespaces.
   Substitute values for  and .
   impdp  directory= dumpfile= 'dmpfile.dmp' transport_datafiles= /u02/transport/tspitr01.dbf, /u02/transport/test01.dbf
*/
--------------------------------------------------------------
-- Start of sample PL/SQL script for importing the tablespaces
--------------------------------------------------------------
-- creating directory objects
CREATE DIRECTORY STREAMS$DIROBJ$1 AS  '/u02/transport/';
CREATE DIRECTORY STREAMS$DIROBJ$DPDIR AS  '/u02/transport';
/* PL/SQL Script to import the exported tablespaces */
DECLARE
  -- the datafiles
  tbs_files     dbms_streams_tablespace_adm.file_set;
  cvt_files     dbms_streams_tablespace_adm.file_set;
  -- the dumpfile to import
  dump_file     dbms_streams_tablespace_adm.file;
  dp_job_name   VARCHAR2(30) := NULL;
  -- names of tablespaces that were imported
  ts_names       dbms_streams_tablespace_adm.tablespace_set;
BEGIN
  -- dump file name and location
  dump_file.file_name :=  'dmpfile.dmp';
  dump_file.directory_object := 'STREAMS$DIROBJ$DPDIR';
  -- forming list of datafiles for import
  tbs_files( 1).file_name :=  'tspitr01.dbf';
  tbs_files( 1).directory_object :=  'STREAMS$DIROBJ$1';
  tbs_files( 2).file_name :=  'test01.dbf';
  tbs_files( 2).directory_object :=  'STREAMS$DIROBJ$1';
  -- import tablespaces
  dbms_streams_tablespace_adm.attach_tablespaces(
    datapump_job_name      => dp_job_name,
    dump_file              => dump_file,
    tablespace_files       => tbs_files,
    converted_files        => cvt_files,
    tablespace_names       => ts_names);
  -- output names of imported tablespaces
  IF ts_names IS NOT NULL AND ts_names.first IS NOT NULL THEN
    FOR i IN ts_names.first .. ts_names.last LOOP
      dbms_output.put_line('imported tablespace '|| ts_names(i));
    END LOOP;
  END IF;
END;
/
-- dropping directory objects
DROP DIRECTORY STREAMS$DIROBJ$1;
DROP DIRECTORY STREAMS$DIROBJ$DPDIR;
--------------------------------------------------------------
-- End of sample PL/SQL script
--------------------------------------------------------------

Removing automatic instance
shutting down automatic instance
Oracle instance shut down
Automatic instance removed
auxiliary instance file /u02/transport/cntrl_tspitr_TEST_kayd.f deleted
auxiliary instance file /u02/transport/TSPITR_TEST_KAYD/datafile/o1_mf_system_bkb7lb6k_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_KAYD/datafile/o1_mf_undotbs1_bkb7lbfr_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_KAYD/datafile/o1_mf_sysaux_bkb7lb6y_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_KAYD/datafile/o1_mf_temp_bkb7q2ql_.tmp deleted
auxiliary instance file /u02/transport/TSPITR_TEST_KAYD/onlinelog/o1_mf_1_bkb7pnmt_.log deleted
auxiliary instance file /u02/transport/TSPITR_TEST_KAYD/onlinelog/o1_mf_2_bkb7pqk4_.log deleted
auxiliary instance file /u02/transport/TSPITR_TEST_KAYD/onlinelog/o1_mf_3_bkb7ptbb_.log deleted

5.将步骤4生成的传输表空间的数据文件tspitr01.dbf,test01.dbf和Data Pump导出文件dmpfile拷贝到目标主机上的/u02目录中

[oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u02/transport/tspitr01.dbf /u02
oracle@192.168.56.2's password:
tspitr01.dbf                                                                                                                         100%  100MB   7.1MB/s   00:14
[oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u02/transport/test01.dbf /u02
oracle@192.168.56.2's password:
test01.dbf                                                                                                                           100%   10MB  10.0MB/s   00:00
[oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u02/transport/dmpfile.dmp /u02
oracle@192.168.56.2's password:
dmpfile.dmp                                                                                                                          100%   96KB  96.0KB/s   00:00
[oracle@jingyong1 u02]$ ls -lrt
total 112876
-rw-r----- 1 oracle oinstall 104865792 Mar 27 17:54 tspitr01.dbf
-rw-r----- 1 oracle oinstall  10493952 Mar 27 18:22 test01.dbf
-rw-r----- 1 oracle oinstall     98304 Mar 27 18:22 dmpfile.dmp

6.在目录主机上创建相关用户及Data Pump目录并将表空间附加到目标数据库中

SQL> create user tspitr identified by "tspitr";

User created.

SQL> grant dba,connect,resource to tspitr;

Grant succeeded.

SQL> create user test identified by "test";

User created.

SQL> grant dba,connect,resource to test;

Grant succeeded.

SQL> create directory mytest as '/u02';

Directory created.

SQL> grant read,write on directory mytest to public;

Grant succeeded.

最后就可以执行导入过程了

[oracle@jingyong1 ~]$ export ORACLE_SID=jy
[oracle@jingyong1 ~]$ export NLS_DATE_FORMATE='yyyy-mm-dd hh24:mi:ss'
[oracle@jingyong1 ~]$ impdp test/test directory=mytest dumpfile=dmpfile.dmp logfile=testtransport.log transport_datafiles= /u02/tspitr01.dbf, /u02/test01.dbf

Import: Release 10.2.0.5.0 - Production on Friday, 27 March, 2015 18:25:25

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "TEST"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded
Starting "TEST"."SYS_IMPORT_TRANSPORTABLE_01":  test/******** directory=mytest dumpfile=dmpfile.dmp logfile=testtransport.log transport_datafiles= /u02/tspitr01.dbf, /u02/test01.dbf
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 "TEST"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at 18:25:49

进入数据库中检查一下

SQL> select count(*) from tspitr.tspitr;

  COUNT(*)
----------
     50641

SQL> select count(*) from test.test;

  COUNT(*)
----------
     50680

与SCN=1167731之前的状态一致。

下面来演示使用until time执行传输表空间
1.确认源数据库与目标数据库所在平台是不是传输表空间所支持的操作系统平台。
确认源数据库操作系统平台:

SQL> select d.platform_name,endian_format from v$transportable_platform tp,v$database d
  2  where tp.platform_name=d.platform_name ;

PLATFORM_NAME                                                                                         ENDIAN_FORMAT
----------------------------------------------------------------------------------------------------- --------------
Linux IA (32-bit)                                                                                     Little

确认目数据库操作系统平台:

SQL> select d.platform_name,endian_format from v$transportable_platform tp,v$database d
  2  where tp.platform_name=d.platform_name ;

PLATFORM_NAME                                                                                         ENDIAN_FORMAT
----------------------------------------------------------------------------------------------------- --------------
Linux IA (32-bit)                                                                                     Little

这里操作系统平台都是Linux

2.确认要被传输的表空间是否是自包含表空间(TSPITR,TEST):

SQL> exec sys.dbms_tts.transport_set_check('TSPITR',true);

PL/SQL procedure successfully completed.


SQL> exec sys.dbms_tts.transport_set_check('TEST',true);

PL/SQL procedure successfully completed.

SQL> select * from sys.transport_set_violations;

no rows selected

如果没有行选择,表示该表空间只包含表数据,可以传输。

修改表tspitr与test中的记录
在修改之前记录当前的系统时间,在执行传输表空间时指定这个系统时间。

SQL> conn tspitr/tspitr
Connected.


SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;

TO_CHAR(SCN_TO_TIME
-------------------
2015-03-27 16:48:29


SQL> insert into tspitr select * from tspitr;

50641 rows created.

SQL> commit;

Commit complete.

SQL> select count(*) from tspitr

  COUNT(*)
----------
    101282


SQL> conn test/test
Connected.
SQL> select count(*) from test;

  COUNT(*)
----------
     50680
SQL> delete from test;

50680 rows deleted.

SQL> commit;

Commit complete.

SQL> select count(*) from test;

  COUNT(*)
----------
         0

在2015-03-27 16:48:29之后,表tspitr中的记录数为101282,表test的记录数为0,2015-03-27 16:48:29之前,表tspitr中的记录数为50641,表test的记录数为50680

3.对源数据库执行备份,在执行备份时一定要加上include current controlfile否则执行transport tablespace命令时会出现以下错误信息:

Automatic instance removed
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of tranport tablespace command at 03/26/2015 20:24:22
RMAN-03015: error occurred in stored script Memory Script
RMAN-06026: some targets not found - aborting restore
RMAN-06024: no backup or copy of the control file found to restore

[oracle@oracle11g admin]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@oracle11g admin]$ rman target sys/zzh_2046@test  catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Thu Mar 26 20:01:33 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database

RMAN> backup as backupset database include current controlfile plus archivelog;


Starting backup at 2015-03-26 20:32:19
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=68 recid=75 stamp=875286167
input archive log thread=1 sequence=69 recid=76 stamp=875291999
input archive log thread=1 sequence=70 recid=77 stamp=875302397
input archive log thread=1 sequence=71 recid=78 stamp=875308491
input archive log thread=1 sequence=72 recid=79 stamp=875350203
input archive log thread=1 sequence=73 recid=80 stamp=875351397
input archive log thread=1 sequence=74 recid=81 stamp=875390545
input archive log thread=1 sequence=75 recid=82 stamp=875390643
input archive log thread=1 sequence=76 recid=83 stamp=875391627
input archive log thread=1 sequence=77 recid=84 stamp=875391661
input archive log thread=1 sequence=78 recid=85 stamp=875391764
input archive log thread=1 sequence=79 recid=86 stamp=875392340
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:32:22
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:32:29
piece handle=/u02/ora_test875392341_991 tag=TAG20150326T203220 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:08
Finished backup at 2015-03-26 20:32:29

Starting backup at 2015-03-26 20:32:29
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/test/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/test/example01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/test/tspitr01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/test/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/test/users01.dbf
input datafile fno=00007 name=/u01/app/oracle/oradata/test/test01.dbf
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:32:30
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:33:45
piece handle=/u02/ora_test875392350_1001 tag=TAG20150326T203229 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:33:46
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:33:47
piece handle=/u02/ora_test875392425_1011 tag=TAG20150326T203229 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 2015-03-26 20:33:47

Starting backup at 2015-03-26 20:33:47
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=80 recid=87 stamp=875392427
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:33:49
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:33:50
piece handle=/u02/ora_test875392428_1021 tag=TAG20150326T203348 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 2015-03-26 20:33:50

Starting Control File and SPFILE Autobackup at 2015-03-26 20:33:50
piece handle=/u02/c-2168949517-20150326-07 comment=NONE
Finished Control File and SPFILE Autobackup at 2015-03-26 20:33:54

RMAN> list backup;


List of Backup Sets
===================

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
6565    56.14M     DISK        00:00:07     2015-03-26 20:32:28
        BP Key: 6566   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203220
        Piece Name: /u02/ora_test875392341_991

  List of Archived Logs in backup set 6565
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    68      1040304    2015-03-25 09:33:41 1064641    2015-03-25 15:02:45
  1    69      1064641    2015-03-25 15:02:45 1067420    2015-03-25 16:39:58
  1    70      1067420    2015-03-25 16:39:58 1090668    2015-03-25 19:33:17
  1    71      1090668    2015-03-25 19:33:17 1093434    2015-03-25 21:14:51
  1    72      1093434    2015-03-25 21:14:51 1125870    2015-03-26 08:50:00
  1    73      1125870    2015-03-26 08:50:00 1126817    2015-03-26 09:09:56
  1    74      1126817    2015-03-26 09:09:56 1144051    2015-03-26 20:02:21
  1    75      1144051    2015-03-26 20:02:21 1144106    2015-03-26 20:04:02
  1    76      1144106    2015-03-26 20:04:02 1144862    2015-03-26 20:20:27
  1    77      1144862    2015-03-26 20:20:27 1144893    2015-03-26 20:21:00
  1    78      1144893    2015-03-26 20:21:00 1144980    2015-03-26 20:22:44
  1    79      1144980    2015-03-26 20:22:44 1145259    2015-03-26 20:32:19

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6607    Full    640.39M    DISK        00:01:08     2015-03-26 20:33:38
        BP Key: 6621   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203229
        Piece Name: /u02/ora_test875392350_1001
  List of Datafiles in backup set 6607
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  1       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/system01.dbf
  2       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/undotbs01.dbf
  3       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/sysaux01.dbf
  4       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/users01.dbf
  5       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/example01.dbf
  6       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/tspitr01.dbf
  7       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/test01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6608    Full    7.02M      DISK        00:00:01     2015-03-26 20:33:46
        BP Key: 6622   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203229
        Piece Name: /u02/ora_test875392425_1011
  Control File Included: Ckp SCN: 1145304      Ckp time: 2015-03-26 20:33:45

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
6658    2.50K      DISK        00:00:01     2015-03-26 20:33:49
        BP Key: 6660   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203348
        Piece Name: /u02/ora_test875392428_1021

  List of Archived Logs in backup set 6658
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    80      1145259    2015-03-26 20:32:19 1145307    2015-03-26 20:33:47

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6689    Full    7.05M      DISK        00:00:01     2015-03-26 20:33:52
        BP Key: 6691   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203351
        Piece Name: /u02/c-2168949517-20150326-07
  Control File Included: Ckp SCN: 1145329      Ckp time: 2015-03-26 20:33:51
  SPFILE Included: Modification time: 2015-03-26 19:31:13

4.在这里指定了auxiliary destination子句让RMAN使用缺省值来管理辅助实例。只指定必须的选项。Oracle建议transport tablespace命令使用辅助目录秋简化辅助实例文件的管理。下面来执transport tablespace命令来传输tspitr,test两个表空间:

RMAN> transport tablespace "TSPITR","TEST" tablespace destination '/u02/transport' auxiliary destination '/u02/transport' until time "to_date('2015-03-27 16:48:29','yyyy-mm-dd hh24:mi:ss')";


Creating automatic instance, with SID='wkgj'

initialization parameters used for automatic instance:
db_name=TEST
compatible=10.2.0.5.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_TEST_wkgj
sga_target=180M
processes=50
#No auxiliary parameter file used
db_create_file_dest=/u02/transport
control_files=/u02/transport/cntrl_tspitr_TEST_wkgj.f


starting up automatic instance TEST

Oracle instance started

Total System Global Area     188743680 bytes

Fixed Size                     1272720 bytes
Variable Size                 62915696 bytes
Database Buffers             121634816 bytes
Redo Buffers                   2920448 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until  time "to_date('2015-03-27 16:48:29','yyyy-mm-dd hh24:mi:ss')";
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log for tspitr to a resent until time
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
# resync catalog after controlfile restore
resync catalog;
}
executing Memory Script

executing command: SET until clause

Starting restore at 27-MAR-15
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=47 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u02/c-2168949517-20150326-07
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/c-2168949517-20150326-07 tag=TAG20150326T203351
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output filename=/u02/transport/cntrl_tspitr_TEST_wkgj.f
Finished restore at 27-MAR-15

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

starting full resync of recovery catalog
full resync complete

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  time "to_date('2015-03-27 16:48:29','yyyy-mm-dd hh24:mi:ss')";
# set an omf destination filename for restore
set newname for clone datafile  1 to new;
# set an omf destination filename for restore
set newname for clone datafile  2 to new;
# set an omf destination filename for restore
set newname for clone datafile  3 to new;
# set an omf destination tempfile
set newname for clone tempfile  1 to new;
# set a destination filename for restore
set newname for datafile  6 to
 "/u02/transport/tspitr01.dbf";
# set a destination filename for restore
set newname for datafile  7 to
 "/u02/transport/test01.dbf";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 3, 6, 7;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile  1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  3 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  6 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  7 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  "TSPITR", "TEST", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
#           datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed temporary file 1 to /u02/transport/TSPITR_TEST_WKGJ/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 27-MAR-15
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u02/transport/TSPITR_TEST_WKGJ/datafile/o1_mf_system_%u_.dbf
restoring datafile 00002 to /u02/transport/TSPITR_TEST_WKGJ/datafile/o1_mf_undotbs1_%u_.dbf
restoring datafile 00003 to /u02/transport/TSPITR_TEST_WKGJ/datafile/o1_mf_sysaux_%u_.dbf
restoring datafile 00006 to /u02/transport/tspitr01.dbf
restoring datafile 00007 to /u02/transport/test01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875392350_1001
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875392350_1001 tag=TAG20150326T203229
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:16
Finished restore at 27-MAR-15

datafile 1 switched to datafile copy
input datafile copy recid=22 stamp=875478089 filename=/u02/transport/TSPITR_TEST_WKGJ/datafile/o1_mf_system_bkblqy42_.dbf
datafile 2 switched to datafile copy
input datafile copy recid=23 stamp=875478089 filename=/u02/transport/TSPITR_TEST_WKGJ/datafile/o1_mf_undotbs1_bkblqy5h_.dbf
datafile 3 switched to datafile copy
input datafile copy recid=24 stamp=875478089 filename=/u02/transport/TSPITR_TEST_WKGJ/datafile/o1_mf_sysaux_bkblqy4h_.dbf
datafile 6 switched to datafile copy
input datafile copy recid=25 stamp=875478089 filename=/u02/transport/tspitr01.dbf
datafile 7 switched to datafile copy
input datafile copy recid=26 stamp=875478089 filename=/u02/transport/test01.dbf

sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  6 online

sql statement: alter database datafile  7 online

Starting recover at 27-MAR-15
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 80 is already on disk as file /u02/1_80_870806981.dbf
archive log thread 1 sequence 81 is already on disk as file /u02/1_81_870806981.dbf
archive log thread 1 sequence 82 is already on disk as file /u02/1_82_870806981.dbf
archive log thread 1 sequence 83 is already on disk as file /u02/1_83_870806981.dbf
archive log filename=/u02/1_80_870806981.dbf thread=1 sequence=80
archive log filename=/u02/1_81_870806981.dbf thread=1 sequence=81
archive log filename=/u02/1_82_870806981.dbf thread=1 sequence=82
archive log filename=/u02/1_83_870806981.dbf thread=1 sequence=83
media recovery complete, elapsed time: 00:00:07
Finished recover at 27-MAR-15

database opened

contents of Memory Script:
{
#mark read only the tablespace that will be exported
sql clone "alter tablespace TSPITR read only";
#mark read only the tablespace that will be exported
sql clone "alter tablespace TEST read only";
# create directory for datapump export
sql clone "create or replace directory STREAMS_DIROBJ_DPDIR as ''
/u02/transport''";
# export the tablespaces in the recovery set
host 'expdp userid=\"/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle\)\(ARGV0=oraclewkgj\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=wkgj^'\)\)\(CONNECT_DATA=\(SID=wkgj\)\)\) as sysdba\" transport_tablespaces=
 TSPITR,
 TEST dumpfile=
dmpfile.dmp directory=
STREAMS_DIROBJ_DPDIR logfile=
explog.log';
}
executing Memory Script

sql statement: alter tablespace TSPITR read only

sql statement: alter tablespace TEST read only

sql statement: create or replace directory STREAMS_DIROBJ_DPDIR as ''/u02/transport''


Export: Release 10.2.0.5.0 - Production on Friday, 27 March, 2015 20:22:11

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TRANSPORTABLE_01":  userid="/********@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle)(ARGV0=oraclewkgj)(ARGS=\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\))(ENVS=ORACLE_SID=wkgj))(CONNECT_DATA=(SID=wkgj))) AS SYSDBA" transport_tablespaces= TSPITR, TEST dumpfile=dmpfile.dmp directory=STREAMS_DIROBJ_DPDIR logfile=explog.log
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
Master table "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TRANSPORTABLE_01 is:
  /u02/transport/dmpfile.dmp
Job "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 20:23:07

host command complete
/*
   The following command may be used to import the tablespaces.
   Substitute values for  and .
   impdp  directory= dumpfile= 'dmpfile.dmp' transport_datafiles= /u02/transport/tspitr01.dbf, /u02/transport/test01.dbf
*/
--------------------------------------------------------------
-- Start of sample PL/SQL script for importing the tablespaces
--------------------------------------------------------------
-- creating directory objects
CREATE DIRECTORY STREAMS$DIROBJ$1 AS  '/u02/transport/';
CREATE DIRECTORY STREAMS$DIROBJ$DPDIR AS  '/u02/transport';
/* PL/SQL Script to import the exported tablespaces */
DECLARE
  -- the datafiles
  tbs_files     dbms_streams_tablespace_adm.file_set;
  cvt_files     dbms_streams_tablespace_adm.file_set;
  -- the dumpfile to import
  dump_file     dbms_streams_tablespace_adm.file;
  dp_job_name   VARCHAR2(30) := NULL;
  -- names of tablespaces that were imported
  ts_names       dbms_streams_tablespace_adm.tablespace_set;
BEGIN
  -- dump file name and location
  dump_file.file_name :=  'dmpfile.dmp';
  dump_file.directory_object := 'STREAMS$DIROBJ$DPDIR';
  -- forming list of datafiles for import
  tbs_files( 1).file_name :=  'tspitr01.dbf';
  tbs_files( 1).directory_object :=  'STREAMS$DIROBJ$1';
  tbs_files( 2).file_name :=  'test01.dbf';
  tbs_files( 2).directory_object :=  'STREAMS$DIROBJ$1';
  -- import tablespaces
  dbms_streams_tablespace_adm.attach_tablespaces(
    datapump_job_name      => dp_job_name,
    dump_file              => dump_file,
    tablespace_files       => tbs_files,
    converted_files        => cvt_files,
    tablespace_names       => ts_names);
  -- output names of imported tablespaces
  IF ts_names IS NOT NULL AND ts_names.first IS NOT NULL THEN
    FOR i IN ts_names.first .. ts_names.last LOOP
      dbms_output.put_line('imported tablespace '|| ts_names(i));
    END LOOP;
  END IF;
END;
/
-- dropping directory objects
DROP DIRECTORY STREAMS$DIROBJ$1;
DROP DIRECTORY STREAMS$DIROBJ$DPDIR;
--------------------------------------------------------------
-- End of sample PL/SQL script
--------------------------------------------------------------

Removing automatic instance
shutting down automatic instance
Oracle instance shut down
Automatic instance removed
auxiliary instance file /u02/transport/cntrl_tspitr_TEST_wkgj.f deleted
auxiliary instance file /u02/transport/TSPITR_TEST_WKGJ/datafile/o1_mf_system_bkblqy42_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_WKGJ/datafile/o1_mf_undotbs1_bkblqy5h_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_WKGJ/datafile/o1_mf_sysaux_bkblqy4h_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_WKGJ/datafile/o1_mf_temp_bkblv2ot_.tmp deleted
auxiliary instance file /u02/transport/TSPITR_TEST_WKGJ/onlinelog/o1_mf_1_bkbltlnc_.log deleted
auxiliary instance file /u02/transport/TSPITR_TEST_WKGJ/onlinelog/o1_mf_2_bkbltp71_.log deleted
auxiliary instance file /u02/transport/TSPITR_TEST_WKGJ/onlinelog/o1_mf_3_bkbltt75_.log deleted


5.将步骤4生成的传输表空间的数据文件tspitr01.dbf,test01.dbf和Data Pump导出文件dmpfile拷贝到目标主机上的/u02目录中

[oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u02/transport/tspitr01.dbf /u02
oracle@192.168.56.2's password:
tspitr01.dbf                                                                                                                         100%  100MB   7.1MB/s   00:14
[oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u02/transport/test01.dbf /u02
oracle@192.168.56.2's password:
test01.dbf                                                                                                                           100%   10MB  10.0MB/s   00:00
[oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u02/transport/dmpfile.dmp /u02
oracle@192.168.56.2's password:
dmpfile.dmp                                                                                                                          100%   96KB  96.0KB/s   00:00
[oracle@jingyong1 u02]$ ls -lrt
total 112876
-rw-r----- 1 oracle oinstall 104865792 Mar 27 17:54 tspitr01.dbf
-rw-r----- 1 oracle oinstall  10493952 Mar 27 18:22 test01.dbf
-rw-r----- 1 oracle oinstall     98304 Mar 27 18:22 dmpfile.dmp

6.在目录主机上创建相关用户及Data Pump目录并将表空间附加到目标数据库中

SQL> create user tspitr identified by "tspitr";

User created.

SQL> grant dba,connect,resource to tspitr;

Grant succeeded.

SQL> create user test identified by "test";

User created.

SQL> grant dba,connect,resource to test;

Grant succeeded.

SQL> create directory mytest as '/u02';

Directory created.

SQL> grant read,write on directory mytest to public;

Grant succeeded.

最后就可以执行导入过程了

[oracle@jingyong1 ~]$ export ORACLE_SID=jy
[oracle@jingyong1 ~]$ export NLS_DATE_FORMATE='yyyy-mm-dd hh24:mi:ss'
[oracle@jingyong1 ~]$ impdp test/test directory=mytest dumpfile=dmpfile.dmp logfile=testtransport.log transport_datafiles= /u02/tspitr01.dbf, /u02/test01.dbf

Import: Release 10.2.0.5.0 - Production on Friday, 27 March, 2015 20:28:39

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "TEST"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded
Starting "TEST"."SYS_IMPORT_TRANSPORTABLE_01":  test/******** directory=mytest dumpfile=dmpfile.dmp logfile=testtransport.log transport_datafiles= /u02/tspitr01.dbf, /u02/test01.dbf
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 "TEST"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at 20:28:55

进入数据库中检查一下
SQL> select count(*) from tspitr.tspitr;

  COUNT(*)
----------
     50641

SQL> select count(*) from test.test;

  COUNT(*)
----------
     50680
与2015-03-27 16:48:29之前的状态一致。


下面演示使用还原点来执行传输表空间
1.确认源数据库与目标数据库所在平台是不是传输表空间所支持的操作系统平台。
确认源数据库操作系统平台:
SQL> select d.platform_name,endian_format from v$transportable_platform tp,v$database d
  2  where tp.platform_name=d.platform_name ;

PLATFORM_NAME                                                                                         ENDIAN_FORMAT
----------------------------------------------------------------------------------------------------- --------------
Linux IA (32-bit)                                                                                     Little

确认目数据库操作系统平台:

SQL> select d.platform_name,endian_format from v$transportable_platform tp,v$database d
  2  where tp.platform_name=d.platform_name ;

PLATFORM_NAME                                                                                         ENDIAN_FORMAT
----------------------------------------------------------------------------------------------------- --------------
Linux IA (32-bit)                                                                                     Little

这里操作系统平台都是Linux

2.确认要被传输的表空间是否是自包含表空间(TSPITR,TEST):

SQL> exec sys.dbms_tts.transport_set_check('TSPITR',true);

PL/SQL procedure successfully completed.


SQL> exec sys.dbms_tts.transport_set_check('TEST',true);

PL/SQL procedure successfully completed.

SQL> select * from sys.transport_set_violations;

no rows selected

如果没有行选择,表示该表空间只包含表数据,可以传输。

修改表tspitr与test中的记录,在修改之前创建一个还原点,在执行传输表空间时指定这个还原点

SQL> select count(*) from test;

  COUNT(*)
----------
         0

SQL> select count(*) from tspitr.tspitr;

  COUNT(*)
----------
    101282

SQL> create restore point before_update;

Restore point created.


SQL> insert into test select * from dba_objects;

50683 rows created.

SQL> commit;

Commit complete.

SQL> delete from tspitr.tspitr;

101282 rows deleted.

SQL> commit;

Commit complete.

SQL> select count(*) from test;

  COUNT(*)
----------
     50683

SQL> select count(*) from tspitr.tspitr;

  COUNT(*)
----------
         0

在创建还原点before_update之后,表tspitr中的记录数为0,表test的记录数为50683,before_update之前,表tspitr中的记录数为101282,表test的记录数为0。

3.对源数据库执行备份,在执行备份时一定要加上include current controlfile否则执行transport tablespace命令时会出现以下错误信息:

Automatic instance removed
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of tranport tablespace command at 03/26/2015 20:24:22
RMAN-03015: error occurred in stored script Memory Script
RMAN-06026: some targets not found - aborting restore
RMAN-06024: no backup or copy of the control file found to restore

[oracle@oracle11g admin]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@oracle11g admin]$ rman target sys/zzh_2046@test  catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Thu Mar 26 20:01:33 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database

RMAN> backup as backupset database include current controlfile plus archivelog;


Starting backup at 2015-03-26 20:32:19
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=68 recid=75 stamp=875286167
input archive log thread=1 sequence=69 recid=76 stamp=875291999
input archive log thread=1 sequence=70 recid=77 stamp=875302397
input archive log thread=1 sequence=71 recid=78 stamp=875308491
input archive log thread=1 sequence=72 recid=79 stamp=875350203
input archive log thread=1 sequence=73 recid=80 stamp=875351397
input archive log thread=1 sequence=74 recid=81 stamp=875390545
input archive log thread=1 sequence=75 recid=82 stamp=875390643
input archive log thread=1 sequence=76 recid=83 stamp=875391627
input archive log thread=1 sequence=77 recid=84 stamp=875391661
input archive log thread=1 sequence=78 recid=85 stamp=875391764
input archive log thread=1 sequence=79 recid=86 stamp=875392340
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:32:22
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:32:29
piece handle=/u02/ora_test875392341_991 tag=TAG20150326T203220 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:08
Finished backup at 2015-03-26 20:32:29

Starting backup at 2015-03-26 20:32:29
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/test/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/test/example01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/test/tspitr01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/test/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/test/users01.dbf
input datafile fno=00007 name=/u01/app/oracle/oradata/test/test01.dbf
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:32:30
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:33:45
piece handle=/u02/ora_test875392350_1001 tag=TAG20150326T203229 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:33:46
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:33:47
piece handle=/u02/ora_test875392425_1011 tag=TAG20150326T203229 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 2015-03-26 20:33:47

Starting backup at 2015-03-26 20:33:47
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=80 recid=87 stamp=875392427
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:33:49
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:33:50
piece handle=/u02/ora_test875392428_1021 tag=TAG20150326T203348 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 2015-03-26 20:33:50

Starting Control File and SPFILE Autobackup at 2015-03-26 20:33:50
piece handle=/u02/c-2168949517-20150326-07 comment=NONE
Finished Control File and SPFILE Autobackup at 2015-03-26 20:33:54

RMAN> list backup;


List of Backup Sets
===================

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
6565    56.14M     DISK        00:00:07     2015-03-26 20:32:28
        BP Key: 6566   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203220
        Piece Name: /u02/ora_test875392341_991

  List of Archived Logs in backup set 6565
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    68      1040304    2015-03-25 09:33:41 1064641    2015-03-25 15:02:45
  1    69      1064641    2015-03-25 15:02:45 1067420    2015-03-25 16:39:58
  1    70      1067420    2015-03-25 16:39:58 1090668    2015-03-25 19:33:17
  1    71      1090668    2015-03-25 19:33:17 1093434    2015-03-25 21:14:51
  1    72      1093434    2015-03-25 21:14:51 1125870    2015-03-26 08:50:00
  1    73      1125870    2015-03-26 08:50:00 1126817    2015-03-26 09:09:56
  1    74      1126817    2015-03-26 09:09:56 1144051    2015-03-26 20:02:21
  1    75      1144051    2015-03-26 20:02:21 1144106    2015-03-26 20:04:02
  1    76      1144106    2015-03-26 20:04:02 1144862    2015-03-26 20:20:27
  1    77      1144862    2015-03-26 20:20:27 1144893    2015-03-26 20:21:00
  1    78      1144893    2015-03-26 20:21:00 1144980    2015-03-26 20:22:44
  1    79      1144980    2015-03-26 20:22:44 1145259    2015-03-26 20:32:19

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6607    Full    640.39M    DISK        00:01:08     2015-03-26 20:33:38
        BP Key: 6621   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203229
        Piece Name: /u02/ora_test875392350_1001
  List of Datafiles in backup set 6607
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  1       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/system01.dbf
  2       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/undotbs01.dbf
  3       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/sysaux01.dbf
  4       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/users01.dbf
  5       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/example01.dbf
  6       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/tspitr01.dbf
  7       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/test01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6608    Full    7.02M      DISK        00:00:01     2015-03-26 20:33:46
        BP Key: 6622   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203229
        Piece Name: /u02/ora_test875392425_1011
  Control File Included: Ckp SCN: 1145304      Ckp time: 2015-03-26 20:33:45

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
6658    2.50K      DISK        00:00:01     2015-03-26 20:33:49
        BP Key: 6660   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203348
        Piece Name: /u02/ora_test875392428_1021

  List of Archived Logs in backup set 6658
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    80      1145259    2015-03-26 20:32:19 1145307    2015-03-26 20:33:47

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6689    Full    7.05M      DISK        00:00:01     2015-03-26 20:33:52
        BP Key: 6691   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203351
        Piece Name: /u02/c-2168949517-20150326-07
  Control File Included: Ckp SCN: 1145329      Ckp time: 2015-03-26 20:33:51
  SPFILE Included: Modification time: 2015-03-26 19:31:13

4.在这里指定了auxiliary destination子句让RMAN使用缺省值来管理辅助实例。只指定必须的选项。Oracle建议transport tablespace命令使用辅助目录秋简化辅助实例文件的管理。下面来执transport tablespace命令来传输tspitr,test两个表空间:


RMAN> transport tablespace "TSPITR","TEST" tablespace destination '/u02/transport' auxiliary destination '/u02/transport' UNTIL RESTORE POINT 'before_update';

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of tranport tablespace command at 03/27/2015 20:42:53
RMAN-00600: internal error, arguments [5085] [point] [] [] []

出现RMAN-00600 internal error, arguments [5085] [point],在MOS上有一篇关于这个错误的文章,是ORACLE的bug,请参考Bug 8571266 – RMAN TSPITR to restore point fails with RMAN-600 [5085] (Doc ID 8571266.8),说这个Bug在11.2.0.2中已经修复了。

RMAN使用备份传输表空间

在Oracle数据库管理手册中创建传输表空间集的方法要求在执行表空间传输期间被传输的表空间要以只读模式打开。相比之下,当RMAN使用备份创建传输表空间集时,不需要访问被传输表空间的联机数据文件。这就消除了要将传输表空间设置为只读模式的操作。结果就是提高了源数据库的可用性,特别是对于很大的表空间更是如此,因为表空间在传输时仍然操作读写状态,而且将表空间设置为只读模式依赖于数据库的负载,可能需要花费很长时间。

使用RMAN创建传输表空间集能让你指定一个目标时间点,SCN或者你恢复窗口中的还原点并且传输数据的时间并不是transport tablespace的时间。例如,如果你的备份保留策略是保证一周的恢复窗口并且想创建传输表空间来报告数据库在每个月最后一天时间的内容,可以使用RMAN在下个月的第一周内的任何时间来完成这个任务。

RMAN的transport tablespace命令被用来从RMAN备份中创建传输表空间集。注意,即使用没有使用RMAN对数据库进行备份,RMAN的transport tablespace命令也仍然能被用来创建传输表空间集。然而,对于传输表空间集所期待的SCN之前必须有传输表空间集所有的数据文件副本,并且为了执行transport tablespace命令使用RMAN的catalog命令将数据文件副本和归档重做日志登记到RMAN的档案库中。当RMAN记录了所有需要的备份和日志后,就可以执行传输表空间。

何时使用RMAN来创建传输表空间集
在任何需要传输表空间的情况下,只要你有将表空间恢复到指定SCN所需要的数据库备份,都可以使用RMAN的transport tablespace命令来创建它们。

然而在以下两种特殊情况下更好有用:
.使用表空间档案库来创建传输表空间集。例如,数据库中有些表空间用来做季报。使用transport
tablespace命令来为这些存储在表空间档案库中的生成季报的表空间创建传输表空间集。之后从档案库中被请求的表空间版本被附加到一些其它数据库中来生成报表。

.当准备使用流来使用源数据库同步目标数据库时,必须安装流,为了使用目标数据库及时更新到指定的SCN,两个数据库必须被同步。

使用RMAN生成传输表空间集要有以下实例:
1.RMAN客户端
2.源数据库,包含了被传输的表空间
3.源数据库的归档重做日志备份,将用来恢复被传输的表空间
4.辅助实例,由RMAN在源数据库所在主机上创建的实例,用来执行表空间的还原和恢复,如果处成功会清除它
5.辅助集,包含了执行传输表空间所要求的数据文件和其它文件但它们不是恢复集的一部分。辅助集包括:system和sysaux表空间的副本,undo表空间和源数据库中包含 undo段或回滚段的数据文件。辅助实例还有其它相关的文件,比如,控制文件,参数文件和联机重做日志文件,但这些都是辅助集的一部分
6.辅助目录,当执行RMAN的transport tablespace命令时,磁盘上用来存储辅助集文件的目录,比如参数文件,数据文件(除了传输表空间的数据文件之外的数据文件),控制文件和辅助实例的联机重做日志文件。如果传输表空间执行成功,这些文件都会被删除。
注意:设置辅助目录是可选项,然而,如果没有设置辅助目录,必须确保对所有辅助实例文件,包括所有数据文件,联机重做日志文件都使用辅助实例参数来指定存储目录,Oracle建议使用辅助目录来简化transport tablespace命令。
7.表空间目录,存储数据文件副本和表空间传输命令完成后的输出文件的磁盘目录。
8.传输集,包含了被传输表空间的数据文件和用于在目标数据库附加表空间的导出dump文件(通常是使用Data Pump导出)。
9.用于在目标数据库附加表空间的示例导入脚本(由RMAN生成)和Data Pump导出的日志文件。

RMAN使用备份执行传输表空间的操作步骤
1.在启动阶段,RMAN会构建一个辅助实例。首先RMAN会为辅助实例自动创建参数文件,并将辅助实例启、动到nomount状态。然后,RMAN使用源数据库的控制文件备份还原辅助实例控制文件并加载控制文件。

2.当辅助实例控制文件被加载后,RMAN就会使用源数据库备份,辅助目录中的辅助数据文件和表空间目录中的传输集文件来还原辅助实例和传输集数据文件。RMAN然后在辅助实例中执行switch操作,因此辅助实例使用还原的数据文件作为辅助实例的数据文件。

RMAN对辅助实例执行数据库按时间点还原。这将辅助集和传输集数据文件中的内容更新到transport tablespace命令所指定目标时间点。(如果没有指定目录时间就是执行完全恢复)。执行transport tablespace命令时间会使用备份将需要的归档重做日志文件还原到辅助目录中(或其它目录中)并在应用给辅助实例之后将其删除。

一旦恢复完成,RMAN会对辅助实例执行open resetlogs操作。这时数据文件反映了表空间在传输表空间操作所指定的目标时间点的内容。

3.辅助实例的恢复集表空间将会被设置为只读模式,并且调用Data Pump来为恢复集表空间生成dump文件缺省情况下,生成的dump文件存储在表空间目录中,也可以指定dump文件目录。

在这时RMAN也生成了用于在目标数据库中附加传输表空间的Data Pump导入的示例脚本。脚本内容将被写入到一个名叫impscript.sql的文件中,并且存储在表空间目录中。这个脚本的命令也被包含在RMAN的transport tablespace命令的输出信息中。

如果所有操作都执行成功,RMAN会关闭辅助实例并删除除了传输集文件之外的,transport tablespace命令生成的所有文件,Data Pump导出日志和示例导入脚本。

注意:transport tablespace失踪不会自动地对恢复集数据文件进行字节序的转换。如果需要,在创建传输集后将数据文件转换为目标数据库的字节序。导入的示例脚本是假设要被附加到目标数据库的传输表空间的数据文件的存储目录与transport tablespace操作创建这些文件的目录相同。如果这些文件在表空间被附加之前移动到新的磁盘目录中,必须修改示例脚本指向新的目录。

RMAN transport tablespace命令的限制
使用RMAN创建传输表空间有以下限制:
1.必须对transport tablespace操作将数据库恢复到指定目标时间点所有需要的表空间(包括辅助集中的表空间)和归档重做日志进行备份。

2.因为RMAN在使用备份创建传输表空间的过程中会使用到Data Pump导出和导入工具,如果被传输的表空间使用XMLTypes就不能使用RMAN进行操作。在这种情况下必须使用Oracle管理手册中介绍的方法

3.因为RMAN会在与源实例相同的主机上自动创建辅助实例来还原和恢复,在执行transport tablespace命令时会有些性能开销。

4.如果删除了一个表空间,即使transport tablespace命令指定的SCN早于表空间被删除时的SCN,也不能将被删除的表空间包含在transport tablepsace命令的传输表空间集中。

5.如果对表空间重命名后,不能使用transport tablespace命令来创建表空间集的目标时间不能早于表空间被删除的时间(RMAN有关于表空间之前的名字)。

6.不能传输传表没有相关约束的表或者没有相关表的约束

7.传输集和辅助集数据文件可以包含以下任何对象:
–复制主表
–部分表
-有varray列,嵌套表或外部文件的表
–快照日志和快照表
–包含undo或回滚段的表空间
–包含属于SYS用户对象加,回滚段的表空间

如果不使用恢复目录执行transport tablespace还有以下两个限制:
1.如果使用过去某个时间点的表空间内容来创建传输集,那么执行transport tablespace命令时表空间集所使用的undo段与传输时所选择的表空间所使用的undo段必须相同。包含transport tablespace命令所指定目标SCN所需要的undo段的表空间是辅助集的一部分。不像恢复目录,控制文件中的RMAN档案库只包含在当时包含undo段的表空间记录。如果表空间要使用的undo段与指定的目标时间要使用的不同,那么transport tablespace命令将会失败。

2.如果数据库已经重用了RMAN档案库中包含transport tablespace操作所需要的备份记录信息,那么因为RMAN不能定位需要的备份而造成操作失败。如果备份仍然可用,可以使用catalog命令将需要的备份登记到RMAN档案库中,但如果数据库已经覆盖了控制文件中的备份记录那么可能要丢失需要的备份记录信息。

使用RMAN创建传输表空间集的操作过程

使用RMAN传输表空间的基本操作
1.确认源数据库与目标数据库所在平台是不是传输表空间所支持的操作系统平台。
确认源数据库操作系统平台:

SQL> select d.platform_name,endian_format from v$transportable_platform tp,v$database d
  2  where tp.platform_name=d.platform_name ;

PLATFORM_NAME                                                                                         ENDIAN_FORMAT
----------------------------------------------------------------------------------------------------- --------------
Linux IA (32-bit)                                                                                     Little

确认目数据库操作系统平台:

SQL> select d.platform_name,endian_format from v$transportable_platform tp,v$database d
  2  where tp.platform_name=d.platform_name ;

PLATFORM_NAME                                                                                         ENDIAN_FORMAT
----------------------------------------------------------------------------------------------------- --------------
Linux IA (32-bit)                                                                                     Little

这里操作系统平台都是Linux

2.确认要被传输的表空间是否是自包含表空间(TSPITR,TEST):

SQL> exec sys.dbms_tts.transport_set_check('TSPITR',true);

PL/SQL procedure successfully completed.


SQL> exec sys.dbms_tts.transport_set_check('TEST',true);

PL/SQL procedure successfully completed.

SQL> select * from sys.transport_set_violations;

no rows selected

如果没有行选择,表示该表空间只包含表数据,可以传输。

记录表空间传输前表tspitr与test中的记录:

SQL> conn tspitr/tspitr
Connected.
SQL> select count(*) from tspitr;

  COUNT(*)
----------
     50641

SQL> conn test/test
Connected.
SQL> select count(*) from test;

  COUNT(*)
----------
     50680

3.对源数据库执行备份,在执行备份时一定要加上include current controlfile否则执行transport tablespace命令时会出现以下错误信息:

Automatic instance removed
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of tranport tablespace command at 03/26/2015 20:24:22
RMAN-03015: error occurred in stored script Memory Script
RMAN-06026: some targets not found - aborting restore
RMAN-06024: no backup or copy of the control file found to restore
[oracle@oracle11g admin]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@oracle11g admin]$ rman target sys/zzh_2046@test  catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Thu Mar 26 20:01:33 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database

RMAN> backup as backupset database include current controlfile plus archivelog;


Starting backup at 2015-03-26 20:32:19
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=68 recid=75 stamp=875286167
input archive log thread=1 sequence=69 recid=76 stamp=875291999
input archive log thread=1 sequence=70 recid=77 stamp=875302397
input archive log thread=1 sequence=71 recid=78 stamp=875308491
input archive log thread=1 sequence=72 recid=79 stamp=875350203
input archive log thread=1 sequence=73 recid=80 stamp=875351397
input archive log thread=1 sequence=74 recid=81 stamp=875390545
input archive log thread=1 sequence=75 recid=82 stamp=875390643
input archive log thread=1 sequence=76 recid=83 stamp=875391627
input archive log thread=1 sequence=77 recid=84 stamp=875391661
input archive log thread=1 sequence=78 recid=85 stamp=875391764
input archive log thread=1 sequence=79 recid=86 stamp=875392340
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:32:22
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:32:29
piece handle=/u02/ora_test875392341_991 tag=TAG20150326T203220 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:08
Finished backup at 2015-03-26 20:32:29

Starting backup at 2015-03-26 20:32:29
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/test/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/test/example01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/test/tspitr01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/test/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/test/users01.dbf
input datafile fno=00007 name=/u01/app/oracle/oradata/test/test01.dbf
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:32:30
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:33:45
piece handle=/u02/ora_test875392350_1001 tag=TAG20150326T203229 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:33:46
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:33:47
piece handle=/u02/ora_test875392425_1011 tag=TAG20150326T203229 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 2015-03-26 20:33:47

Starting backup at 2015-03-26 20:33:47
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=80 recid=87 stamp=875392427
channel ORA_DISK_1: starting piece 1 at 2015-03-26 20:33:49
channel ORA_DISK_1: finished piece 1 at 2015-03-26 20:33:50
piece handle=/u02/ora_test875392428_1021 tag=TAG20150326T203348 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 2015-03-26 20:33:50

Starting Control File and SPFILE Autobackup at 2015-03-26 20:33:50
piece handle=/u02/c-2168949517-20150326-07 comment=NONE
Finished Control File and SPFILE Autobackup at 2015-03-26 20:33:54

RMAN> list backup;


List of Backup Sets
===================

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
6565    56.14M     DISK        00:00:07     2015-03-26 20:32:28
        BP Key: 6566   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203220
        Piece Name: /u02/ora_test875392341_991

  List of Archived Logs in backup set 6565
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    68      1040304    2015-03-25 09:33:41 1064641    2015-03-25 15:02:45
  1    69      1064641    2015-03-25 15:02:45 1067420    2015-03-25 16:39:58
  1    70      1067420    2015-03-25 16:39:58 1090668    2015-03-25 19:33:17
  1    71      1090668    2015-03-25 19:33:17 1093434    2015-03-25 21:14:51
  1    72      1093434    2015-03-25 21:14:51 1125870    2015-03-26 08:50:00
  1    73      1125870    2015-03-26 08:50:00 1126817    2015-03-26 09:09:56
  1    74      1126817    2015-03-26 09:09:56 1144051    2015-03-26 20:02:21
  1    75      1144051    2015-03-26 20:02:21 1144106    2015-03-26 20:04:02
  1    76      1144106    2015-03-26 20:04:02 1144862    2015-03-26 20:20:27
  1    77      1144862    2015-03-26 20:20:27 1144893    2015-03-26 20:21:00
  1    78      1144893    2015-03-26 20:21:00 1144980    2015-03-26 20:22:44
  1    79      1144980    2015-03-26 20:22:44 1145259    2015-03-26 20:32:19

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6607    Full    640.39M    DISK        00:01:08     2015-03-26 20:33:38
        BP Key: 6621   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203229
        Piece Name: /u02/ora_test875392350_1001
  List of Datafiles in backup set 6607
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  1       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/system01.dbf
  2       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/undotbs01.dbf
  3       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/sysaux01.dbf
  4       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/users01.dbf
  5       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/example01.dbf
  6       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/tspitr01.dbf
  7       Full 1145279    2015-03-26 20:32:30 /u01/app/oracle/oradata/test/test01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6608    Full    7.02M      DISK        00:00:01     2015-03-26 20:33:46
        BP Key: 6622   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203229
        Piece Name: /u02/ora_test875392425_1011
  Control File Included: Ckp SCN: 1145304      Ckp time: 2015-03-26 20:33:45

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
6658    2.50K      DISK        00:00:01     2015-03-26 20:33:49
        BP Key: 6660   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203348
        Piece Name: /u02/ora_test875392428_1021

  List of Archived Logs in backup set 6658
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    80      1145259    2015-03-26 20:32:19 1145307    2015-03-26 20:33:47

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6689    Full    7.05M      DISK        00:00:01     2015-03-26 20:33:52
        BP Key: 6691   Status: AVAILABLE  Compressed: NO  Tag: TAG20150326T203351
        Piece Name: /u02/c-2168949517-20150326-07
  Control File Included: Ckp SCN: 1145329      Ckp time: 2015-03-26 20:33:51
  SPFILE Included: Modification time: 2015-03-26 19:31:13

4.在这里指定了auxiliary destination子句让RMAN使用缺省值来管理辅助实例。只指定必须的选项。Oracle建议transport tablespace命令使用辅助目录秋简化辅助实例文件的管理。下面来执transport tablespace命令来传输tspitr,test两个表空间:

RMAN> transport tablespace "TSPITR","TEST" tablespace destination '/u02/transport' auxiliary destination '/u02/transport';


Creating automatic instance, with SID='flqb'

initialization parameters used for automatic instance:
db_name=TEST
compatible=10.2.0.5.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_TEST_flqb
sga_target=180M
processes=50
#No auxiliary parameter file used
db_create_file_dest=/u02/transport
control_files=/u02/transport/cntrl_tspitr_TEST_flqb.f


starting up automatic instance TEST

Oracle instance started

Total System Global Area     188743680 bytes

Fixed Size                     1272720 bytes
Variable Size                 62915696 bytes
Database Buffers             121634816 bytes
Redo Buffers                   2920448 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until  scn 1145307;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log for tspitr to a resent until time
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
# resync catalog after controlfile restore
resync catalog;
}
executing Memory Script

executing command: SET until clause

Starting restore at 2015-03-26 20:35:10
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=47 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875392425_1011
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875392425_1011 tag=TAG20150326T203229
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output filename=/u02/transport/cntrl_tspitr_TEST_flqb.f
Finished restore at 2015-03-26 20:35:15

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

starting full resync of recovery catalog
full resync complete

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  scn 1145307;
# set an omf destination filename for restore
set newname for clone datafile  1 to new;
# set an omf destination filename for restore
set newname for clone datafile  2 to new;
# set an omf destination filename for restore
set newname for clone datafile  3 to new;
# set an omf destination tempfile
set newname for clone tempfile  1 to new;
# set a destination filename for restore
set newname for datafile  6 to
 "/u02/transport/tspitr01.dbf";
# set a destination filename for restore
set newname for datafile  7 to
 "/u02/transport/test01.dbf";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 3, 6, 7;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile  1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  3 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  6 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  7 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  "TSPITR", "TEST", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
#           datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed temporary file 1 to /u02/transport/TSPITR_TEST_FLQB/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 2015-03-26 20:35:24
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u02/transport/TSPITR_TEST_FLQB/datafile/o1_mf_system_%u_.dbf
restoring datafile 00002 to /u02/transport/TSPITR_TEST_FLQB/datafile/o1_mf_undotbs1_%u_.dbf
restoring datafile 00003 to /u02/transport/TSPITR_TEST_FLQB/datafile/o1_mf_sysaux_%u_.dbf
restoring datafile 00006 to /u02/transport/tspitr01.dbf
restoring datafile 00007 to /u02/transport/test01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875392350_1001
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875392350_1001 tag=TAG20150326T203229
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:25
Finished restore at 2015-03-26 20:36:50

datafile 1 switched to datafile copy
input datafile copy recid=22 stamp=875392611 filename=/u02/transport/TSPITR_TEST_FLQB/datafile/o1_mf_system_bk7z8fsc_.dbf
datafile 2 switched to datafile copy
input datafile copy recid=23 stamp=875392611 filename=/u02/transport/TSPITR_TEST_FLQB/datafile/o1_mf_undotbs1_bk7z8ft1_.dbf
datafile 3 switched to datafile copy
input datafile copy recid=24 stamp=875392611 filename=/u02/transport/TSPITR_TEST_FLQB/datafile/o1_mf_sysaux_bk7z8fsp_.dbf
datafile 6 switched to datafile copy
input datafile copy recid=25 stamp=875392611 filename=/u02/transport/tspitr01.dbf
datafile 7 switched to datafile copy
input datafile copy recid=26 stamp=875392611 filename=/u02/transport/test01.dbf

sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  6 online

sql statement: alter database datafile  7 online

Starting recover at 2015-03-26 20:36:51
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 80 is already on disk as file /u02/1_80_870806981.dbf
archive log filename=/u02/1_80_870806981.dbf thread=1 sequence=80
media recovery complete, elapsed time: 00:00:01
Finished recover at 2015-03-26 20:36:53

database opened

contents of Memory Script:
{
#mark read only the tablespace that will be exported
sql clone "alter tablespace TSPITR read only";
#mark read only the tablespace that will be exported
sql clone "alter tablespace TEST read only";
# create directory for datapump export
sql clone "create or replace directory STREAMS_DIROBJ_DPDIR as ''
/u02/transport''";
# export the tablespaces in the recovery set
host 'expdp userid=\"/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle\)\(ARGV0=oracleflqb\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=flqb^'\)\)\(CONNECT_DATA=\(SID=flqb\)\)\) as sysdba\" transport_tablespaces=
 TSPITR,
 TEST dumpfile=
dmpfile.dmp directory=
STREAMS_DIROBJ_DPDIR logfile=
explog.log';
}
executing Memory Script

sql statement: alter tablespace TSPITR read only

sql statement: alter tablespace TEST read only

sql statement: create or replace directory STREAMS_DIROBJ_DPDIR as ''/u02/transport''


Export: Release 10.2.0.5.0 - Production on Thursday, 26 March, 2015 20:37:24

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TRANSPORTABLE_01":  userid="/********@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle)(ARGV0=oracleflqb)(ARGS=\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\))(ENVS=ORACLE_SID=flqb))(CONNECT_DATA=(SID=flqb))) AS SYSDBA" transport_tablespaces= TSPITR, TEST dumpfile=dmpfile.dmp directory=STREAMS_DIROBJ_DPDIR logfile=explog.log
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
Master table "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TRANSPORTABLE_01 is:
  /u02/transport/dmpfile.dmp
Job "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 20:38:23

host command complete
/*
   The following command may be used to import the tablespaces.
   Substitute values for  and .
   impdp  directory= dumpfile= 'dmpfile.dmp' transport_datafiles= /u02/transport/tspitr01.dbf, /u02/transport/test01.dbf
*/
--------------------------------------------------------------
-- Start of sample PL/SQL script for importing the tablespaces
--------------------------------------------------------------
-- creating directory objects
CREATE DIRECTORY STREAMS$DIROBJ$1 AS  '/u02/transport/';
CREATE DIRECTORY STREAMS$DIROBJ$DPDIR AS  '/u02/transport';
/* PL/SQL Script to import the exported tablespaces */
DECLARE
  -- the datafiles
  tbs_files     dbms_streams_tablespace_adm.file_set;
  cvt_files     dbms_streams_tablespace_adm.file_set;
  -- the dumpfile to import
  dump_file     dbms_streams_tablespace_adm.file;
  dp_job_name   VARCHAR2(30) := NULL;
  -- names of tablespaces that were imported
  ts_names       dbms_streams_tablespace_adm.tablespace_set;
BEGIN
  -- dump file name and location
  dump_file.file_name :=  'dmpfile.dmp';
  dump_file.directory_object := 'STREAMS$DIROBJ$DPDIR';
  -- forming list of datafiles for import
  tbs_files( 1).file_name :=  'tspitr01.dbf';
  tbs_files( 1).directory_object :=  'STREAMS$DIROBJ$1';
  tbs_files( 2).file_name :=  'test01.dbf';
  tbs_files( 2).directory_object :=  'STREAMS$DIROBJ$1';
  -- import tablespaces
  dbms_streams_tablespace_adm.attach_tablespaces(
    datapump_job_name      => dp_job_name,
    dump_file              => dump_file,
    tablespace_files       => tbs_files,
    converted_files        => cvt_files,
    tablespace_names       => ts_names);
  -- output names of imported tablespaces
  IF ts_names IS NOT NULL AND ts_names.first IS NOT NULL THEN
    FOR i IN ts_names.first .. ts_names.last LOOP
      dbms_output.put_line('imported tablespace '|| ts_names(i));
    END LOOP;
  END IF;
END;
/
-- dropping directory objects
DROP DIRECTORY STREAMS$DIROBJ$1;
DROP DIRECTORY STREAMS$DIROBJ$DPDIR;
--------------------------------------------------------------
-- End of sample PL/SQL script
--------------------------------------------------------------

Removing automatic instance
shutting down automatic instance
Oracle instance shut down
Automatic instance removed
auxiliary instance file /u02/transport/cntrl_tspitr_TEST_flqb.f deleted
auxiliary instance file /u02/transport/TSPITR_TEST_FLQB/datafile/o1_mf_system_bk7z8fsc_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_FLQB/datafile/o1_mf_undotbs1_bk7z8ft1_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_FLQB/datafile/o1_mf_sysaux_bk7z8fsp_.dbf deleted
auxiliary instance file /u02/transport/TSPITR_TEST_FLQB/datafile/o1_mf_temp_bk7zcm9b_.tmp deleted
auxiliary instance file /u02/transport/TSPITR_TEST_FLQB/onlinelog/o1_mf_1_bk7zc5pm_.log deleted
auxiliary instance file /u02/transport/TSPITR_TEST_FLQB/onlinelog/o1_mf_2_bk7zc8bl_.log deleted
auxiliary instance file /u02/transport/TSPITR_TEST_FLQB/onlinelog/o1_mf_3_bk7zcbvb_.log deleted;

执行成功后在/u02/transport目录中生成了以下文件及临时目录,要被传输的表空间的数据文件使用了其原始文件名,传输表空间集的Data Pump导出文件是dmpfile.dmp,导出日志文件是explog.log,示例导入脚本是impscrpt.sql,而所有辅助文件被删除了。

[oracle@oracle11g transport]$ ls -lrt
total 112888
drwxr-x--- 4 oracle oinstall      4096 Mar 26 20:35 TSPITR_TEST_FLQB
-rw-r----- 1 oracle oinstall 104865792 Mar 26 20:37 tspitr01.dbf
-rw-r----- 1 oracle oinstall  10493952 Mar 26 20:37 test01.dbf
-rw-r--r-- 1 oracle oinstall      1255 Mar 26 20:38 explog.log
-rw-r----- 1 oracle oinstall     98304 Mar 26 20:38 dmpfile.dmp
-rw-r--r-- 1 oracle oinstall      2179 Mar 26 20:38 impscrpt.sql

示例导入脚本impscrpt.sql的内容如下所示:

[oracle@oracle11g transport]$ cat impscrpt.sql
/*
   The following command may be used to import the tablespaces.
   Substitute values for  and .
   impdp  directory= dumpfile= 'dmpfile.dmp' transport_datafiles= /u02/transport/tspitr01.dbf, /u02/transport/test01.dbf
*/
--------------------------------------------------------------
-- Start of sample PL/SQL script for importing the tablespaces
--------------------------------------------------------------
-- creating directory objects
CREATE DIRECTORY STREAMS$DIROBJ$1 AS  '/u02/transport/';
CREATE DIRECTORY STREAMS$DIROBJ$DPDIR AS  '/u02/transport';
/* PL/SQL Script to import the exported tablespaces */
DECLARE
  -- the datafiles
  tbs_files     dbms_streams_tablespace_adm.file_set;
  cvt_files     dbms_streams_tablespace_adm.file_set;
  -- the dumpfile to import
  dump_file     dbms_streams_tablespace_adm.file;
  dp_job_name   VARCHAR2(30) := NULL;
  -- names of tablespaces that were imported
  ts_names       dbms_streams_tablespace_adm.tablespace_set;
BEGIN
  -- dump file name and location
  dump_file.file_name :=  'dmpfile.dmp';
  dump_file.directory_object := 'STREAMS$DIROBJ$DPDIR';
  -- forming list of datafiles for import
  tbs_files( 1).file_name :=  'tspitr01.dbf';
  tbs_files( 1).directory_object :=  'STREAMS$DIROBJ$1';
  tbs_files( 2).file_name :=  'test01.dbf';
  tbs_files( 2).directory_object :=  'STREAMS$DIROBJ$1';
  -- import tablespaces
  dbms_streams_tablespace_adm.attach_tablespaces(
    datapump_job_name      => dp_job_name,
    dump_file              => dump_file,
    tablespace_files       => tbs_files,
    converted_files        => cvt_files,
    tablespace_names       => ts_names);
  -- output names of imported tablespaces
  IF ts_names IS NOT NULL AND ts_names.first IS NOT NULL THEN
    FOR i IN ts_names.first .. ts_names.last LOOP
      dbms_output.put_line('imported tablespace '|| ts_names(i));
    END LOOP;
  END IF;
END;
/
-- dropping directory objects
DROP DIRECTORY STREAMS$DIROBJ$1;
DROP DIRECTORY STREAMS$DIROBJ$DPDIR;
--------------------------------------------------------------
-- End of sample PL/SQL script
--------------------------------------------------------------

5.将步骤4生成的传输表空间的数据文件tspitr01.dbf,test01.dbf和Data Pump导出文件dmpfile拷贝到目标主机上的/u02目录中

[root@jingyong1 u02]# scp -r oracle@192.168.56.2:/u02/transport/tspitr01.dbf /u02
oracle@192.168.56.2's password:
tspitr01.dbf                                                                                                                         100%  100MB   9.1MB/s   00:11
[root@jingyong1 u02]# scp -r oracle@192.168.56.2:/u02/transport/test01.dbf /u02
oracle@192.168.56.2's password:
test01.dbf
[root@jingyong1 u02]# scp -r oracle@192.168.56.2:/u02/transport/dmpfile.dmp /u02
oracle@192.168.56.2's password:
dmpfile.dmp                                                                                                                          100%   96KB  96.0KB/s   00:00
                                                                                                                      100%   10MB  10.0MB/s   00:01
[root@jingyong1 u02]# ls -lrt
total 112776
-rw-r----- 1 root root 104865792 Mar 26 20:51 tspitr01.dbf
-rw-r----- 1 root root  10493952 Mar 26 20:51 test01.dbf
-rw-r----- 1 root   root         98304 Mar 26 21:06 dmpfile.dmp

[root@jingyong1 u02]# chown -R oracle:oinstall *
[root@jingyong1 u02]# chmod -R 777 *
[root@jingyong1 u02]# ls -lrt
total 112876
-rwxrwxrwx 1 oracle oinstall 104865792 Mar 26 20:51 tspitr01.dbf
-rwxrwxrwx 1 oracle oinstall  10493952 Mar 26 20:51 test01.dbf
-rwxrwxrwx 1 oracle oinstall     98304 Mar 26 21:06 dmpfile.dmp

6.在目录主机上创建相关用户及Data Pump目录并将表空间附加到目标数据库中

SQL> create user tspitr identified by "tspitr";

User created.

SQL> grant dba,connect,resource to tspitr;

Grant succeeded.

SQL> create user test identified by "test";

User created.

SQL> grant dba,connect,resource to test;

Grant succeeded.

SQL> create directory mytest as '/u02';

Directory created.

SQL> grant read,write on directory mytest to public;

Grant succeeded.

最后就可以执行导入过程了

[oracle@jingyong1 dbs]$ export ORACLE_SID=jy
[oracle@jingyong1 dbs]$ export NLS_DATE_FORMATE='yyyy-mm-dd hh24:mi:ss'
[oracle@jingyong1 dbs]$ impdp test/test directory=mytest dumpfile=dmpfile.dmp logfile=testtransport.log transport_datafiles= /u02/tspitr01.dbf, /u02/test01.dbf

Import: Release 10.2.0.5.0 - Production on Thursday, 26 March, 2015 21:14:59

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "TEST"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded
Starting "TEST"."SYS_IMPORT_TRANSPORTABLE_01":  test/******** directory=mytest dumpfile=dmpfile.dmp logfile=testtransport.log transport_datafiles= /u02/tspitr01.dbf, /u02/test01.dbf
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 "TEST"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at 21:15:28

进入数据库中检查一下

SQL> conn tspitr/tspitr
Connected.
SQL> select count(*) from tspitr;

  COUNT(*)
----------
     50641

SQL> conn test/test
Connected.
SQL> select count(*) from test;

  COUNT(*)
----------
     50680

RMAN复制数据库(十)

使用PFILE参数文件执行duplicate
可以使用辅助实例的PFILE参数文件来执行duplicate命令,测试环境如下:
1.目标数据库test主机是oracle11g,复制数据库dup主机是jingyong1
2.PFILE参数文件/u01/app/oracle/product/10.2.0/db/dbs/initdup.ora存储在主机jingyong1上。
3.主机oracle11g与jingyong1通过网络连接
在这种情况下可以在主机oracle11g或jingyong1上执行duplicate命令.

在主机jingyong1上执行duplicate命令的执行步骤如下:
1.创建辅助实例的密码文件(这里辅助实例名为dup)

[oracle@jingyong1 dbs]$ orapwd file=/u01/app/oracle/product/10.2.0/db/dbs/orapwdup password=oracle entries=10
[oracle@jingyong1 dbs]$ ls -lrt orapwdup
-rw-r----- 1 oracle oinstall 2560 Mar 25 20:49 orapwdup

2.创建辅助实例网络连接,修改监听文件,使用静态监听来监听辅助实例远程主机jingyong1

[oracle@jingyong1 admin]$ vi listener.ora

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
     (SID_NAME = dup)
      (ORACLE_HOME =/u01/app/oracle/product/10.2.0/db)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.11)(PORT = 1521))
    )
  )

给辅助实例增加网络服务名

[oracle@jingyong1 admin]$ vi tnsnames.ora
dup =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.56.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME =dup)
      (UR=A)
    )
  )

在复制主机上给目标实例增加网络服务名(增加以下信息)

[oracle@jingyong1 admin]$ vi tnsnames.ora

test =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.56.2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME =test)
      (UR=A)
    )
  )

测试网络连接
远程主机jingyong1

[oracle@jingyong1 admin]$ export ORACLE_SID=dup
[oracle@jingyong1 admin]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Mar 25 20:53:26 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/oracle@dup as sysdba
Connected to an idle instance.

目标主机

[oracle@jingyong1 admin]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Thu Mar 26 10:20:56 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/zzh_2046@test as sysdba
Connected.

3.创建辅助实例的参数文件

[oracle@jingyong1 dbs]$ vi initdup.ora

db_name=dup
db_unique_name=dup
control_files= /u01/app/oracle/oradata/dup/control01.ctl
#db_file_name_convert=('/u01/app/oracle/oradata/test/','/u01/app/oracle/oradata/dup/')
#log_file_name_convert=('/u01/app/oracle/oradata/test/','/u01/app/oracle/oradata/dup/')
remote_login_passwordfile=exclusive
compatible = 10.2.0.5.0
db_block_size=8192
sga_target=160M
sga_max_size=160M
pga_aggregate_target=16M




[oracle@jingyong1 dbs]$ export ORACLE_SID=dup
[oracle@jingyong1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Mar 25 21:08:14 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.




4.启动辅助实例

[oracle@jingyong1 dbs]$ export ORACLE_SID=dup
[oracle@jingyong1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Thu Mar 26 09:06:57 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

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

Total System Global Area  167772160 bytes
Fixed Size                  1272624 bytes
Variable Size              58721488 bytes
Database Buffers          104857600 bytes
Redo Buffers                2920448 bytes
SQL> set long 300
SQL> set linesize 300
SQL> show parameter spfile

NAME                                 TYPE                   VALUE
------------------------------------ ---------------------- ------------------------------
spfile                               string

断开连接

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

这里一定要断开启动辅助实例的会话否则在执行复制操作时会出现如下错误 :

executing Memory Script

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 03/24/2015 18:28:32
RMAN-03015: error occurred in stored script Memory Script
RMAN-06136: ORACLE error from auxiliary database: ORA-01013: user requested cancel of current operation

5.加载或打开目标数据库

[oracle@oracle11g ~]$ export ORACLE_SID=test
[oracle@oracle11g ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Thu Mar 26 08:49:51 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272600 bytes
Variable Size              92275944 bytes
Database Buffers           71303168 bytes
Redo Buffers                2920448 bytes
Database mounted.
Database opened.

6.确保有需要的备份和归档重做日志,对目标数据库(被复制的数据库)进行备份(包含数据文件和归档重做日志)

[oracle@oracle11g admin]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@oracle11g admin]$ rman target sys/zzh_2046@test catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Tue Mar 24 15:15:52 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database

RMAN> backup as backupset database plus archivelog delete all input;


Starting backup at 25-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=65 recid=72 stamp=875262973
input archive log thread=1 sequence=66 recid=73 stamp=875266238
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266246_751 tag=TAG20150325T093040 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u02/1_65_870806981.dbf recid=72 stamp=875262973
archive log filename=/u02/1_66_870806981.dbf recid=73 stamp=875266238
Finished backup at 25-MAR-15

Starting backup at 25-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/test/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/test/example01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/test/tspitr01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/test/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266253_761 tag=TAG20150325T093052 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:46
Finished backup at 25-MAR-15

Starting backup at 25-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=67 recid=74 stamp=875266422
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266425_771 tag=TAG20150325T093344 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u02/1_67_870806981.dbf recid=74 stamp=875266422
Finished backup at 25-MAR-15

Starting Control File and SPFILE Autobackup at 25-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_25/o1_mf_s_875266428_bk4441pd_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 25-MAR-15

RMAN> list backup;


List of Backup Sets
===================

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
4782    5.72M      DISK        00:00:04     25-MAR-15
        BP Key: 4783   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093040
        Piece Name: /u02/ora_test875266246_751

  List of Archived Logs in backup set 4782
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    65      1009334    24-MAR-15 1038362    25-MAR-15
  1    66      1038362    25-MAR-15 1040219    25-MAR-15

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4794    Full    624.76M    DISK        00:02:40     25-MAR-15
        BP Key: 4797   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093052
        Piece Name: /u02/ora_test875266253_761
  List of Datafiles in backup set 4794
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/system01.dbf
  2       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/undotbs01.dbf
  3       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/sysaux01.dbf
  4       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/users01.dbf
  5       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/example01.dbf
  6       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/tspitr01.dbf

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
4811    12.50K     DISK        00:00:01     25-MAR-15
        BP Key: 4818   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093344
        Piece Name: /u02/ora_test875266425_771

  List of Archived Logs in backup set 4811
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    67      1040219    25-MAR-15 1040304    25-MAR-15

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4827    Full    6.89M      DISK        00:00:06     25-MAR-15
        BP Key: 4829   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093348
        Piece Name: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_25/o1_mf_s_875266428_bk4441pd_.bkp
  Control File Included: Ckp SCN: 1040326      Ckp time: 25-MAR-15
  SPFILE Included: Modification time: 25-MAR-15

将上面的备份传输到远程主机的相同目录中:

[oracle@jingyong1 dup]$ scp -r oracle@192.168.56.2:/u02/ora_test875266246_751 /u02
oracle@192.168.56.2's password:
ora_test875266246_751                                                                                                                100% 5857KB   5.7MB/s   00:00
[oracle@jingyong1 dup]$ scp -r oracle@192.168.56.2:/u02/ora_test875266253_761 /u02
oracle@192.168.56.2's password:
ora_test875266253_761                                                                                                                100%  625MB   8.1MB/s   01:17
[oracle@jingyong1 dup]$ scp -r oracle@192.168.56.2:/u02/ora_test875266425_771 /u02
oracle@192.168.56.2's password:
ora_test875266425_771                                                                                                                100%   13KB  13.0KB/s   00:00
[oracle@jingyong1 dup]$ scp -r oracle@192.168.56.2:/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_25/o1_mf_s_875266428_bk4441pd_.bkp /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015-03-25
oracle@192.168.56.2's password:
o1_mf_s_875266428_bk4441pd_.bkp

7.执行duplicate命令,如果没有配置自动通道,那么至少手动分配一个辅助实例如果是使用PFILE参数文件启动辅助实例需要指定pfile参数文件,且pfile参数文件必须存储在运行RMAN执行复制的主机上。这里辅助实例使用PFILE参数文件来启动,并使用自动通道:

[oracle@jingyong1 ~]$ export NLS_DATE_FORMATE='yyyy-mm-dd hh24:mi:ss'
[oracle@jingyong1 ~]$ rman target sys/zzh_2046@test auxiliary sys/oracle@dup catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Thu Mar 26 10:28:09 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database
connected to auxiliary database: DUP (not mounted)

RMAN> duplicate target database to dup device type disk pfile='/u01/app/oracle/product/10.2.0/db/dbs/initdup.ora';

Starting Duplicate Db at 26-MAR-15
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=36 devtype=DISK

contents of Memory Script:
{
   set until scn  1126817;
   set newname for datafile  1 to
 "/u01/app/oracle/oradata/dup/system01.dbf";
   set newname for datafile  2 to
 "/u01/app/oracle/oradata/dup/undotbs01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/oradata/dup/sysaux01.dbf";
   set newname for datafile  4 to
 "/u01/app/oracle/oradata/dup/users01.dbf";
   set newname for datafile  5 to
 "/u01/app/oracle/oradata/dup/example01.dbf";
   set newname for datafile  6 to
 "/u01/app/oracle/oradata/dup/tspitr01.dbf";
   restore
   check readonly
   clone database
   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 26-MAR-15
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/dup/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/dup/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/dup/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/dup/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/dup/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/dup/tspitr01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875266253_761
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875266253_761 tag=TAG20150325T093052
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:26
Finished restore at 26-MAR-15
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUP" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '/u01/app/oracle/oradata/dup/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '/u01/app/oracle/oradata/dup/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '/u01/app/oracle/oradata/dup/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/dup/system01.dbf'
 CHARACTER SET ZHS16GBK


contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875356263 filename=/u01/app/oracle/oradata/dup/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875356263 filename=/u01/app/oracle/oradata/dup/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875356263 filename=/u01/app/oracle/oradata/dup/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875356263 filename=/u01/app/oracle/oradata/dup/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875356263 filename=/u01/app/oracle/oradata/dup/tspitr01.dbf

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

executing command: SET until clause

Starting recover at 26-MAR-15
using channel ORA_AUX_DISK_1

starting media recovery

channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=67
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875266425_771
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875266425_771 tag=TAG20150325T093344
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_67_870806981.dbf thread=1 sequence=67
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_67_870806981.dbf recid=1 stamp=875356267
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=68
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=69
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875292006_791
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875292006_791 tag=TAG20150325T164005
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_68_870806981.dbf thread=1 sequence=68
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_68_870806981.dbf recid=3 stamp=875356270
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_69_870806981.dbf thread=1 sequence=69
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_69_870806981.dbf recid=2 stamp=875356270
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=70
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=71
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875308493_811
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875308493_811 tag=TAG20150325T211453
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_70_870806981.dbf thread=1 sequence=70
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_70_870806981.dbf recid=4 stamp=875356282
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_71_870806981.dbf thread=1 sequence=71
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_71_870806981.dbf recid=5 stamp=875356283
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=72
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=73
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875351407_831
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875351407_831 tag=TAG20150326T091000
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_72_870806981.dbf thread=1 sequence=72
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_72_870806981.dbf recid=7 stamp=875356293
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_73_870806981.dbf thread=1 sequence=73
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_73_870806981.dbf recid=6 stamp=875356292
media recovery complete, elapsed time: 00:00:16
Finished recover at 26-MAR-15

contents of Memory Script:
{
   shutdown clone;
   startup clone nomount pfile= '/u01/app/oracle/product/10.2.0/db/dbs/initdup.ora';
}
executing Memory Script

database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     167772160 bytes

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


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

executing command: SET NEWNAME

renamed temporary file 1 to /u01/app/oracle/oradata/dup/temp01.dbf in control file

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/dup/undotbs01.dbf recid=1 stamp=875356321

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/dup/sysaux01.dbf recid=2 stamp=875356321

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/dup/users01.dbf recid=3 stamp=875356321

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/dup/example01.dbf recid=4 stamp=875356322

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/dup/tspitr01.dbf recid=5 stamp=875356322

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875356321 filename=/u01/app/oracle/oradata/dup/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875356321 filename=/u01/app/oracle/oradata/dup/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875356321 filename=/u01/app/oracle/oradata/dup/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875356322 filename=/u01/app/oracle/oradata/dup/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875356322 filename=/u01/app/oracle/oradata/dup/tspitr01.dbf

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

database opened
Finished Duplicate Db at 26-MAR-15

在主机oracle11g上执行duplicate命令的执行步骤如下:
1.创建辅助实例的密码文件(这里辅助实例名为dup)

[oracle@jingyong1 dbs]$ orapwd file=/u01/app/oracle/product/10.2.0/db/dbs/orapwdup password=oracle entries=10
[oracle@jingyong1 dbs]$ ls -lrt orapwdup
-rw-r----- 1 oracle oinstall 2560 Mar 25 20:49 orapwdup

2.创建辅助实例网络连接,修改监听文件,使用静态监听来监听辅助实例远程主机jingyong1

[oracle@jingyong1 admin]$ vi listener.ora

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
     (SID_NAME = dup)
      (ORACLE_HOME =/u01/app/oracle/product/10.2.0/db)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.11)(PORT = 1521))
    )
  )

给辅助实例增加网络服务名

[oracle@jingyong1 admin]$ vi tnsnames.ora
dup =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.56.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME =dup)
      (UR=A)
    )
  )

在复制主机上给目标实例增加网络服务名(增加以下信息)

[oracle@jingyong1 admin]$ vi tnsnames.ora

test =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.56.2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME =test)
      (UR=A)
    )
  )

测试网络连接
远程主机jingyong1

[oracle@jingyong1 admin]$ export ORACLE_SID=dup
[oracle@jingyong1 admin]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Mar 25 20:53:26 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/oracle@dup as sysdba
Connected to an idle instance.

目标主机

[oracle@oracle11g admin]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Thu Mar 26 10:20:56 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/zzh_2046@test as sysdba
Connected.

3.创建辅助实例的参数文件

[oracle@jingyong1 dbs]$ vi initdup.ora

db_name=dup
db_unique_name=dup
control_files= /u01/app/oracle/oradata/dup/control01.ctl
#db_file_name_convert=('/u01/app/oracle/oradata/test/','/u01/app/oracle/oradata/dup/')
#log_file_name_convert=('/u01/app/oracle/oradata/test/','/u01/app/oracle/oradata/dup/')
remote_login_passwordfile=exclusive
compatible = 10.2.0.5.0
db_block_size=8192
sga_target=160M
sga_max_size=160M
pga_aggregate_target=16M




[oracle@jingyong1 dbs]$ export ORACLE_SID=dup
[oracle@jingyong1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Mar 25 21:08:14 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.



4.启动辅助实例

[oracle@jingyong1 dbs]$ export ORACLE_SID=dup
[oracle@jingyong1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Thu Mar 26 09:06:57 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

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

Total System Global Area  167772160 bytes
Fixed Size                  1272624 bytes
Variable Size              58721488 bytes
Database Buffers          104857600 bytes
Redo Buffers                2920448 bytes
SQL> set long 300
SQL> set linesize 300
SQL> show parameter spfile

NAME                                 TYPE                   VALUE
------------------------------------ ---------------------- ------------------------------
spfile                               string


断开连接

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

这里一定要断开启动辅助实例的会话否则在执行复制操作时会出现如下错误 :

executing Memory Script

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 03/24/2015 18:28:32
RMAN-03015: error occurred in stored script Memory Script
RMAN-06136: ORACLE error from auxiliary database: ORA-01013: user requested cancel of current operation

5.加载或打开目标数据库

[oracle@oracle11g ~]$ export ORACLE_SID=test
[oracle@oracle11g ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Thu Mar 26 08:49:51 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272600 bytes
Variable Size              92275944 bytes
Database Buffers           71303168 bytes
Redo Buffers                2920448 bytes
Database mounted.
Database opened.

6.确保有需要的备份和归档重做日志,对目标数据库(被复制的数据库)进行备份(包含数据文件和归档重做日志)

[oracle@oracle11g admin]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@oracle11g admin]$ rman target sys/zzh_2046@test catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Tue Mar 24 15:15:52 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database

RMAN> backup as backupset database plus archivelog delete all input;


Starting backup at 25-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=65 recid=72 stamp=875262973
input archive log thread=1 sequence=66 recid=73 stamp=875266238
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266246_751 tag=TAG20150325T093040 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u02/1_65_870806981.dbf recid=72 stamp=875262973
archive log filename=/u02/1_66_870806981.dbf recid=73 stamp=875266238
Finished backup at 25-MAR-15

Starting backup at 25-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/test/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/test/example01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/test/tspitr01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/test/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266253_761 tag=TAG20150325T093052 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:46
Finished backup at 25-MAR-15

Starting backup at 25-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=67 recid=74 stamp=875266422
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266425_771 tag=TAG20150325T093344 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u02/1_67_870806981.dbf recid=74 stamp=875266422
Finished backup at 25-MAR-15

Starting Control File and SPFILE Autobackup at 25-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_25/o1_mf_s_875266428_bk4441pd_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 25-MAR-15

RMAN> list backup;


List of Backup Sets
===================

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
4782    5.72M      DISK        00:00:04     25-MAR-15
        BP Key: 4783   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093040
        Piece Name: /u02/ora_test875266246_751

  List of Archived Logs in backup set 4782
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    65      1009334    24-MAR-15 1038362    25-MAR-15
  1    66      1038362    25-MAR-15 1040219    25-MAR-15

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4794    Full    624.76M    DISK        00:02:40     25-MAR-15
        BP Key: 4797   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093052
        Piece Name: /u02/ora_test875266253_761
  List of Datafiles in backup set 4794
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/system01.dbf
  2       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/undotbs01.dbf
  3       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/sysaux01.dbf
  4       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/users01.dbf
  5       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/example01.dbf
  6       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/tspitr01.dbf

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
4811    12.50K     DISK        00:00:01     25-MAR-15
        BP Key: 4818   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093344
        Piece Name: /u02/ora_test875266425_771

  List of Archived Logs in backup set 4811
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    67      1040219    25-MAR-15 1040304    25-MAR-15

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4827    Full    6.89M      DISK        00:00:06     25-MAR-15
        BP Key: 4829   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093348
        Piece Name: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_25/o1_mf_s_875266428_bk4441pd_.bkp
  Control File Included: Ckp SCN: 1040326      Ckp time: 25-MAR-15
  SPFILE Included: Modification time: 25-MAR-15

将上面的备份传输到远程主机的相同目录中:

[oracle@jingyong1 dup]$ scp -r oracle@192.168.56.2:/u02/ora_test875266246_751 /u02
oracle@192.168.56.2's password:
ora_test875266246_751                                                                                                                100% 5857KB   5.7MB/s   00:00
[oracle@jingyong1 dup]$ scp -r oracle@192.168.56.2:/u02/ora_test875266253_761 /u02
oracle@192.168.56.2's password:
ora_test875266253_761                                                                                                                100%  625MB   8.1MB/s   01:17
[oracle@jingyong1 dup]$ scp -r oracle@192.168.56.2:/u02/ora_test875266425_771 /u02
oracle@192.168.56.2's password:
ora_test875266425_771                                                                                                                100%   13KB  13.0KB/s   00:00
[oracle@jingyong1 dup]$ scp -r oracle@192.168.56.2:/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_25/o1_mf_s_875266428_bk4441pd_.bkp /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015-03-25
oracle@192.168.56.2's password:
o1_mf_s_875266428_bk4441pd_.bkp

7.将复制主机jingyong1上的参数文件目录/u01/app/oracle/product/10.2.0/db/dbs作为NFS挂载到目标主机oracle11g中的/jingyong1目录具体操作请参考http://blog.itpub.net/26015009/viewspace-1474224/

8.执行duplicate命令,如果没有配置自动通道,那么至少手动分配一个辅助实例如果是使用PFILE参数文件启动辅助实例需要指定pfile参数文件,且pfile参数文件必须存储在运行RMAN执行复制的主机上。这里辅助实例使用PFILE参数文件来启动,这里在主机oracle11g上执行RMAN命令,为了能让RMAN访问主机jingyong1上的辅助实例pfile参数文件使用NFS来引用pfile参数文件:

[oracle@oracle11g admin]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@oracle11g admin]$ rman target sys/zzh_2046@test auxiliary sys/oracle@dup catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Thu Mar 26 11:32:46 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database
connected to auxiliary database: DUP (not mounted)

RMAN>

RMAN> duplicate target database to dup device type disk pfile='/jingyong1/initdup.ora';

Starting Duplicate Db at 2015-03-26 11:39:05
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=38 devtype=DISK

contents of Memory Script:
{
   set until scn  1126817;
   set newname for datafile  1 to
 "/u01/app/oracle/oradata/dup/system01.dbf";
   set newname for datafile  2 to
 "/u01/app/oracle/oradata/dup/undotbs01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/oradata/dup/sysaux01.dbf";
   set newname for datafile  4 to
 "/u01/app/oracle/oradata/dup/users01.dbf";
   set newname for datafile  5 to
 "/u01/app/oracle/oradata/dup/example01.dbf";
   set newname for datafile  6 to
 "/u01/app/oracle/oradata/dup/tspitr01.dbf";
   restore
   check readonly
   clone database
   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 2015-03-26 11:39:05
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/dup/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/dup/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/dup/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/dup/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/dup/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/dup/tspitr01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875266253_761
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875266253_761 tag=TAG20150325T093052
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:06
Finished restore at 2015-03-26 11:40:12
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUP" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '/u01/app/oracle/oradata/dup/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '/u01/app/oracle/oradata/dup/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '/u01/app/oracle/oradata/dup/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/dup/system01.dbf'
 CHARACTER SET ZHS16GBK


contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875360416 filename=/u01/app/oracle/oradata/dup/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875360416 filename=/u01/app/oracle/oradata/dup/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875360416 filename=/u01/app/oracle/oradata/dup/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875360416 filename=/u01/app/oracle/oradata/dup/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875360416 filename=/u01/app/oracle/oradata/dup/tspitr01.dbf

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

executing command: SET until clause

Starting recover at 2015-03-26 11:40:14
using channel ORA_AUX_DISK_1

starting media recovery

channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=67
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875266425_771
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875266425_771 tag=TAG20150325T093344
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_67_870806981.dbf thread=1 sequence=67
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_67_870806981.dbf recid=1 stamp=875360419
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=68
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=69
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875292006_791
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875292006_791 tag=TAG20150325T164005
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_68_870806981.dbf thread=1 sequence=68
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_68_870806981.dbf recid=3 stamp=875360422
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_69_870806981.dbf thread=1 sequence=69
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_69_870806981.dbf recid=2 stamp=875360421
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=70
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=71
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875308493_811
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875308493_811 tag=TAG20150325T211453
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_70_870806981.dbf thread=1 sequence=70
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_70_870806981.dbf recid=4 stamp=875360434
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_71_870806981.dbf thread=1 sequence=71
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_71_870806981.dbf recid=5 stamp=875360435
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=72
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=73
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875351407_831
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875351407_831 tag=TAG20150326T091000
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_72_870806981.dbf thread=1 sequence=72
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_72_870806981.dbf recid=7 stamp=875360449
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_73_870806981.dbf thread=1 sequence=73
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_73_870806981.dbf recid=6 stamp=875360448
media recovery complete, elapsed time: 00:00:14
Finished recover at 2015-03-26 11:41:01

contents of Memory Script:
{
   shutdown clone;
   startup clone nomount pfile= '/jingyong1/initdup.ora';
}
executing Memory Script

database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     167772160 bytes

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


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

executing command: SET NEWNAME

renamed temporary file 1 to /u01/app/oracle/oradata/dup/temp01.dbf in control file

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/dup/undotbs01.dbf recid=1 stamp=875360473

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/dup/sysaux01.dbf recid=2 stamp=875360473

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/dup/users01.dbf recid=3 stamp=875360473

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/dup/example01.dbf recid=4 stamp=875360473

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/dup/tspitr01.dbf recid=5 stamp=875360473

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875360473 filename=/u01/app/oracle/oradata/dup/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875360473 filename=/u01/app/oracle/oradata/dup/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875360473 filename=/u01/app/oracle/oradata/dup/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875360473 filename=/u01/app/oracle/oradata/dup/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875360473 filename=/u01/app/oracle/oradata/dup/tspitr01.dbf

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

database opened
Finished Duplicate Db at 2015-03-26 11:41:33

RMAN复制数据库(九)

使用rman duplicate database to a Past Point in Time
测试环境如下:
1.目标数据库test与复制数据库dup在不同的主机上使用不同的目标结构
2.使用恢复目录数据库jy
3.使用disk和sbt配置的自动通道
4.主机oracle11g上有ASM磁盘组+DISK1
5.将复制数据库dup恢复到2015-03-26 09:00:00
6.在主机oracle11g上创建的备份与归档重做日志必须能被主机jingyong1访问

执行步骤如下:
1.创建辅助实例的密码文件(这里辅助实例名为dup)

[oracle@jingyong1 dbs]$ orapwd file=/u01/app/oracle/product/10.2.0/db/dbs/orapwdup password=oracle entries=10
[oracle@jingyong1 dbs]$ ls -lrt orapwdup
-rw-r----- 1 oracle oinstall 2560 Mar 25 20:49 orapwdup

2.创建辅助实例网络连接,修改监听文件,使用静态监听来监听辅助实例远程主机jingyong1

[oracle@jingyong1 admin]$ vi listener.ora

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
     (SID_NAME = dup)
      (ORACLE_HOME =/u01/app/oracle/product/10.2.0/db)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.11)(PORT = 1521))
    )
  )

给辅助实例增加网络服务名

[oracle@jingyong1 admin]$ vi tnsnames.ora
dup =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.56.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME =dup)
      (UR=A)
    )
  )

在目标主机上给辅助实例增加网络服务名

[oracle@oracle11g admin]$ vi tnsnames.ora
dup =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.56.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME =dup)
      (UR=A)
    )
  )

测试网络连接
远程主机jingyong1

[oracle@jingyong1 admin]$ export ORACLE_SID=dup
[oracle@jingyong1 admin]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Mar 25 20:53:26 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/oracle@dup as sysdba
Connected to an idle instance.

目标主机oracle11g

[oracle@oracle11g admin]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Mar 25 21:00:13 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/oracle@dup as sysdba
Connected to an idle instance.

3.创建辅助实例的参数文件

[oracle@jingyong1 dbs]$ vi initdup.ora

db_name=dup
db_unique_name=dup
control_files= /u01/app/oracle/oradata/dup/control01.ctl
#db_file_name_convert=('/u01/app/oracle/oradata/test/','/u01/app/oracle/oradata/dup/')
#log_file_name_convert=('/u01/app/oracle/oradata/test/','/u01/app/oracle/oradata/dup/')
remote_login_passwordfile=exclusive
compatible = 10.2.0.5.0
db_block_size=8192
sga_target=160M
sga_max_size=160M
pga_aggregate_target=16M




[oracle@jingyong1 dbs]$ export ORACLE_SID=dup
[oracle@jingyong1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Mar 25 21:08:14 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

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

File created.

4.启动辅助实例

[oracle@jingyong1 dbs]$ export ORACLE_SID=dup
[oracle@jingyong1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Thu Mar 26 09:06:57 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup nomount
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272624 bytes
Variable Size              58721488 bytes
Database Buffers          104857600 bytes
Redo Buffers                2920448 bytes
SQL> set long 300
SQL> set linesize 300
SQL> show parameter spfile

NAME                                 TYPE                   VALUE
------------------------------------ ---------------------- ------------------------------
spfile                               string                 /u01/app/oracle/product/10.2.0
                                                            /db/dbs/spfiledup.ora

断开连接

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

这里一定要断开启动辅助实例的会话否则在执行复制操作时会出现如下错误 :

executing Memory Script

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 03/24/2015 18:28:32
RMAN-03015: error occurred in stored script Memory Script
RMAN-06136: ORACLE error from auxiliary database: ORA-01013: user requested cancel of current operation

5.加载或打开目标数据库

[oracle@oracle11g ~]$ export ORACLE_SID=test
[oracle@oracle11g ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Thu Mar 26 08:49:51 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272600 bytes
Variable Size              92275944 bytes
Database Buffers           71303168 bytes
Redo Buffers                2920448 bytes
Database mounted.
Database opened.

6.确保有需要的备份和归档重做日志,对目标数据库(被复制的数据库)进行备份(包含数据文件和归档重做日志)

[oracle@oracle11g admin]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@oracle11g admin]$ rman target sys/zzh_2046@test catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Tue Mar 24 15:15:52 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database

RMAN> backup as backupset database plus archivelog delete all input;


Starting backup at 25-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=65 recid=72 stamp=875262973
input archive log thread=1 sequence=66 recid=73 stamp=875266238
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266246_751 tag=TAG20150325T093040 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u02/1_65_870806981.dbf recid=72 stamp=875262973
archive log filename=/u02/1_66_870806981.dbf recid=73 stamp=875266238
Finished backup at 25-MAR-15

Starting backup at 25-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/test/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/test/example01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/test/tspitr01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/test/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266253_761 tag=TAG20150325T093052 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:46
Finished backup at 25-MAR-15

Starting backup at 25-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=67 recid=74 stamp=875266422
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266425_771 tag=TAG20150325T093344 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u02/1_67_870806981.dbf recid=74 stamp=875266422
Finished backup at 25-MAR-15

Starting Control File and SPFILE Autobackup at 25-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_25/o1_mf_s_875266428_bk4441pd_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 25-MAR-15

RMAN> list backup;


List of Backup Sets
===================

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
4782    5.72M      DISK        00:00:04     25-MAR-15
        BP Key: 4783   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093040
        Piece Name: /u02/ora_test875266246_751

  List of Archived Logs in backup set 4782
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    65      1009334    24-MAR-15 1038362    25-MAR-15
  1    66      1038362    25-MAR-15 1040219    25-MAR-15

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4794    Full    624.76M    DISK        00:02:40     25-MAR-15
        BP Key: 4797   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093052
        Piece Name: /u02/ora_test875266253_761
  List of Datafiles in backup set 4794
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/system01.dbf
  2       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/undotbs01.dbf
  3       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/sysaux01.dbf
  4       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/users01.dbf
  5       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/example01.dbf
  6       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/tspitr01.dbf

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
4811    12.50K     DISK        00:00:01     25-MAR-15
        BP Key: 4818   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093344
        Piece Name: /u02/ora_test875266425_771

  List of Archived Logs in backup set 4811
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    67      1040219    25-MAR-15 1040304    25-MAR-15

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4827    Full    6.89M      DISK        00:00:06     25-MAR-15
        BP Key: 4829   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093348
        Piece Name: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_25/o1_mf_s_875266428_bk4441pd_.bkp
  Control File Included: Ckp SCN: 1040326      Ckp time: 25-MAR-15
  SPFILE Included: Modification time: 25-MAR-15

将上面的备份传输到远程主机的相同目录中:

[oracle@jingyong1 dup]$ scp -r oracle@192.168.56.2:/u02/ora_test875266246_751 /u02
oracle@192.168.56.2's password:
ora_test875266246_751                                                                                                                100% 5857KB   5.7MB/s   00:00
[oracle@jingyong1 dup]$ scp -r oracle@192.168.56.2:/u02/ora_test875266253_761 /u02
oracle@192.168.56.2's password:
ora_test875266253_761                                                                                                                100%  625MB   8.1MB/s   01:17
[oracle@jingyong1 dup]$ scp -r oracle@192.168.56.2:/u02/ora_test875266425_771 /u02
oracle@192.168.56.2's password:
ora_test875266425_771                                                                                                                100%   13KB  13.0KB/s   00:00
[oracle@jingyong1 dup]$ scp -r oracle@192.168.56.2:/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_25/o1_mf_s_875266428_bk4441pd_.bkp /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015-03-25
oracle@192.168.56.2's password:
o1_mf_s_875266428_bk4441pd_.bkp

7.执行duplicate命令,如果没有配置自动通道,那么至少手动分配一个辅助实例如果是使用PFILE参数文件启动辅助实例需要指定pfile参数文件,且pfile参数文件必须存储在运行RMAN执行复制的主机上。这里辅助实例使用SPFILE参数文件来启动,并使用自动通道:

[oracle@oracle11g admin]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@oracle11g admin]$ rman target sys/zzh_2046@test auxiliary sys/oracle@dup catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Thu Mar 26 09:22:10 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database
connected to auxiliary database: DUP (not mounted)

RMAN> duplicate target database to dup until time "to_date('2015-03-26 09:00:00','yyyy-mm-dd hh24:mi:ss')";

Starting Duplicate Db at 2015-03-26 09:22:55
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=37 devtype=DISK

contents of Memory Script:
{
   set until scn  1125870;
   set newname for datafile  1 to
 "/u01/app/oracle/oradata/dup/system01.dbf";
   set newname for datafile  2 to
 "/u01/app/oracle/oradata/dup/undotbs01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/oradata/dup/sysaux01.dbf";
   set newname for datafile  4 to
 "/u01/app/oracle/oradata/dup/users01.dbf";
   set newname for datafile  5 to
 "/u01/app/oracle/oradata/dup/example01.dbf";
   set newname for datafile  6 to
 "/u01/app/oracle/oradata/dup/tspitr01.dbf";
   restore
   check readonly
   clone database
   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 2015-03-26 09:22:56
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/dup/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/dup/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/dup/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/dup/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/dup/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/dup/tspitr01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875266253_761
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875266253_761 tag=TAG20150325T093052
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:16
Finished restore at 2015-03-26 09:24:14
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUP" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '/u01/app/oracle/oradata/dup/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '/u01/app/oracle/oradata/dup/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '/u01/app/oracle/oradata/dup/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/dup/system01.dbf'
 CHARACTER SET ZHS16GBK


contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875352256 filename=/u01/app/oracle/oradata/dup/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875352256 filename=/u01/app/oracle/oradata/dup/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875352256 filename=/u01/app/oracle/oradata/dup/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875352256 filename=/u01/app/oracle/oradata/dup/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875352256 filename=/u01/app/oracle/oradata/dup/tspitr01.dbf

contents of Memory Script:
{
   set until time  "to_date('2015-03-26 09:00:00','yyyy-mm-dd hh24:mi:ss')";
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 2015-03-26 09:24:15
using channel ORA_AUX_DISK_1

starting media recovery

channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=67
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875266425_771
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875266425_771 tag=TAG20150325T093344
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_67_870806981.dbf thread=1 sequence=67
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_67_870806981.dbf recid=1 stamp=875352261
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=68
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=69
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875292006_791
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875292006_791 tag=TAG20150325T164005
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_68_870806981.dbf thread=1 sequence=68
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_68_870806981.dbf recid=3 stamp=875352263
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_69_870806981.dbf thread=1 sequence=69
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_69_870806981.dbf recid=2 stamp=875352263
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=70
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=71
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875308493_811
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875308493_811 tag=TAG20150325T211453
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_70_870806981.dbf thread=1 sequence=70
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_70_870806981.dbf recid=4 stamp=875352274
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_71_870806981.dbf thread=1 sequence=71
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_71_870806981.dbf recid=5 stamp=875352274
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=72
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=73
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875351407_831
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875351407_831 tag=TAG20150326T091000
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_72_870806981.dbf thread=1 sequence=72
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_72_870806981.dbf recid=7 stamp=875352285
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_73_870806981.dbf thread=1 sequence=73
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_73_870806981.dbf recid=6 stamp=875352283
media recovery complete, elapsed time: 00:00:14
Finished recover at 2015-03-26 09:24:59

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

database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     167772160 bytes

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


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

executing command: SET NEWNAME

renamed temporary file 1 to /u01/app/oracle/oradata/dup/temp01.dbf in control file

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/dup/undotbs01.dbf recid=1 stamp=875352312

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/dup/sysaux01.dbf recid=2 stamp=875352312

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/dup/users01.dbf recid=3 stamp=875352312

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/dup/example01.dbf recid=4 stamp=875352312

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/dup/tspitr01.dbf recid=5 stamp=875352312

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875352312 filename=/u01/app/oracle/oradata/dup/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875352312 filename=/u01/app/oracle/oradata/dup/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875352312 filename=/u01/app/oracle/oradata/dup/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875352312 filename=/u01/app/oracle/oradata/dup/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875352312 filename=/u01/app/oracle/oradata/dup/tspitr01.dbf

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

database opened
Finished Duplicate Db at 2015-03-26 09:25:43

RMAN复制数据库(八)

使用RMAN DUPLICATE DATABASE From ASM to ASM
测试环境如下:
1.使用了恢复目录数据库jy
2.目标数据库dupdb在主机jingyong1上,并且数据文件是存储在磁盘组+DG1中
3.将目标数据库dupdb复制到远程主机oracle11g上生成数据库dupcp。
4.主机oracle11g上有ASM磁盘组+DISK1
5.将数据库dupcp的数据文件存储在磁盘组+DISK1中
6.在磁盘组+DISK1中存储两份控制文件
7.在主机jingyong1上创建的备份与归档重做日志必须能被主机oracle11g访问

执行步骤如下:
1.创建辅助实例的密码文件(这里辅助实例名为dupcp)

[oracle@oracle11g dbs]$ orapwd file=/u01/app/oracle/10.2.0/db/dbs/orapwdupcp password=oracle entries=10
[oracle@oracle11g dbs]$ ls -lrt orapwdupcp
-rw-r----- 1 oracle oinstall 2560 Mar 25 22:05 orapwdupcp

2.创建辅助实例网络连接,修改监听文件,使用静态监听来监听辅助实例远程主机oracle11g

[oracle@oracle11g admin]$ vi listener.ora

SID_LIST_LISTENER =
  (SID_LIST =

    (SID_DESC =
     (SID_NAME = dupcp)
      (ORACLE_HOME =/u01/app/oracle/10.2.0/db)
    )

  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.2)(PORT = 1521))
    )
  )

给辅助实例增加网络服务名

[oracle@oracle11g admin]$ vi tnsnames.ora
dupcp =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.56.2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME =dupcp)
      (UR=A)
    )
  )

在目标主机上给辅助实例增加网络服务名

[oracle@jingyong1 admin]$ vi tnsnames.ora
dupcp =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.56.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME =dupcp)
      (UR=A)
    )
  )

测试网络连接
远程主机oracle11g

[oracle@oracle11g admin]$ export ORACLE_SID=dupcp
[oracle@oracle11g admin]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Mar 25 22:14:49 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/oracle@dupcp as sysdba
Connected to an idle instance.

目标主机jingyong1

[oracle@jingyong1 admin]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Mar 25 22:16:10 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/oracle@dupcp as sysdba
Connected to an idle instance.


3.创建辅助实例的参数文件

[oracle@oracle11g dbs]$ vi initdupcp.ora

db_name=dupcp
db_unique_name=dupcp
control_files=('+DISK1/control01.ctl','+DISK1/control02.ctl')
db_file_name_convert=('+DG1/','+DISK1/')
log_file_name_convert=('+DG1/','+DISK1/')
remote_login_passwordfile=exclusive
compatible = 10.2.0.5.0
db_block_size=8192
sga_target=160M
sga_max_size=160M
pga_aggregate_target=16M





[oracle@oracle11g dbs]$ export ORACLE_SID=dupcp
[oracle@oracle11g dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Mar 25 22:21:16 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> create spfile from pfile='/u01/app/oracle/10.2.0/db/dbs/initdupcp.ora';

File created.

4.启动辅助实例

[oracle@oracle11g dbs]$ export ORACLE_SID=dupcp
[oracle@oracle11g dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Mar 25 22:22:12 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup nomount
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272624 bytes
Variable Size              58721488 bytes
Database Buffers          104857600 bytes
Redo Buffers                2920448 bytes
SQL> set long 300
SQL> set linesize 300
SQL> show parameter spfile

NAME                                 TYPE                   VALUE
------------------------------------ ---------------------- ------------------------------
spfile                               string                 /u01/app/oracle/10.2.0/db/dbs/
                                                            spfiledupcp.ora

断开连接

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

这里一定要断开启动辅助实例的会话否则在执行复制操作时会出现如下错误 :

executing Memory Script

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 03/24/2015 18:28:32
RMAN-03015: error occurred in stored script Memory Script
RMAN-06136: ORACLE error from auxiliary database: ORA-01013: user requested cancel of current operation


5.加载或打开目标数据库

[oracle@jingyong1 u02]$ export ORACLE_SID=dupdb
[oracle@jingyong1 u02]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 21:13:44 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272600 bytes
Variable Size              92275944 bytes
Database Buffers           71303168 bytes
Redo Buffers                2920448 bytes
Database mounted.
Database opened.

6.确保有需要的备份和归档重做日志,对目标数据库(被复制的数据库)进行备份(包含数据文件和归档重做日志)

[oracle@jingyong1 dbs]$ rman target sys/oracle@dupdb catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Wed Mar 25 21:47:53 2015

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

connected to target database: DUPDB (DBID=600524259)
connected to recovery catalog database



RMAN> backup as backupset database plus archivelog;


Starting backup at 25-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=1 recid=1 stamp=875310741
input archive log thread=1 sequence=2 recid=2 stamp=875310860
input archive log thread=1 sequence=3 recid=3 stamp=875310962
input archive log thread=1 sequence=4 recid=4 stamp=875311041
input archive log thread=1 sequence=5 recid=5 stamp=875311330
input archive log thread=1 sequence=6 recid=6 stamp=875311560
input archive log thread=1 sequence=7 recid=7 stamp=875312933
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_dupdb875312935_131 tag=TAG20150325T222854 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:05
Finished backup at 25-MAR-15

Starting backup at 25-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=+DG1/system01.dbf
input datafile fno=00003 name=+DG1/sysaux01.dbf
input datafile fno=00005 name=+DG1/example01.dbf
input datafile fno=00006 name=+DG1/tspitr01.dbf
input datafile fno=00002 name=+DG1/undotbs01.dbf
input datafile fno=00004 name=+DG1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_dupdb875312941_141 tag=TAG20150325T222900 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:39
Finished backup at 25-MAR-15

Starting backup at 25-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=8 recid=8 stamp=875313048
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_dupdb875313054_151 tag=TAG20150325T223053 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 25-MAR-15

Starting Control File and SPFILE Autobackup at 25-MAR-15
piece handle=/u02/dupdb_c-600524259-20150325-02 comment=NONE
Finished Control File and SPFILE Autobackup at 25-MAR-15

RMAN> list backup;


List of Backup Sets
===================

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
5648    18.11M     DISK        00:00:04     25-MAR-15
        BP Key: 5649   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T222854
        Piece Name: /u02/ora_dupdb875312935_131

  List of Archived Logs in backup set 5648
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    1       1093435    25-MAR-15 1094797    25-MAR-15
  1    2       1094797    25-MAR-15 1094860    25-MAR-15
  1    3       1094860    25-MAR-15 1094957    25-MAR-15
  1    4       1094957    25-MAR-15 1095004    25-MAR-15
  1    5       1095004    25-MAR-15 1095738    25-MAR-15
  1    6       1095738    25-MAR-15 1098358    25-MAR-15
  1    7       1098358    25-MAR-15 1103796    25-MAR-15

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
5683    Full    633.66M    DISK        00:01:31     25-MAR-15
        BP Key: 5691   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T222900
        Piece Name: /u02/ora_dupdb875312941_141
  List of Datafiles in backup set 5683
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1103818    25-MAR-15 +DG1/system01.dbf
  2       Full 1103818    25-MAR-15 +DG1/undotbs01.dbf
  3       Full 1103818    25-MAR-15 +DG1/sysaux01.dbf
  4       Full 1103818    25-MAR-15 +DG1/users01.dbf
  5       Full 1103818    25-MAR-15 +DG1/example01.dbf
  6       Full 1103818    25-MAR-15 +DG1/tspitr01.dbf

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
5723    2.50K      DISK        00:00:01     25-MAR-15
        BP Key: 5730   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T223053
        Piece Name: /u02/ora_dupdb875313054_151

  List of Archived Logs in backup set 5723
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    8       1103796    25-MAR-15 1103855    25-MAR-15

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
5757    Full    7.11M      DISK        00:00:05     25-MAR-15
        BP Key: 5759   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T223057
        Piece Name: /u02/dupdb_c-600524259-20150325-02
  Control File Included: Ckp SCN: 1103879      Ckp time: 25-MAR-15
  SPFILE Included: Modification time: 25-MAR-15

将上面的备份传输到远程主机的相同目录中:

[oracle@oracle11g u02]$ scp -r oracle@192.168.56.11:/u02/ora_dupdb875312935_131 /u02
The authenticity of host '192.168.56.11 (192.168.56.11)' can't be established.
RSA key fingerprint is 8b:38:ef:bf:d4:1e:9e:2a:cb:31:67:6c:3b:83:3f:62.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.56.11' (RSA) to the list of known hosts.
oracle@192.168.56.11's password:
ora_dupdb875312935_131                                                                                                               100%   18MB   3.6MB/s   00:05
[oracle@oracle11g u02]$ scp -r oracle@192.168.56.11:/u02/ora_dupdb875312941_141 /u02
oracle@192.168.56.11's password:
ora_dupdb875312941_141                                                                                                               100%  634MB   6.7MB/s   01:35
[oracle@oracle11g u02]$ scp -r oracle@192.168.56.11:/u02/ora_dupdb875313054_151 /u02
oracle@192.168.56.11's password:
ora_dupdb875313054_151                                                                                                               100% 3072     3.0KB/s   00:00
[oracle@oracle11g u02]$ scp -r oracle@192.168.56.11:/u02/dupdb_c-600524259-20150325-02 /u02
oracle@192.168.56.11's password:
dupdb_c-600524259-20150325-02                                                                                                        100% 7296KB   7.1MB/s   00:01
[oracle@oracle11g u02]$

检查磁盘组+DISK1的空间使用情况,要有足够的空间存储复制数据库的所有文件

ASMCMD> lsdg
State    Type    Rebal  Unbal  Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_MB  Usable_file_MB  Offline_disks  Name
MOUNTED  EXTERN  N      N         512   4096  1048576      4096     4046                0            4046              0  DISK1/

7.执行duplicate命令,如果没有配置自动通道,那么至少手动分配一个辅助实例如果是使用PFILE参数文件启动辅助实例需要指定pfile参数文件,且pfile参数文件必须存储在运行RMAN执行复制的主机上。这里辅助实例使用SPFILE参数文件来启动,并使用自动通道:

[oracle@jingyong1 dbs]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@jingyong1 dbs]$ rman target sys/oracle@dupdb catalog rman/rman@jy auxiliary sys/oracle@dupcp

Recovery Manager: Release 10.2.0.5.0 - Production on Wed Mar 25 22:47:55 2015

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

connected to target database: DUPDB (DBID=600524259)
connected to recovery catalog database
connected to auxiliary database: DUPCP (not mounted)

RMAN> duplicate target database to dupcp;

Starting Duplicate Db at 2015-03-25 22:48:15
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=36 devtype=DISK

contents of Memory Script:
{
   set until scn  1103855;
   set newname for datafile  1 to
 "+DISK1/system01.dbf";
   set newname for datafile  2 to
 "+DISK1/undotbs01.dbf";
   set newname for datafile  3 to
 "+DISK1/sysaux01.dbf";
   set newname for datafile  4 to
 "+DISK1/users01.dbf";
   set newname for datafile  5 to
 "+DISK1/example01.dbf";
   set newname for datafile  6 to
 "+DISK1/tspitr01.dbf";
   restore
   check readonly
   clone database
   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 2015-03-25 22:48:18
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to +DISK1/system01.dbf
restoring datafile 00002 to +DISK1/undotbs01.dbf
restoring datafile 00003 to +DISK1/sysaux01.dbf
restoring datafile 00004 to +DISK1/users01.dbf
restoring datafile 00005 to +DISK1/example01.dbf
restoring datafile 00006 to +DISK1/tspitr01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_dupdb875312941_141
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_dupdb875312941_141 tag=TAG20150325T222900
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:06
Finished restore at 2015-03-25 22:49:31
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUPCP" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '+DISK1/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '+DISK1/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '+DISK1/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '+DISK1/system01.dbf'
 CHARACTER SET ZHS16GBK


contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875314184 filename=+DISK1/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875314184 filename=+DISK1/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875314184 filename=+DISK1/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875314184 filename=+DISK1/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875314184 filename=+DISK1/tspitr01.dbf

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

executing command: SET until clause

Starting recover at 2015-03-25 22:49:37
using channel ORA_AUX_DISK_1

starting media recovery

channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=8
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_dupdb875313054_151
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_dupdb875313054_151 tag=TAG20150325T223053
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archive log filename=/u01/app/oracle/10.2.0/db/dbs/arch1_8_875310182.dbf thread=1 sequence=8
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/10.2.0/db/dbs/arch1_8_875310182.dbf recid=1 stamp=875314186
media recovery complete, elapsed time: 00:00:02
Finished recover at 2015-03-25 22:49:43

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

database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     167772160 bytes

Fixed Size                     1272624 bytes
Variable Size                 58721488 bytes
Database Buffers             104857600 bytes
Redo Buffers                   2920448 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUPCP" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '+DISK1/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '+DISK1/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '+DISK1/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '+DISK1/system01.dbf'
 CHARACTER SET ZHS16GBK


contents of Memory Script:
{
   set newname for tempfile  1 to
 "+DISK1/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "+DISK1/undotbs01.dbf";
   catalog clone datafilecopy  "+DISK1/sysaux01.dbf";
   catalog clone datafilecopy  "+DISK1/users01.dbf";
   catalog clone datafilecopy  "+DISK1/example01.dbf";
   catalog clone datafilecopy  "+DISK1/tspitr01.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed temporary file 1 to +DISK1/temp01.dbf in control file

cataloged datafile copy
datafile copy filename=+DISK1/undotbs01.dbf recid=1 stamp=875314211

cataloged datafile copy
datafile copy filename=+DISK1/sysaux01.dbf recid=2 stamp=875314211

cataloged datafile copy
datafile copy filename=+DISK1/users01.dbf recid=3 stamp=875314211

cataloged datafile copy
datafile copy filename=+DISK1/example01.dbf recid=4 stamp=875314212

cataloged datafile copy
datafile copy filename=+DISK1/tspitr01.dbf recid=5 stamp=875314212

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875314211 filename=+DISK1/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875314211 filename=+DISK1/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875314211 filename=+DISK1/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875314212 filename=+DISK1/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875314212 filename=+DISK1/tspitr01.dbf

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

database opened
Finished Duplicate Db at 2015-03-25 22:50:24

RMAN复制数据库(七)

使用RMAN duplicate database from file System to ASM
测试环境如下:
1.使用了恢复目录数据库jy
2.目标数据库test在主机oracle11g上,并且数据文件是存储在文件系统中
3.将目标数据库test复制到远程主机jingyong1上生成数据库dupdb。
4.主机jingyong1上有ASM磁盘组+dg1
5.将数据库dupdb的数据文件存储在磁盘组+dg1中
6.在磁盘组+dg1中存储两份控制文件
7.在主机oracle11g上创建的备份与归档重做日志必须能被主机jingyong1访问

执行步骤如下:
1.创建辅助实例的密码文件(这里辅助实例名为dupdb)

[oracle@jingyong1 dbs]$ orapwd file=/u01/app/oracle/product/10.2.0/db/dbs/orapwdupdb password=oracle entries=10
[oracle@jingyong1 dbs]$ ls -lrt orapwdupdb
-rw-r----- 1 oracle oinstall 2560 Mar 25 20:49 orapwdupdb

2.创建辅助实例网络连接,修改监听文件,使用静态监听来监听辅助实例远程主机jingyong1

[oracle@jingyong1 admin]$ vi listener.ora

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
     (SID_NAME = dupdb)
      (ORACLE_HOME =/u01/app/oracle/product/10.2.0/db)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.11)(PORT = 1521))
    )
  )

给辅助实例增加网络服务名

[oracle@jingyong1 admin]$ vi tnsnames.ora
dupdb =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.56.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME =dupdb)
      (UR=A)
    )
  )

在目标主机上给辅助实例增加网络服务名

[oracle@oracle11g admin]$ vi tnsnames.ora
dupdb =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.56.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME =dupdb)
      (UR=A)
    )
  )

测试网络连接
远程主机jingyong1

[oracle@jingyong1 admin]$ export ORACLE_SID=dupdb
[oracle@jingyong1 admin]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Mar 25 20:53:26 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/oracle@dupdb as sysdba
Connected to an idle instance.

目标主机oracle11g

[oracle@oracle11g admin]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Mar 25 21:00:13 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/oracle@dupdb as sysdba
Connected to an idle instance.

3.创建辅助实例的参数文件

[oracle@jingyong1 dbs]$ vi initdupdb.ora

db_name=dupdb
db_unique_name=dupdb
control_files=('+DG1/control01.ctl','+DG1/control02.ctl')
db_file_name_convert=('/u01/app/oracle/oradata/test/','+DG1/')
log_file_name_convert=('/u01/app/oracle/oradata/test/','+DG1/')
remote_login_passwordfile=exclusive
compatible = 10.2.0.5.0
db_block_size=8192
sga_target=160M
sga_max_size=160M
pga_aggregate_target=16M



[oracle@jingyong1 dbs]$ export ORACLE_SID=dupdb
[oracle@jingyong1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Mar 25 21:08:14 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

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

File created.

4.启动辅助实例

[oracle@jingyong1 dbs]$ export ORACLE_SID=dupdb
[oracle@jingyong1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Mar 25 21:10:09 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup nomount
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272624 bytes
Variable Size              58721488 bytes
Database Buffers          104857600 bytes
Redo Buffers                2920448 bytes


SQL> set long 300
SQL> set linesize 300
SQL> show parameter spfile

NAME                                 TYPE                   VALUE
------------------------------------ ---------------------- ------------------------------
spfile                               string                 /u01/app/oracle/product/10.2.0
                                                            /db/dbs/spfiledupdb.ora

断开连接

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

这里一定要断开启动辅助实例的会话否则在执行复制操作时会出现如下错误 :

executing Memory Script

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 03/24/2015 18:28:32
RMAN-03015: error occurred in stored script Memory Script
RMAN-06136: ORACLE error from auxiliary database: ORA-01013: user requested cancel of current operation

5.加载或打开目标数据库

[oracle@oracle11g ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 21:13:44 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272600 bytes
Variable Size              92275944 bytes
Database Buffers           71303168 bytes
Redo Buffers                2920448 bytes
Database mounted.
Database opened.

6.确保有需要的备份和归档重做日志,对目标数据库(被复制的数据库)进行备份(包含数据文件和归档重做日志)

[oracle@oracle11g admin]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@oracle11g admin]$ rman target sys/zzh_2046@test catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Tue Mar 24 15:15:52 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database

RMAN> backup as backupset database plus archivelog delete all input;


Starting backup at 25-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=65 recid=72 stamp=875262973
input archive log thread=1 sequence=66 recid=73 stamp=875266238
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266246_751 tag=TAG20150325T093040 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u02/1_65_870806981.dbf recid=72 stamp=875262973
archive log filename=/u02/1_66_870806981.dbf recid=73 stamp=875266238
Finished backup at 25-MAR-15

Starting backup at 25-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/test/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/test/example01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/test/tspitr01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/test/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266253_761 tag=TAG20150325T093052 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:46
Finished backup at 25-MAR-15

Starting backup at 25-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=67 recid=74 stamp=875266422
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266425_771 tag=TAG20150325T093344 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u02/1_67_870806981.dbf recid=74 stamp=875266422
Finished backup at 25-MAR-15

Starting Control File and SPFILE Autobackup at 25-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_25/o1_mf_s_875266428_bk4441pd_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 25-MAR-15

RMAN> list backup;


List of Backup Sets
===================

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
4782    5.72M      DISK        00:00:04     25-MAR-15
        BP Key: 4783   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093040
        Piece Name: /u02/ora_test875266246_751

  List of Archived Logs in backup set 4782
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    65      1009334    24-MAR-15 1038362    25-MAR-15
  1    66      1038362    25-MAR-15 1040219    25-MAR-15

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4794    Full    624.76M    DISK        00:02:40     25-MAR-15
        BP Key: 4797   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093052
        Piece Name: /u02/ora_test875266253_761
  List of Datafiles in backup set 4794
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/system01.dbf
  2       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/undotbs01.dbf
  3       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/sysaux01.dbf
  4       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/users01.dbf
  5       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/example01.dbf
  6       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/tspitr01.dbf

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
4811    12.50K     DISK        00:00:01     25-MAR-15
        BP Key: 4818   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093344
        Piece Name: /u02/ora_test875266425_771

  List of Archived Logs in backup set 4811
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    67      1040219    25-MAR-15 1040304    25-MAR-15

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4827    Full    6.89M      DISK        00:00:06     25-MAR-15
        BP Key: 4829   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093348
        Piece Name: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_25/o1_mf_s_875266428_bk4441pd_.bkp
  Control File Included: Ckp SCN: 1040326      Ckp time: 25-MAR-15
  SPFILE Included: Modification time: 25-MAR-15

将上面的备份传输到远程主机的相同目录中:

[oracle@jingyong1 dup]$ scp -r oracle@192.168.56.2:/u02/ora_test875266246_751 /u02
oracle@192.168.56.2's password:
ora_test875266246_751                                                                                                                100% 5857KB   5.7MB/s   00:00
[oracle@jingyong1 dup]$ scp -r oracle@192.168.56.2:/u02/ora_test875266253_761 /u02
oracle@192.168.56.2's password:
ora_test875266253_761                                                                                                                100%  625MB   8.1MB/s   01:17
[oracle@jingyong1 dup]$ scp -r oracle@192.168.56.2:/u02/ora_test875266425_771 /u02
oracle@192.168.56.2's password:
ora_test875266425_771                                                                                                                100%   13KB  13.0KB/s   00:00
[oracle@jingyong1 dup]$ scp -r oracle@192.168.56.2:/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_25/o1_mf_s_875266428_bk4441pd_.bkp /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015-03-25
oracle@192.168.56.2's password:
o1_mf_s_875266428_bk4441pd_.bkp

检查磁盘组+DG1的空间使用情况,要有足够的空间存储复制数据库的所有文件

ASMCMD> lsdg
State    Type    Rebal  Unbal  Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_MB  Usable_file_MB  Offline_disks  Name
MOUNTED  EXTERN  N      N         512   4096  1048576      4096     4045                0            4045              0  DG1/

7.执行duplicate命令,如果没有配置自动通道,那么至少手动分配一个辅助实例如果是使用PFILE参数文件启动辅助实例需要指定pfile参数文件,且pfile参数文件必须存储在运行RMAN执行复制的主机上。这里辅助实例使用SPFILE参数文件来启动,并使用自动通道:

[oracle@oracle11g admin]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@oracle11g admin]$ rman target sys/zzh_2046@test auxiliary sys/oracle@dupdb catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Wed Mar 25 21:26:07 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database
connected to auxiliary database: DUPDB (not mounted)

RMAN> duplicate target database to dupdb;

Starting Duplicate Db at 2015-03-25 21:26:22
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=35 devtype=DISK

contents of Memory Script:
{
   set until scn  1093434;
   set newname for datafile  1 to
 "+DG1/system01.dbf";
   set newname for datafile  2 to
 "+DG1/undotbs01.dbf";
   set newname for datafile  3 to
 "+DG1/sysaux01.dbf";
   set newname for datafile  4 to
 "+DG1/users01.dbf";
   set newname for datafile  5 to
 "+DG1/example01.dbf";
   set newname for datafile  6 to
 "+DG1/tspitr01.dbf";
   restore
   check readonly
   clone database
   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 2015-03-25 21:26:23
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to +DG1/system01.dbf
restoring datafile 00002 to +DG1/undotbs01.dbf
restoring datafile 00003 to +DG1/sysaux01.dbf
restoring datafile 00004 to +DG1/users01.dbf
restoring datafile 00005 to +DG1/example01.dbf
restoring datafile 00006 to +DG1/tspitr01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875266253_761
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875266253_761 tag=TAG20150325T093052
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:05
Finished restore at 2015-03-25 21:27:32
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUPDB" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '+DG1/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '+DG1/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '+DG1/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '+DG1/system01.dbf'
 CHARACTER SET ZHS16GBK


contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875309253 filename=+DG1/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875309253 filename=+DG1/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875309253 filename=+DG1/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875309253 filename=+DG1/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875309253 filename=+DG1/tspitr01.dbf

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

executing command: SET until clause

Starting recover at 2015-03-25 21:27:37
using channel ORA_AUX_DISK_1

starting media recovery

channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=67
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875266425_771
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875266425_771 tag=TAG20150325T093344
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_67_870806981.dbf thread=1 sequence=67
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_67_870806981.dbf recid=1 stamp=875309258
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=68
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=69
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875292006_791
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875292006_791 tag=TAG20150325T164005
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_68_870806981.dbf thread=1 sequence=68
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_68_870806981.dbf recid=3 stamp=875309261
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_69_870806981.dbf thread=1 sequence=69
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_69_870806981.dbf recid=2 stamp=875309260
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=70
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=71
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875308493_811
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875308493_811 tag=TAG20150325T211453
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_70_870806981.dbf thread=1 sequence=70
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_70_870806981.dbf recid=4 stamp=875309268
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_71_870806981.dbf thread=1 sequence=71
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_71_870806981.dbf recid=5 stamp=875309268
media recovery complete, elapsed time: 00:00:04
Finished recover at 2015-03-25 21:27:57

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

database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     167772160 bytes

Fixed Size                     1272624 bytes
Variable Size                 58721488 bytes
Database Buffers             104857600 bytes
Redo Buffers                   2920448 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUPDB" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '+DG1/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '+DG1/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '+DG1/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '+DG1/system01.dbf'
 CHARACTER SET ZHS16GBK


contents of Memory Script:
{
   set newname for tempfile  1 to
 "+DG1/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "+DG1/undotbs01.dbf";
   catalog clone datafilecopy  "+DG1/sysaux01.dbf";
   catalog clone datafilecopy  "+DG1/users01.dbf";
   catalog clone datafilecopy  "+DG1/example01.dbf";
   catalog clone datafilecopy  "+DG1/tspitr01.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed temporary file 1 to +DG1/temp01.dbf in control file

cataloged datafile copy
datafile copy filename=+DG1/undotbs01.dbf recid=1 stamp=875309291

cataloged datafile copy
datafile copy filename=+DG1/sysaux01.dbf recid=2 stamp=875309291

cataloged datafile copy
datafile copy filename=+DG1/users01.dbf recid=3 stamp=875309291

cataloged datafile copy
datafile copy filename=+DG1/example01.dbf recid=4 stamp=875309292

cataloged datafile copy
datafile copy filename=+DG1/tspitr01.dbf recid=5 stamp=875309292

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875309291 filename=+DG1/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875309291 filename=+DG1/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875309291 filename=+DG1/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875309292 filename=+DG1/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875309292 filename=+DG1/tspitr01.dbf

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

database opened
Finished Duplicate Db at 2015-03-25 21:28:33

RMAN复制数据库(六)

在相同主机上创建复制数据库
当在与目标数据库相同主机上创建复制数据库就与在远程主机上使用不同目录结构复制数据库一样。可以在目标数据库的Oracle Home目录中创建复制数据库,但数据库名必须不同于目标数据库。

1.创建辅助实例的密码文件(这里辅助实例名为aux)

[oracle@oracle11g dbs]$ orapwd file=/u01/app/oracle/product/10.2.0/db/dbs/orapwaux password=oracle entries=10;
[oracle@oracle11g dbs]$ ls -lrt
-rw-r----- 1 oracle oinstall    2560 Mar 24 14:47 orapwdup

2.创建辅助实例网络连接,修改监听文件,使用静态监听来监听辅助实例

[oracle@oracle11g dbs]$ vi listener.ora

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
     (SID_NAME = aux)
      (ORACLE_HOME =/u01/app/oracle/product/10.2.0/db)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.11)(PORT = 1521))
    )
  )

给辅助实例增加网络服务名

[oracle@oracle11g dbs]$ vi tnsnames.ora
aux =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.56.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME =aux)
      (UR=A)
    )
  )

测试网络连接

[oracle@oracle11g dbs]$ export ORACLE_SID=aux
[oracle@oracle11g dbs]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 14:57:08 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/oracle@dup as sysdba
Connected to an idle instance.

3.创建辅助实例的参数文件

[oracle@oracle11g dbs]$ vi initdup.ora

db_name=aux
db_unique_name=aux
control_files= /u01/app/oracle/oradata/aux/control01.ctl
db_file_name_convert=('/u01/app/oracle/oradata/test/','/u01/app/oracle/oradata/aux/')
log_file_name_convert=('/u01/app/oracle/oradata/test/','/u01/app/oracle/oradata/aux/')
remote_login_passwordfile=exclusive
compatible = 10.2.0.5.0
db_block_size=8192
sga_target=160M
sga_max_size=160M
pga_aggregate_target=16M



[oracle@oracle11g dbs]$ export ORACLE_SID=aux
[oracle@oracle11g dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 21:13:44 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

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

File created.

4.启动辅助实例

[oracle@oracle11g dbs]$ export ORACLE_SID=aux
[oracle@oracle11g dbs]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 21:13:44 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


SQL> conn sys/oracle@dup as sysdba
Connected to an idle instance.

SQL> startup nomount
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272624 bytes
Variable Size              58721488 bytes
Database Buffers          104857600 bytes
Redo Buffers                2920448 bytes

SQL> show parameter spfile

NAME                                 TYPE                   VALUE
------------------------------------ ---------------------- ------------------------------
spfile                               string                 /u01/app/oracle/product/10.2.0
                                                            /db/dbs/spfileaux.ora

断开连接

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

这里一定要断开启动辅助实例的会话否则在执行复制操作时会出现如下错误 :

executing Memory Script

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 03/24/2015 18:28:32
RMAN-03015: error occurred in stored script Memory Script
RMAN-06136: ORACLE error from auxiliary database: ORA-01013: user requested cancel of current operation

配置辅助实例的网络服务名

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

JY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = jy)
    )
  )

TEST =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.2)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = test)
    )
  )




aux =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.56.2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME =aux)
      (UR=A)
    )
  )

[oracle@oracle11g dbs]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 21:13:44 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/oracle@aux as sysdba
Connected.

5.加载或打开目标数据库

[oracle@oracle11g ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 21:13:44 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272600 bytes
Variable Size              92275944 bytes
Database Buffers           71303168 bytes
Redo Buffers                2920448 bytes
Database mounted.
Database opened.

6.确保有需要的备份和归档重做日志,对目标数据库(被复制的数据库)进行备份(包含数据文件和归档重做日志)

[oracle@oracle11g admin]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@oracle11g admin]$ rman target sys/zzh_2046@test catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Tue Mar 24 15:15:52 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database

RMAN> backup as backupset database plus archivelog delete all input;


Starting backup at 25-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=65 recid=72 stamp=875262973
input archive log thread=1 sequence=66 recid=73 stamp=875266238
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266246_751 tag=TAG20150325T093040 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u02/1_65_870806981.dbf recid=72 stamp=875262973
archive log filename=/u02/1_66_870806981.dbf recid=73 stamp=875266238
Finished backup at 25-MAR-15

Starting backup at 25-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/test/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/test/example01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/test/tspitr01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/test/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266253_761 tag=TAG20150325T093052 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:46
Finished backup at 25-MAR-15

Starting backup at 25-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=67 recid=74 stamp=875266422
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266425_771 tag=TAG20150325T093344 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u02/1_67_870806981.dbf recid=74 stamp=875266422
Finished backup at 25-MAR-15

Starting Control File and SPFILE Autobackup at 25-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_25/o1_mf_s_875266428_bk4441pd_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 25-MAR-15

RMAN> list backup;


List of Backup Sets
===================

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
4782    5.72M      DISK        00:00:04     25-MAR-15
        BP Key: 4783   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093040
        Piece Name: /u02/ora_test875266246_751

  List of Archived Logs in backup set 4782
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    65      1009334    24-MAR-15 1038362    25-MAR-15
  1    66      1038362    25-MAR-15 1040219    25-MAR-15

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4794    Full    624.76M    DISK        00:02:40     25-MAR-15
        BP Key: 4797   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093052
        Piece Name: /u02/ora_test875266253_761
  List of Datafiles in backup set 4794
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/system01.dbf
  2       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/undotbs01.dbf
  3       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/sysaux01.dbf
  4       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/users01.dbf
  5       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/example01.dbf
  6       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/tspitr01.dbf

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
4811    12.50K     DISK        00:00:01     25-MAR-15
        BP Key: 4818   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093344
        Piece Name: /u02/ora_test875266425_771

  List of Archived Logs in backup set 4811
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    67      1040219    25-MAR-15 1040304    25-MAR-15

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4827    Full    6.89M      DISK        00:00:06     25-MAR-15
        BP Key: 4829   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093348
        Piece Name: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_25/o1_mf_s_875266428_bk4441pd_.bkp
  Control File Included: Ckp SCN: 1040326      Ckp time: 25-MAR-15
  SPFILE Included: Modification time: 25-MAR-15

7.执行duplicate命令,如果没有配置自动通道,那么至少手动分配一个辅助实例如果是使用PFILE参数文件启动辅助实例需要指定pfile参数文件,且pfile参数文件必须存储在运行RMAN执行复制的主机上。这里辅助实例使用SPFILE参数文件来启动,并使用自动通道:

[oracle@oracle11g ~]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@oracle11g ~]$ rman target sys/zzh_2046@test auxiliary sys/system@aux catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Wed Mar 25 10:49:35 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database
connected to auxiliary database: AUX (not mounted)

RMAN> duplicate target database to aux nofilenamecheck;

Starting Duplicate Db at 2015-03-25 10:50:29
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=38 devtype=DISK

contents of Memory Script:
{
   set until scn  1040304;
   set newname for datafile  1 to
 "/u01/app/oracle/oradata/aux/system01.dbf";
   set newname for datafile  2 to
 "/u01/app/oracle/oradata/aux/undotbs01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/oradata/aux/sysaux01.dbf";
   set newname for datafile  4 to
 "/u01/app/oracle/oradata/aux/users01.dbf";
   set newname for datafile  5 to
 "/u01/app/oracle/oradata/aux/example01.dbf";
   set newname for datafile  6 to
 "/u01/app/oracle/oradata/aux/tspitr01.dbf";
   restore
   check readonly
   clone database
   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 2015-03-25 10:50:30
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/aux/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/aux/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/aux/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/aux/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/aux/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/aux/tspitr01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875266253_761
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875266253_761 tag=TAG20150325T093052
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:56
Finished restore at 2015-03-25 10:52:28
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "AUX" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '/u01/app/oracle/oradata/aux/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '/u01/app/oracle/oradata/aux/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '/u01/app/oracle/oradata/aux/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/aux/system01.dbf'
 CHARACTER SET ZHS16GBK


contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875271151 filename=/u01/app/oracle/oradata/aux/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875271151 filename=/u01/app/oracle/oradata/aux/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875271151 filename=/u01/app/oracle/oradata/aux/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875271151 filename=/u01/app/oracle/oradata/aux/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875271151 filename=/u01/app/oracle/oradata/aux/tspitr01.dbf

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

executing command: SET until clause

Starting recover at 2015-03-25 10:52:30
using channel ORA_AUX_DISK_1

starting media recovery

channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=67
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875266425_771
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875266425_771 tag=TAG20150325T093344
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/u01/app/oracle/10.2.0/db/dbs/arch1_67_870806981.dbf thread=1 sequence=67
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/10.2.0/db/dbs/arch1_67_870806981.dbf recid=1 stamp=875271154
media recovery complete, elapsed time: 00:00:03
Finished recover at 2015-03-25 10:52:38

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

database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     167772160 bytes

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


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

executing command: SET NEWNAME

renamed temporary file 1 to /u01/app/oracle/oradata/aux/temp01.dbf in control file

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/aux/undotbs01.dbf recid=1 stamp=875271167

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/aux/sysaux01.dbf recid=2 stamp=875271167

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/aux/users01.dbf recid=3 stamp=875271167

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/aux/example01.dbf recid=4 stamp=875271167

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/aux/tspitr01.dbf recid=5 stamp=875271168

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875271167 filename=/u01/app/oracle/oradata/aux/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875271167 filename=/u01/app/oracle/oradata/aux/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875271167 filename=/u01/app/oracle/oradata/aux/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875271167 filename=/u01/app/oracle/oradata/aux/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875271168 filename=/u01/app/oracle/oradata/aux/tspitr01.dbf

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

database opened
Finished Duplicate Db at 2015-03-25 10:53:24


[oracle@oracle11g admin]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Mar 25 10:53:30 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select instance_name from v$instance;

INSTANCE_NAME
----------------
aux