#/bin/bash
## ********************************************
## 名 称:statis_hdfs_cnt.sh
## 功能描述:统计hdfs昨天分区的数据量
## 创建人员: ypg
## 创建日期:
## 修改信息:
## 版 本: V1.0
## 起调方式:sh statis_hdfs_cnt.sh statis_hdfs_cnt.conf
## 参数说明:$1:配置文件,跟脚本同级目录
## ********************************************
#加载环境
source ~/.bash_profile
hd_source
local_path=/test/statis_hdfs_cnt
copy_path=/user/hive/warehouse/copy.db
new_path=/user/hive/warehouse/new.db
back_path=/user/hive/warehouse/bak.db
one_day_ago=`date -d"1 day ago" +%Y%m%d`
[ -e ${local_path}/statis_hdfs_cnt.txt ] && rm ${local_path}/statis_hdfs_cnt.txt
#备份一天前的数据,并将小文件合并
function statis_hdfs_cnt_fun(){
hadoop fs -test -d ${copy_path}/${tableName}/etl_date=${one_day_ago}
if [ $? -eq 0 ]; then
cnt=`hadoop fs -cat ${copy_path}/${tableName}/etl_date=${one_day_ago}/* | wc -l`
echo "${tableName}\t${one_day_ago}\t$cnt" >> ${local_path}/statis_hdfs_cnt.txt
else
hadoop fs -test -d ${new_path}/${tableName}/etl_date=${one_day_ago}
if [ $? -eq 0 ]; then
cnt=`hadoop fs -cat ${new_path}/${tableName}/etl_date=${one_day_ago}/* | wc -l`
echo "${tableName}\t${one_day_ago}\t$cnt" >> ${local_path}/statis_hdfs_cnt.txt
else
cnt=`hadoop fs -cat ${back_path}/${tableName}/etl_date=${one_day_ago}/* | wc -l`
echo "${tableName}\t${one_day_ago}\t$cnt" >> ${local_path}/statis_hdfs_cnt.txt
fi
fi
}
#遍历处理
for tableName in `cat ${local_path}/$1`
do
statis_hdfs_cnt_fun ${tableName}
done
统计hdfs昨天分区的数据量
最新推荐文章于 2024-08-03 21:57:01 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)