cassandra统计key的个数脚本。不完善,不能过滤掉删除后的数据。待完善。。。
#!/bin/bash
#统计cassandra的某个keyspace中key的数量
usage="Usage:
$0 <KeyspacePath>
KeyspacePath 需要统计的keyspace的路径
Example:
sh $0 /data/support/nosql_data/data/ISYDB
"
if [ $# -ne 1 ];then
echo "$usage"
exit 1
fi
HOME_PATH=$(dirname $0)
cd ${HOME_PATH}
HOME_PATH=$(pwd)
bktool=${HOME_PATH}/sstablekeys
sDir=$1
keyspaceName=$(echo $sDir | awk -F/ '{print $(NF)}')
echo 'flush Memtable to SSTable...'
sh nodetool -h localhost -p 7199 flush $keyspaceName
#sh nodetool -h localhost -p 7199 compact $keyspaceName
#sh nodetool -h localhost -p 7199 cleanup $keyspaceName
sucess=0
cd ${sDir}
echo '开始统计...'
for file in $(ls *-Data.db);
do
filename=$(echo $file | awk -F. '{print $1}')
sFile=$sDir/${filename}.db
count=$($bktool $sFile |wc -l)
echo 'count ' $sFile 'num=' $count
((sucess+=count))
done
echo '备份完成:keys总数 = '$sucess''