#!/bin/bash
domain="xy.push.live.fanxing.com"
current_storage_dir="/data1/worker.snapshotv3.live.xycdn.com/store/"
log_time="date +%F_%T"
date=`date +"%Y%m%d"`
pre_date=`date +"%Y%m%d" -d "1 day ago"`
pre_two_date=`date +"%Y%m%d" -d "2 day ago"`
function write_log() {
content=$1
echo "`${log_time}` $1" >>/tmp/du_count_time.log
}
function archive_count() {
for i in `seq 2 13`
do
if [ -d /data$i/worker.snapshotv3.live.xycdn.com/store ];then
for date in $(ls /data$i/worker.snapshotv3.live.xycdn.com/store)
do
cd /data$i/worker.snapshotv3.live.xycdn.com/store/$date;ls|grep "$domain"
if [ $? -eq 0 ];then
du -sh $domain >>/tmp/du_count.log
else
echo "the date dir is not exist $domain snapshot"
continue
fi
done
else
echo "$data$i is not exist $domain snapshot"
continue
fi
done
}
function current_count() {
[ -d $current_storage_dir ] || exit 1
arr_current_storage=($pre_two_date $pre_date $date)
for date_dir in ${arr_current_storage[*]}
do
cd ${current_storage_dir}${date_dir};ls|grep "$domain"
if [ $? -eq 0 ];then
du -sh $domain >>/tmp/du_count.log
else
echo "the date dir is not exist $domain snapshot"
continue
fi
done
}
main() {
# [ -f /tmp/du_count.log ] && echo -n >/tmp/du_count.log
# write_log "start count fanxing archive snapshot captity"
# archive_count
# write_log "END count fanxing archive snapshot captity"
write_log "start count fanxing current 3 days snapshot captity"
current_count
write_log "end count fanxing current 3 days snapshot captity"
awk '{sum+=/T/?$1*1024:(/M/?$1/1024:$1)}END{print "Sum="sum"G"}' /tmp/du_count.log
}
main