Transferring Oracle Files Between Databases In ASM
DBMS_FILE_TRANSFER
DBMS_FILE_TRANSFER package provides three procedures to move Oracle files. COPY_FILE procedure moves files between directories within a database. However GET_FILE and PUT_FILE procedures contacts to a remote database and transfer files from or to remote database.
Note: When transferring files in use, you should bring them offline to guarantee consistency.
Let’s see the usage of PUT_FILE procedure:
Syntax:
DBMS_FILE_TRANSFER package provides three procedures to move Oracle files. COPY_FILE procedure moves files between directories within a database. However GET_FILE and PUT_FILE procedures contacts to a remote database and transfer files from or to remote database.
Note: When transferring files in use, you should bring them offline to guarantee consistency.
Let’s see the usage of PUT_FILE procedure:
Syntax:
DBMS_FILE_TRANSFER.PUT_FILE(
Source_directory_object IN VARCHAR2,
Source_file_name IN VARCHAR2,
Destination_directory_object IN VARCHAR2,
Destination_file_name IN VARCHAR2,
Database_link_name IN VARCHAR2);
Don’t forget to grant READ on the source directory to source database user and grant WRITE on destination directory to destination database user.
Create the directory on the source database:
CREATE OR REPLACE DIRECTORY SOURCEDIR AS '+FRA/SID/ARCHIVELOG' ;
GRANT READ ON DIRECTORY SOURCEDIR TO "SOURCEUSER";
Create the directory on the destination database:
CREATE OR REPLACE DIRECTORY DESTDIR AS '+FRA/SID/ARCHIVELOG ' ;
GRANT WRITE ON DIRECTORY DESTDIR TO "DESTUSER";
Create the Database Link on the source database:
CREATE DATABASE LINK "TESTLINK " CONNECT TO DESTUSER IDENTIFIED BYPASSWORD USING 'INST2';
Start file transfer:
CONNECT Sourceuser/Password@Inst1 BEGIN SYS.DBMS_FILE_TRANSFER.PUT_FILE ( ' SOURCEDIR' , 'Source_file_name' , ' DESTDIR ' , 'Destination_file_name','TESTLINK' ) ; END ;
In my dataguard case I didn’t need to create directory on the destination (standby) database. After creating the source directory on the primary side, I used the same directory name for the destination (of course after the archivelog was applied on standby). I executed the procedure as follows:
BEGIN SYS.DBMS_FILE_TRANSFER.PUT_FILE ( 'ARCHDIR' , 'Thread_1_seq_204982.1897.709557909' , ' ARCHDIR ' , 'Thread_1_seq_204982','TESTLINK' ) ; END ;
When you use the destination file name same with the source file name in an OMF environment you get the following error, so you must use a different destination file name.
ORA-19504: Failed To Create File "+FRA/…/Thread_1_seq_204982.1897.709557909" ORA-17502: Ksfdcre:4 Failed To Create File +FRA/…/Thread_1_seq_204982.1897.709557909 ORA-15046: ASM File Name '+FRA/… /Thread_1_seq_204982.1897.709557909' Is Not In Single-File Creation Form
FTP proxy Method
Another option for file transfer in ASM is FTP proxy Method. You must have Oracle XML DBinstalled for this option. XML DB uses the virtual folder /sys/asm to access ASM files. An example usage of this future is:
Ftp> Open Server1 Port1 Ftp> User Username1 Password Required For USERNAME1 Password: Password-For-Username1 Ftp> Cd /Sys/Asm/FRA/SID/ARCHIVELOG Ftp> Proxy Open Server2 Port2 Ftp> Proxy User Username2 Password Required For USERNAME2 Password: Password-For-Username2 Ftp> Proxy Cd /Sys/Asm/FRA/SID/ARCHIVELOG Ftp> Proxy Put Thread_1_seq_204982.1897.709557909 Ftp> Proxy Get Thread_1_seq_204982.1897.709557909
Refer to Using FTP and Oracle XML DB Protocol Server and Commanding ASM By Arup Nandafor more information.
11g ASM cp Command
Next option is ASM cp command which is an new feature of 11g. (Not suitable for my 10g case)
Syntax for remote ASM copy is:
ASMCMD> Cp [Srcfile] Username@Hostname.SID.Port:path
username can be any username in the ASM instance that has the system privilege. Port number is required if the listener doesn’t listen from default port 1521. Also don’t forget that ASM instance needs to be registered with the listener.
For example:
ASMCMD> Cp +FRA/SID/ARCHIVELOG/Thread_1_seq_204982.1897.709557909 Sys@ORCL.+ASM: +FRA/SID/ARCHIVELOG/Thread_1_seq_204982
Find more information about ASM cp command here.
RMAN Convert
Last option is RMAN but unfortunately not directly to ASM. You can copy an ASM file to file system, ftp the converted file to remote host then convert again into remote ASM. I’m not sure if anyone chose this way where we have simpler options, but it’s good to know this capability of RMAN.
Here is how we use RMAN Convert command to copy files between ASM and file system.:
RMAN> Convert Datafile "+DATAFILE/Tbs_21.F" Format "/Tmp/Conv_df_%U";
======================================================================
Comments
Post a Comment
Oracle DBA Information