ASM工具asmcmd

shilei1發表於2011-07-17


感覺OracleASM一直很不透明,不過Oracle還是提供了一些工具來訪問ASM磁碟組的,asmcdm就是其中一個工具。


如果不做任何配置,直接呼叫asmcmd,多半會碰到下面的錯誤:

$ asmcmd
ASMCMD-08103: failed to connect to ASM; ASMCMD running in non-connected mode

要連線ASM,其實只需要做兩件事情,確保$ORACLE_HOME$ORACLE_SID的設定正確既可:

ASMCMD> exit
$ bash
bash-3.00$ env|grep ORACLE_
ORACLE_SID=rac11g1
ORACLE_BASE=/data/oracle
ORACLE_HOME=/data/oracle/product/11.1/database
bash-3.00$ export ORACLE_SID=+ASM1
bash-3.00$ asmcmd
ASMCMD> ls
DATA/

現在已經成功的連線到ASM磁碟組。

ASMCMD> help
asmcmd [-v] [-a ] [-p] [command]

The environment variables ORACLE_HOME and ORACLE_SID determine the
instance to which the program connects, and ASMCMD establishes a
bequeath connection to it, in the same manner as a SQLPLUS / AS
SYSDBA. The user must be a member of the SYSDBA group.

Specifying the -v option prints the asmcmd version number and
exits immediately.

Specify the -a option to choose the type of connection. There are
only two possibilities: connecting as "sysasm" or as "sysdba".
The default value if this option is unspecified is "sysasm".

Specifying the -p option allows the current directory to be displayed
in the command prompt, like so:

ASMCMD [+DATAFILE/ORCL/CONTROLFILE] >

[command] specifies one of the following commands, along with its
parameters.

Type "help [command]" to get help on a specific ASMCMD command.

commands:
--------
help

cd
cp
du
find
ls
lsct
lsdg
mkalias
mkdir
pwd
rm
rmalias

md_backup
md_restore

lsdsk
remap

ASMCMD> pwd
+
ASMCMD> cd DATA
ASMCMD> ls
RACTEST/
ASMCMD> cd RACTEST
ASMCMD> ls
CONTROLFILE/
DATAFILE/
ONLINELOG/
PARAMETERFILE/
TEMPFILE/
spfileractest.ora
ASMCMD> du
Used_MB Mirror_used_MB
2457 2457
ASMCMD> lsct
DB_Name Status Software_Version Compatible_version Instance_Name Disk_Group
ractest CONNECTED 11.1.0.6.0 11.1.0.0.0 ractest1 DATA
ASMCMD> lsdg
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Name
MOUNTED EXTERN N 512 4096 1048576 963503 960944 0 960944 0 DATA/
ASMCMD> lsdsk
Path
/dev/rdsk/emcpower0b
/dev/rdsk/emcpower0e
/dev/rdsk/emcpower0g

HELP可以列出asmcmd的命令,上面是一些常用的命令。

11gasmcmd還提供新特性,cp命令。

使用cp命令將ASM內部的檔案複製到作業系統還是很方便的:

ASMCMD> cp spfileractest.ora /data/spfileractest.ora
source +DATA/RACTEST/spfileractest.ora
target /data/spfileractest.ora
copying file(s)...
file, /data/spfileractest.ora, copy committed.

同樣利用cp也可以將磁碟上面的資料檔案、備份檔案等複製到ASM磁碟中:

bash-3.00$ rman target /

恢復管理器: Release 11.1.0.6.0 - Production on 星期三 9 3 10:38:17 2008

Copyright (c) 1982, 2007, Oracle. All rights reserved.

連線到目標資料庫: RACTEST (DBID=3192712917)

RMAN> run
2> {
3> allocate channel c1 device type disk format '/data/%U';
4> backup current controlfile;
5> }

使用目標資料庫控制檔案替代恢復目錄分配的通道: c1通道 c1: SID=63 例項=ractest1 裝置型別=DISK

啟動 backup 03-9 -08通道 c1: 正在啟動全部資料檔案備份集通道 c1: 正在指定備份集內的資料檔案備份集內包括當前控制檔案通道 c1: 正在啟動段 1 03-9 -08通道 c1: 已完成段 1 03-9 -08段控制程式碼=/data/02jplh5q_1_1 標記=TAG20080903T103850 註釋=NONE通道 c1: 備份集已完成, 經過時間:00:00:01完成 backup 03-9 -08釋放的通道: c1

RMAN> quit

恢復管理器完成。

下面利用asmcmd複製這個生成的備份檔案到ASM磁碟組:

ASMCMD> ls
CONTROLFILE/
DATAFILE/
ONLINELOG/
PARAMETERFILE/
TEMPFILE/
redo01.log
spfileractest.ora
ASMCMD> mkdir backup
ASMCMD> cp /data/02jplh5q_1_1 +DATA/RACTEST/backup/02jplh5q_1_1
source /data/02jplh5q_1_1
target +DATA/RACTEST/backup/02jplh5q_1_1
copying file(s)...
file, +DATA/ractest/backup/02jplh5q_1_1, copy committed.

不過不是任何檔案都可以複製到ASM中,比如複製資料庫安裝的壓縮檔案:

ASMCMD> cp /data/solaris.sparc64_11gR1_database.zip solaris.sparc64_11gR1_database.zip
source /data/solaris.sparc64_11gR1_database.zip
target solaris.sparc64_11gR1_database.zip
ASMCMD-08012: can not determine file type for file->'/data/solaris.sparc64_11gR1_database.zip'
ORA-15056: additional error message
ORA-17503: ksfdopn:DGGetFileAttr15 Failed to open file /data/solaris.sparc64_11gR1_database.zip
ORA-27046: file size is not a multiple of logical block size
Additional information: 1
ORA-06512: at "SYS.X$DBMS_DISKGROUP", line 207
ORA-06512: at line 3 (DBD ERROR: OCIStmtExecute)

錯誤資訊已經很明顯了,OracleASM從設計上就不是可以存放任何東西的檔案系統,只有Oracle資料庫相關的檔案,比如資料檔案、日誌檔案、控制檔案、引數檔案以及備份檔案等可以儲存到ASM中。

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

相關文章