Tuesday, August 7, 2012

Transportable Tablespaces from Backup with RMAN in Oracle 10g Release 2


Before Oracle 10g it was also possible to create transportable tablespaces
(they were introduced with ORACLE 8i):
we have used export-utility (exp) to create them.
- first we had to make the tablespace READ ONLY before exporting,
- then we had to used export utility to dump the tablespace metadata.
(In the exp-dumpfile only the metadata of the tablespace are dumped)
- and after we shipped the datafiles from the source system to the target system we could use the import utility(imp) to import the metadata from the dumpfile and
- finally we could take the tablespace in the target system read write.
This procedure had a number of significant limitations:
1. The source- and target-platforms had to be exactely the same(up to the last OS-package)
2. The source- and target-database had to exactely the same version (up to the last patchset)
3. The tablespace had to be made READ ONLY before exporting the metadata
Since ORACLE 10gR2 we can now use RMAN to create a transportable tablespace-set from Backup.
Now we do not need to make the tablespace(s) READ ONLY any more.
Here are the steps RMAN will take to do so:
1. RMAN connects to the source-database
2. RMAN creates an AUXILIARY instance and an AUXILIARY database which constists of a SYSTEM- and an UNDO-tablespace and the tablespace(s) we want to export. For this RMAN uses a backupset of the source database.
3. RMAN recovers the AUXILIARY database to the desired point in time
4. RMAN uses export-datapump (expdp) to create a dumpfile-set:
this consists of:
- the the datafiles which represent the transportable-tablespace-set,
- the dumpfile of the export con taining the metadata of the tablespace-set
- a sql-script which can be used to import the metadata into the target system
5. RMAN removes the AUXILIARY instance from the host.
And here is a demo:
I have written a little sql-script which contains an RMAN-run-block:
[oracle@lutz1 oracle]$ rman target / @tts.sql
Recovery Manager: Release 10.2.0.1.0 – Production on Tue Feb 7 02:57:33 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1106297266)
RMAN> run {
2> TRANSPORT TABLESPACE ‘LUTZ_TEST’
3> AUXILIARY DESTINATION ‘/home/oracle/AUX/tts’
4> DUMP FILE ‘lutz_test.dmp’
5> EXPORT LOG ‘lutz_test.log’
6> IMPORT SCRIPT ‘lutz_test_im.sql’
7> TABLESPACE DESTINATION ‘/home/oracle/AUX/tts’
8> UNTIL TIME=”to_date(’07-02-2006:02:57:00′, ‘dd-mm-yyyy:hh24:mi:ss’)”;
9> }
using target database control file instead of recovery catalog
RMAN-05026: WARNING: presuming following set of tablespaces applies
to specified point in time


List of tablespaces expected to have UNDO segments
tablespace SYSTEM
tablespace UNDOTBS1

Creating automatic instance, with SID=’yigu’

initialization parameters used for automatic instance:
db_name=ORCL
compatible=10.2.0.1.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_ORCL_yigu
large_pool_size=1M
shared_pool_size=110M
#No auxiliary parameter file used
db_create_file_dest=/home/oracle/AUX/tts
control_files=/home/oracle/AUX/tts/cntrl_tspitr_ORCL_yigu.f


starting up automatic instance ORCL

Oracle instance started
Total System Global Area 201326592 bytes
Fixed Size 1218508 bytes
Variable Size 146802740 bytes
Database Buffers 50331648 bytes
Redo Buffers 2973696 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until time “to_date(’07-02-2006:02:57:00′, ‘dd-mm-yyyy: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;’;
}
executing Memory Script

executing command: SET until clause

Starting restore at 07-FEB-06
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=37 devtype=DISK
allocated channel: ORA_AUX_SBT_TAPE_1
channel ORA_AUX_SBT_TAPE_1: sid=36 devtype=SBT_TAPE
channel ORA_AUX_SBT_TAPE_1: Oracle Secure Backup

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 /opt/oracle/flash_recovery_area/ORCL/
autobackup/2006_02_07/o1_mf_s_581741757_1yhzkgp5_.bkp

channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/opt/oracle/flash_recovery_area/ORCL/
autobackup/2006_02_07/o1_mf_s_581741757_1yhzkgp5_.bkp tag=TAG20060207T025557

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:06
output filename=/home/oracle/AUX/tts/cntrl_tspitr_ORCL_yigu.f
Finished restore at 07-FEB-06

sql statement: alter database mount clone database
sql statement: alter system archive log current
sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;
released channel: ORA_AUX_DISK_1
released channel: ORA_AUX_SBT_TAPE_1

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until time “to_date(’07-02-2006:02:57:00′, ‘dd-mm-yyyy: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
“/home/oracle/AUX/tts/lutz_test.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;
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”;
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace “LUTZ_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
renamed temporary file 1 to /home/oracle/AUX/tts/TSPITR_ORCL_YIGU/
datafile/o1_mf_temp_%u_.tmp in control file


Starting restore at 07-FEB-06
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=37 devtype=DISK
channel ORA_AUX_DISK_1: restoring datafile 00001
input datafile copy recid=2 stamp=581741278 filename=/opt/oracle/flash_recovery_area/ORCL/
datafile/o1_mf_system_1yhyzg1w_.dbf
destination for restore of datafile 00001:
/home/oracle/AUX/tts/TSPITR_ORCL_YIGU/
datafile/o1_mf_system_%u_.dbf

channel ORA_AUX_DISK_1: copied datafile copy of datafile 00001
output filename=/home/oracle/AUX/tts/TSPITR_ORCL_YIGU/
datafile/o1_mf_system_1yhzoc4n_.dbf recid=8 stamp=581741970

channel ORA_AUX_DISK_1: restoring datafile 00002
input datafile copy recid=5 stamp=581741387 filename=/opt/oracle/flash_recovery_area/ORCL/
datafile/o1_mf_undotbs1_1yhz5np1_.dbf

destination for restore of datafile 00002: /home/oracle/AUX/tts/
TSPITR_ORCL_YIGU/datafile/o1_mf_undotbs1_%u_.dbf

channel ORA_AUX_DISK_1: copied datafile copy of datafile 00002
output filename=/home/oracle/AUX/tts/TSPITR_ORCL_YIGU/
datafile/o1_mf_undotbs1_1yhzrccl_.dbf
recid=9 stamp=581741983

channel ORA_AUX_DISK_1: restoring datafile 00003
input datafile copy recid=3 stamp=581741352 filename=/opt/oracle/flash_recovery_area/ORCL/
datafile/o1_mf_sysaux_1yhz2s7c_.dbf
destination for restore of
datafile 00003: /home/oracle/AUX/tts/TSPITR_ORCL_YIGU/
datafile/o1_mf_sysaux_%u_.dbf

channel ORA_AUX_DISK_1: copied datafile copy of datafile 00003
output filename=/home/oracle/AUX/tts/TSPITR_ORCL_YIGU/
datafile/o1_mf_sysaux_1yhzrm6x_.dbf
recid=10 stamp=581742036

channel ORA_AUX_DISK_1: restoring datafile 00006
input datafile copy recid=6 stamp=581741397 filename=/opt/oracle/flash_recovery_area/ORCL/
datafile/o1_mf_lutz_tes_1yhz63wv_.dbf

destination for restore of datafile 00006:
/home/oracle/AUX/tts/lutz_test.dbf

channel ORA_AUX_DISK_1:
copied datafile copy of datafile 00006

output filename=/home/oracle/AUX/tts/lutz_test.dbf
recid=11 stamp=581742044

Finished restore at 07-FEB-06

datafile 1 switched to datafile copy
input datafile copy recid=12 stamp=581742047 filename=/home/oracle/AUX/tts/TSPITR_ORCL_YIGU/
datafile/o1_mf_system_1yhzoc4n_.dbf

datafile 2 switched to datafile copy
input datafile copy recid=13 stamp=581742048 filename=/home/oracle/AUX/tts/TSPITR_ORCL_YIGU/
datafile/o1_mf_undotbs1_1yhzrccl_.dbf

datafile 3 switched to datafile copy
input datafile copy recid=14 stamp=581742048 filename=/home/oracle/AUX/tts/TSPITR_ORCL_YIGU/
datafile/o1_mf_sysaux_1yhzrm6x_.dbf

datafile 6 switched to datafile copy
input datafile copy recid=15 stamp=581742048 filename=/home/oracle/AUX/tts/lutz_test.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

Starting recover at 07-FEB-06

using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 10 is already on disk as file /opt/oracle/flash_recovery_area/ORCL/
archivelog/2006_02_07/o1_mf_1_10_1yhzo2j8_.arc

archive log filename=/opt/oracle/flash_recovery_area/ORCL/
archivelog/2006_02_07/o1_mf_1_10_1yhzo2j8_.arc
thread=1 sequence=10media recovery complete, elapsed time: 00:00:01

Finished recover at 07-FEB-06
database opened

contents of Memory Script:
{
#mark read only the tablespace that will be exported
sql clone “alter tablespace LUTZ_TEST read only”;
# create directory for datapump export
sql clone “create or replace directory STREAMS_DIROBJ_DPDIR as ”
/home/oracle/AUX/tts””;
# export the tablespaces in the recovery set
host ‘expdp userid=\”/@\(DESCRIPTION=\(ADDRESS=(PROTOCOL=beq\)(PROGRAM=/opt/oracle/product/db10_2/bin/oracle\)
\(ARGV0=oracleyigu\)\(ARGS=^’\(DESCRIPTION=\(LOCAL=YES\)
(ADDRESS=\(PROTOCOL=beq\)\)\)^’\)\(ENVS=^’ORACLE_SID=yigu^’\)\)
\(CONNECT_DATA=\(SID=yigu\)\)\) as sysdba\” transport_tablespaces=

LUTZ_TEST dumpfile=
lutz_test.dmp directory=
STREAMS_DIROBJ_DPDIR logfile=
lutz_test.log’;
}
executing Memory Script

sql statement: alter tablespace LUTZ_TEST read only
sql statement: create or replace directory STREAMS_DIROBJ_DPDIR as ”/home/oracle/AUX/tts”

Export: Release 10.2.0.1.0 - Production on Tuesday, 07 February, 2006 3:01:47
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 – Production
With the Partitioning, OLAP and Data Mining options
Starting “SYS”.”SYS_EXPORT_TRANSPORTABLE_01″: userid=”/********@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)
(PROGRAM=/opt/oracle/product/db10_2/bin/oracle)(ARGV0=oracleyigu)
(ARGS=\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\))
(ENVS=ORACLE_SID=yigu))(CONNECT_DATA=(SID=yigu))) AS SYSDBA” transport_tablespaces= LUTZ_TEST dumpfile=lutz_test.dmp directory=STREAMS_DIROBJ_DPDIR logfile=lutz_test.log

Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
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:
/home/oracle/AUX/tts/lutz_test.dmp
Job “SYS”.”SYS_EXPORT_TRANSPORTABLE_01″ successfully completed at 03:02:44

host command complete
/*
The following command may be used to import the tablespaces.
Substitute values for and .
impdp directory= dumpfile= ‘lutz_test.dmp’ transport_datafiles= /home/oracle/AUX/tts/lutz_test.dbf
*/
————————————————————–
– Start of sample PL/SQL script for importing the tablespaces
————————————————————–
– creating directory objects
CREATE DIRECTORY STREAMS$DIROBJ$1 AS ‘/home/oracle/AUX/tts/’;
CREATE DIRECTORY STREAMS$DIROBJ$DPDIR AS ‘/home/oracle/AUX/tts’;
/* 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 := ‘lutz_test.dmp’;
dump_file.directory_object := ‘STREAMS$DIROBJ$DPDIR’;
— forming list of datafiles for import
tbs_files( 1).file_name := ‘lutz_test.dbf’;
tbs_files( 1).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 /home/oracle/AUX/tts/cntrl_tspitr_ORCL_yigu.f
deleted

auxiliary instance file /home/oracle/AUX/tts/TSPITR_ORCL_YIGU/datafile/
o1_mf_system_1yhzoc4n_.dbf
deleted

auxiliary instance file /home/oracle/AUX/tts/TSPITR_ORCL_YIGU/datafile/
o1_mf_undotbs1_1yhzrccl_.dbf
deleted

auxiliary instance file /home/oracle/AUX/tts/TSPITR_ORCL_YIGU/datafile/
o1_mf_sysaux_1yhzrm6x_.dbf
deleted

auxiliary instance file /home/oracle/AUX/tts/TSPITR_ORCL_YIGU/datafile/
o1_mf_temp_1yhzvhkk_.tmp
deleted

auxiliary instance file /home/oracle/AUX/tts/TSPITR_ORCL_YIGU/onlinelog/
o1_mf_1_1yhztxdl_.log
deleted

auxiliary instance file /home/oracle/AUX/tts/TSPITR_ORCL_YIGU/onlinelog/
o1_mf_2_1yhzv0p5_.log
deleted

auxiliary instance file /home/oracle/AUX/tts/TSPITR_ORCL_YIGU/onlinelog/
o1_mf_3_1yhzv4gp_.log
deleted


Recovery Manager complete.
[oracle@lutz1 oracle]$ ll /home/oracle/AUX/tts/
total 10344
-rw-r—– 1 oracle oinstall 10493952 Feb 7 03:01 lutz_test.dbf
-rw-r—– 1 oracle oinstall 65536 Feb 7 03:02 lutz_test.dmp
-rw-r–r– 1 oracle oinstall 2075 Feb 7 03:03 lutz_test_im.sql
-rw-r–r– 1 oracle oinstall 1130 Feb 7 03:02 lutz_test.log
drwxr-x— 4 oracle oinstall 4096 Feb 7 02:58 TSPITR_ORCL_YIGU
[oracle@lutz1 oracle]$ cat /home/oracle/AUX/tts/lutz_test_im.sql
/*
The following command may be used to import the tablespaces.
Substitute values for and .
impdp directory= dumpfile= ‘lutz_test.dmp’ transport_datafiles= /home/oracle/AUX/tts/lutz_test.dbf
*/
————————————————————–
– Start of sample PL/SQL script for importing the tablespaces
————————————————————–
– creating directory objects
CREATE DIRECTORY STREAMS$DIROBJ$1 AS
‘/home/oracle/AUX/tts/’;

CREATE DIRECTORY STREAMS$DIROBJ$DPDIR AS
‘/home/oracle/AUX/tts’;

/* 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 := ‘lutz_test.dmp’;
dump_file.directory_object := ‘STREAMS$DIROBJ$DPDIR’;
— forming list of datafiles for import
tbs_files( 1).file_name := ‘lutz_test.dbf’;
tbs_files( 1).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
————————————————————–
[oracle@lutz1 oracle]$ cat /home/oracle/AUX/tts/lutz_test.log
Export: Release 10.2.0.1.0 – Production on Tuesday, 07 February, 2006 3:01:47
Copyright (c) 2003, 2005, Oracle. All rights reserved.
;;;
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
- Production

With the Partitioning, OLAP and Data Mining options
Starting “SYS”.”SYS_EXPORT_TRANSPORTABLE_01″: userid=”/********@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)
(PROGRAM=/opt/oracle/product/db10_2/bin/oracle)(ARGV0=oracleyigu)
(ARGS=\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=(PROTOCOL=beq\)\)\))(ENVS=ORACLE_SID=yigu))
(CONNECT_DATA=(SID=yigu))) AS SYSDBA” transport_tablespaces= LUTZ_TEST dumpfile=lutz_test.dmp directory=STREAMS_DIROBJ_DPDIR logfile=lutz_test.log

Processing object type
TRANSPORTABLE_EXPORT/PLUGTS_BLK

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:
/home/oracle/AUX/tts/lutz_test.dmp
Job “SYS”.”SYS_EXPORT_TRANSPORTABLE_01″
successfully completed at 03:02:44

[oracle@lutz1 oracle]$ ls -rtl /home/oracle/AUX/tts/TSPITR_ORCL_YIGU/*
/home/oracle/AUX/tts/TSPITR_ORCL_YIGU/onlinelog:
total 0

No comments: