通過FTP訪問ASM磁碟組

yangtingkun發表於2008-09-13

除了使用asmcmd命令之外,還可以通過FTP的方式訪問ASM磁碟組中的檔案。

 

 

預設情況,這個ftp的埠是關閉的,可以通過下面的命令開啟:

SQL> conn / as sysdba
已連線。
SQL> @?/rdbms/admin/catxdbdbca.sql 7788 8800
SQL> SET FEEDBACK 1
SQL> SET NUMWIDTH 10
SQL> SET LINESIZE 80
SQL> SET TRIMSPOOL ON
SQL> SET TAB OFF
SQL> SET PAGESIZE 100
SQL>
SQL> define ftpport  = &1
SQL> define httpport = &2
SQL> Rem Create a function to traverse the dom elements.
SQL> CREATE OR REPLACE FUNCTION traverseDom
  2            (parnode dbms_xmldom.DOMNode, pathSeg VARCHAR2)
  3            RETURN dbms_xmldom.DOMNode IS
  4  nodeList    dbms_xmldom.DOMNodeList;
  5  anElement   dbms_xmldom.DOMElement;
  6  aNode       dbms_xmldom.DOMNode;
  7  BEGIN
  8    -- Convert the passed in dom node to an element
  9    anElement := dbms_xmldom.makeElement(parnode);
 10 
 11    -- Select the path segment requested by the user
 12    nodeList  := dbms_xmldom.getChildrenByTagName(anElement, pathSeg);
 13 
 14    -- get the first node out of the list
 15    aNode := dbms_xmldom.item(nodeList, 0);
 16 
 17    -- return that node (ignore errors here).
 18    return aNode;
 19  END;
 20  /

函式已建立。

SQL>
SQL> declare
  2     configxml    sys.xmltype;
  3     configdomdoc dbms_xmldom.DOMDocument;
  4     textNode     dbms_xmldom.DOMNode;
  5     aNode        dbms_xmldom.DOMNode;
  6     protNode     dbms_xmldom.DOMNode;
  7     anElement    dbms_xmldom.DOMElement;
  8     listOfNodes  dbms_xmldom.DOMNodeList;
  9     aString      VARCHAR2(100);
 10  begin
 11 
 12  -- Select the resource and set it into the config
 13  select sys_nc_rowinfo$ into configxml from xdb.xdb$config ;
 14 
 15  -- Create a dom document out of the xmltype
 16  configdomdoc := dbms_xmldom.newDOMDocument(configxml);
 17 
 18  -- Get the root Element of the dom
 19  anElement := dbms_xmldom.getDocumentElement(configdomdoc);
 20 
 21  -- Convert this to a node
 22  aNode := dbms_xmldom.makeNode(anElement);
 23 
 24  -- Traverse One Element Down At A Time.
 25  aNode := traverseDom(aNode, 'sysconfig');
 26  protNode := traverseDom(aNode, 'protocolconfig');
 27 
 28  -- Set the FTP port by traversing /ftpconfig/ftp-port
 29  aNode := traverseDom(protNode, 'ftpconfig');
 30  aNode := traverseDom(aNode, 'ftp-port');
 31  textNode := dbms_xmldom.getFirstChild(aNode);
 32  dbms_xmldom.setNodeValue(textNode, &ftpport);
 33 
 34  -- Set the FTP port by traversing /ftpconfig/ftp-port
 35  aNode := traverseDom(protNode, 'httpconfig');
 36  aNode := traverseDom(aNode, 'http-port');
 37  textNode := dbms_xmldom.getFirstChild(aNode);
 38  dbms_xmldom.setNodeValue(textNode, &httpport);
 39 
 40  dbms_xdb.cfg_update(configxml);
 41  commit;
 42 
 43  end;
 44  /
原值   32: dbms_xmldom.setNodeValue(textNode, &ftpport);
新值   32: dbms_xmldom.setNodeValue(textNode, 7788);
原值   38: dbms_xmldom.setNodeValue(textNode, &httpport);
新值   38: dbms_xmldom.setNodeValue(textNode, 8800);

PL/SQL 過程已成功完成。

SQL>
SQL>
SQL> drop function traverseDom;

函式已刪除。

這個指令碼需要SYS或者XDB使用者來呼叫,後面跟的兩個引數分別是FTP的埠和HTTP/WEBDAV的埠。

下面就可以通過埠7788來訪問ASM磁碟組了:

SQL> host
$ ftp    
ftp> open ser1 7788     
Connected to ser1.
220- ser1
Unauthorised use of this FTP server is prohibited and may be subject to civil and criminal prosecution.
220 ser1 FTP Server (Oracle XML DB/Oracle Database) ready.
Name (ser1:root): system
331 pass required for SYSTEM
Password:
230 SYSTEM logged in
Remote system type is Unix.
ftp> cd /sys/asm
250 CWD Command successful
ftp> ls
200 PORT Command successful
150 ASCII Data Connection
DATA
226 ASCII Transfer Complete
6 bytes received in 0.17 seconds (0.04 Kbytes/s)
ftp> cd DATA
250 CWD Command successful
ftp> ls
200 PORT Command successful
150 ASCII Data Connection
RACTEST
ASMTESTING
226 ASCII Transfer Complete
21 bytes received in 0.0021 seconds (9.58 Kbytes/s)
ftp> cd RACTEST
250 CWD Command successful
ftp> ls
200 PORT Command successful
150 ASCII Data Connection
CONTROLFILE
ONLINELOG
DATAFILE
TEMPFILE
PARAMETERFILE
spfileractest.ora
backup
226 ASCII Transfer Complete
86 bytes received in 0.003 seconds (28.41 Kbytes/s)
ftp> lcd /data
Local directory now /data
ftp> cd DATAFILE
250 CWD Command successful
ftp> ls
200 PORT Command successful
150 ASCII Data Connection
SYSTEM.259.664395355
SYSAUX.260.664395357
UNDOTBS1.261.664395359
UNDOTBS2.263.664395371
USERS.264.664395373
226 ASCII Transfer Complete
113 bytes received in 0.0028 seconds (38.79 Kbytes/s)
ftp> bin
200  Type set to I.
ftp> prompt
Interactive mode off.
ftp> mget SYSTEM.259.664395355
200 PORT Command successful
150 BIN Data Connection
226 BIN Transfer Complete
local: SYSTEM.259.664395355 remote: SYSTEM.259.664395355
734011392 bytes received in 17 seconds (41380.50 Kbytes/s)
ftp> ls
200 PORT Command successful
150 ASCII Data Connection
SYSTEM.259.664395355
SYSAUX.260.664395357
UNDOTBS1.261.664395359
UNDOTBS2.263.664395371
USERS.264.664395373
226 ASCII Transfer Complete
113 bytes received in 0.0037 seconds (29.51 Kbytes/s)
ftp> cd ..
250 CWD Command successful
ftp> ls
200 PORT Command successful
150 ASCII Data Connection
CONTROLFILE
ONLINELOG
DATAFILE
TEMPFILE
PARAMETERFILE
spfileractest.ora
backup
226 ASCII Transfer Complete
86 bytes received in 0.003 seconds (27.67 Kbytes/s)
ftp> cd backup
250 CWD Command successful
ftp> send SYSTEM.259.664395355 system.dbf
200 PORT Command successful
150 BIN Data Connection
226 BIN Transfer Complete
local: SYSTEM.259.664395355 remote: system.dbf
734011392 bytes sent in 9.5 seconds (75647.23 Kbytes/s)
ftp> ls
200 PORT Command successful
150 ASCII Data Connection
02jplh5q_1_1
system.dbf
226 ASCII Transfer Complete
26 bytes received in 0.0025 seconds (10.13 Kbytes/s)
ftp> quit
221 QUIT Goodbye.

上面展示了利用ftp功能,在作業系統和ASM之間讀寫檔案的操作。需要注意,ftp登陸需要一個非SYSDBA賬號。

登陸後在/sys/asm下可以找到ASM磁碟組資訊。ftp的基本命令都可以使用,包括mkdir

這個埠開啟之後,除了本機之外,其他伺服器也通過同樣的方法可以直接訪問ASM磁碟組。

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/4227/viewspace-448289/,如需轉載,請註明出處,否則將追究法律責任。

相關文章