hive临时目录清理

5 篇文章 0 订阅

hive运行失败会导致临时目录无法自动清理,因此需要自己写脚本去进行清理

实际发现hive临时目录有两个:
/tmp/hive/{user}/*
/warehouse/tablespace//hive/**/.hive-staging_hive

分别由配置hive.exec.scratchdir和hive.exec.stagingdir决定:
在这里插入图片描述
在这里插入图片描述
要注意的是stagingdir可能存在多个层级的目录中,比如xxx.db/.hive-staging_xxx,xxx.db/${table}/.hive-staging_xxx。这里为了偷懒,只清理两层即可,如果发现有更多层,再多加一层的调用即可

创建清理脚本clean_hive_tmpfile.sh

#!/bin/bash
usage="Usage: cleanup.sh [days]"
        if [ ! "$1" ]
        then
        echo $usage
        exit 1
fi
 
now=$(date +%s)
days=$1
 
cleanTmpFile() {
        echo "clean path:"$1
        su hdfs -c "hdfs dfs -ls -d $1" | grep "^d" | while read f; do
                dir_date=`echo $f | awk '{print $6}'`
                difference=$(( ( $now - $(date -d "$dir_date" +%s) ) / (24 * 60 * 60 ) ))
 
                if [ $difference -gt $days ]; then
                        echo $f
                        name=`echo $f| awk '{ print $8 }'`
                        echo "delete:"$name
                        su hdfs -c "hadoop fs -rm -r -skipTrash $name"
                fi
        done
 
}
 
cleanTmpFile /tmp/hive/*/*
cleanTmpFile "/warehouse/tablespace/*/hive/*/.hive-staging_*"
cleanTmpFile "/warehouse/tablespace/*/hive/*/*/.hive-staging_*"

配置crontab,每天凌晨2点执行,清理30天以前的目录

0 2 * * * sh /data/script/clean_hive_tmpfile.sh 30 >> /tmp/clean_hive_tmpfile.log

参考:
https://cwiki.apache.org/confluence/display/Hive/Configuration+Properties#ConfigurationProperties-hive.start.cleanup.scratchdir
https://www.cnblogs.com/ucarinc/p/11831280.html
https://blog.csdn.net/zhoudetiankong/article/details/51800887
http://t.zoukankan.com/telegram-p-10748530.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值