版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載馅扣。http://www.reibang.com/p/77c1ca19d3cb
集群A上HIVE表數(shù)據(jù)需同步到集群B上,由于每張表做了日分區(qū),傳輸部分日期數(shù)據(jù)向族,通過手工方式一一篩選比較復(fù)雜,編寫腳本實現(xiàn)棠绘。
#件相!/bin/sh
hdfs_src="hdfs://源集群NN地址:8020"
hdfs_dst="hdfs://目標(biāo)集群NN地址:8020"
hadoop_cmd="hadoop distcp -update -bandwidth 50"
declare -A dict? ? //聲明字典
dict['talbe1']="/hdfs上table1對應(yīng)的上層目錄/table1"
dict['talbe2']="/hdfs上table2對應(yīng)的上層目錄/table2"
start_day="20190303"
end_day="20190509"
for table in $(echo ${!dict[*]})? ? ? //遍歷字典所有key值,即表名
do
? hdfs_path=$(echo ${dict[$table]})? //賦值每張表對應(yīng)的hdfs路徑
? start_date=`date -d "$start_day" +%Y%m%d`? //獲取日期變量
? end_date=`date -d "$end_day" +%Y%m%d`
? ? ? while [[ $start_date < $end_date ]]
? ? ? do
? ? ? hadoop distcp -update -bandwith 15 $hdfs_src$hdfs_path/dt=$start_date $hdfs_dst$hdfs_path/dt=$start_date
? ? ? start_date=`date -d "+1 day $start_date" +%Y%m%d`
? ? ? done
done
之后在集群B上建庫建表,執(zhí)行msck repair table 表名氧苍。這步后面再更新到腳本中夜矗。