1、按照時間戳范圍查詢記錄
echo "scan 'event_log', { COLUMN => 'cf:sid', TIMERANGE => [1466265600272, 1471622400481]} " | hbase shell > ./record.txt
其中這里的cf:sid和key一致, 時間戳范圍需要按照時間自己轉換:
#current=`date "+%Y-%m-%d %H:%M:%S"` #獲取當前時間,例:2015-03-11 12:33:41
current=“2015-03-11 12:33:41”
timeStamp=`date -d "$current" +%s` #將current轉換為時間戳,精確到秒
currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000)) #將current轉換為時間戳,精確到毫秒
echo $currentTimeStamp
2、通過shell命令提取record.txt中的sid字段,並拼成hbase刪除行命令
cat record.txt|awk '{print "deleteall '\''event_log'\''", ",", "'\''"$1"'\''"}' > del.sh
3、生成hbase刪除腳本
在del.sh頭尾分別加上:
#!/bin/sh
exec hbase shell <<EOF
和
EOF
4、執行刪除腳本
sh del.sh