使用自定义辅助控制文件来执行表空间传输
[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