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

最后就可以执行导入过程了
[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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/6babcd045422b613ec9318eb94c1f113.html