在实际生产中,往往会碰到一套RAC中运行多个数据库,ASM某磁盘组中按照各数据库创建目录,因此ASM某磁盘组中会有很多个目录,例如环境描述为:
[grid@ray01 ~]$ asmcmdASMCMD> lsdgState Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files NameMOUNTED NORMAL N 512 4096 4194304 307495424 20330080 5671968 3379056 0 N DATA1/MOUNTED NORMAL N 512 4096 4194304 385296 414056 34608 189724 0 Y ARCH1/MOUNTED NORMAL N 512 4096 4194304 27945008 14398896 1243056 6572920 0 N RECO1/ASMCMD> cd data1ASMCMD> lsorcl1/orcl2/orcl3/orcl4/orcl5/orcl6/orcl7/orcl8/orcl9/orcl10/orcl11/orcl12/orcl13/orcl14/orcl15/orcl16/orcl17/orcl18/orcl19/orcl20/orcl21/orcl22/orcl23/
那么,如果想看各目录大小,传统的方式为:
ASMCMD> du orcl1Used_MB Mirror_used_MB22888 45808ASMCMD> du orcl2Used_MB Mirror_used_MB22888 45808ASMCMD> du orcl3Used_MB Mirror_used_MB22888 45808...
这种方式太过复杂,以下分享一个小脚本,可以批量查询各目录大小,并以列表的形式展示出来
[grid@ray01 ~]$ vi asmdu.sh#!/bin/bash## du of each subdirectory in a directory for ASM#D=$1if [[ -z $D ]]thenecho \"Please provide a directory !\"exit 1fi(for DIR in `asmcmd ls ${D}`doecho ${DIR} `asmcmd du ${D}/${DIR} | tail -1`done) | awk -v D=\"$D\" \' BEGIN { printf(\"\\n\\t\\t%40s\\n\\n\", D \" subdirectories size\") ;printf(\"%25s%16s%16s\\n\", \"Subdir\", \"Used MB\", \"Mirror MB\") ;printf(\"%25s%16s%16s\\n\", \"------\", \"-------\", \"---------\") ;}{printf(\"%25s%16s%16s\\n\", $1, $2, $3) ;use += $2 ;mir += $3 ;}END { printf(\"\\n\\n%25s%16s%16s\\n\", \"------\", \"-------\", \"---------\");printf(\"%25s%16s%16s\\n\\n\", \"Total\", use, mir) ;} \'[grid@ray01 ~]$ chmod +x asmdu.sh
执行脚本,后面跟上需要查询的磁盘组名称就行了。
[grid@ray01 ~]$ ./asmdu.sh data1datac1 subdirectories sizeSubdir Used MB Mirror MB------ ------- ---------orcl1/ 22888 45808orcl2/ 132416 264996orcl3/ 32 64orcl4/ 865608 1731248orcl5/ 3280996 6562024orcl6/ 25472266 50944596orcl7/ 465936 931904orcl8 11700 23432orcl9/ 28408 56848orcl10/ 29800 59632orcl11/ 19270 38572orcl12/ 5172 10376orcl13/ 14902644 29805320orcl14/ 1352754 2705540orcl15/ 408012 816056orcl16/ 17586 35204orcl17/ 14164 28360orcl18/ 12498 25028orcl19/ 1201054 2402140orcl20/ 200890 401812orcl21/ 38416 76864orcl22/ 18872 37776orcl23/ 80340 160712------ ------- ---------Total 48581722 97164312
以上为客户环境执行演示,因此过滤掉关键信息。