Oracle的ASM一直不够透明,但Oracle还是提供了一些工具来访问ASM磁盘组的,asmcdm就是其中一个工具,本文将对其进行详细介绍。

感觉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/

      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

 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

 

      使用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

连接到目标数据库: 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> 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

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)

错误信息已经很明显了,Oracle的ASM从设计上就不是可以存放任何东西的文件系统,只有Oracle数据库相关的文件,比如数据文件、日志文件、控制文件、参数文件以及备份文件等可以存储到ASM中。