在实际生产中,往往会碰到一套RAC中运行多个数据库,ASM某磁盘组中按照各数据库创建目录,因此ASM某磁盘组中会有很多个目录,例如环境描述为:
[grid@ray01 ~]$ asmcmd
ASMCMD> lsdg
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
MOUNTED 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 data1
ASMCMD> ls
orcl1/
orcl2/
orcl3/
orcl4/
orcl5/
orcl6/
orcl7/
orcl8/
orcl9/
orcl10/
orcl11/
orcl12/
orcl13/
orcl14/
orcl15/
orcl16/
orcl17/
orcl18/
orcl19/
orcl20/
orcl21/
orcl22/
orcl23/
那么,如果想看各目录大小,传统的方式为:
ASMCMD> du orcl1
Used_MB Mirror_used_MB
22888 45808
ASMCMD> du orcl2
Used_MB Mirror_used_MB
22888 45808
ASMCMD> du orcl3
Used_MB Mirror_used_MB
22888 45808
...
这种方式太过复杂,以下分享一个小脚本,可以批量查询各目录大小,并以列表的形式展示出来
[grid@ray01 ~]$ vi asmdu.sh
#!/bin/bash
#
# du of each subdirectory in a directory for ASM
#
D=$1
if [[ -z $D ]]
then
echo "Please provide a directory !"
exit 1
fi
(for DIR in `asmcmd ls ${D}`
do
echo ${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 data1
datac1 subdirectories size
Subdir Used MB Mirror MB
------ ------- ---------
orcl1/ 22888 45808
orcl2/ 132416 264996
orcl3/ 32 64
orcl4/ 865608 1731248
orcl5/ 3280996 6562024
orcl6/ 25472266 50944596
orcl7/ 465936 931904
orcl8 11700 23432
orcl9/ 28408 56848
orcl10/ 29800 59632
orcl11/ 19270 38572
orcl12/ 5172 10376
orcl13/ 14902644 29805320
orcl14/ 1352754 2705540
orcl15/ 408012 816056
orcl16/ 17586 35204
orcl17/ 14164 28360
orcl18/ 12498 25028
orcl19/ 1201054 2402140
orcl20/ 200890 401812
orcl21/ 38416 76864
orcl22/ 18872 37776
orcl23/ 80340 160712
------ ------- ---------
Total 48581722 97164312
以上为客户环境执行演示,因此过滤掉关键信息。