这篇文章主要介绍“hive数据怎么迁移”,在日常操作中,相信很多人在hive数据怎么迁移问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”hive数据怎么迁移”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
hive数据迁移,cdh4u5的hive中数据迁移到cdh6.1的hive中,由于distcp不能使用,需要手动导出数据
on hadoop4
cd /tmp/test/people_payment_log
hadoop fs -get /data/warehouse/userdb.db/people_payment/hour=201309* .
hadoop fs -get /data/warehouse/userdb.db/people_payment/hour=201310* .
hadoop fs -get /data/warehouse/userdb.db/people_payment/hour=201311* .
hadoop fs -get /data/warehouse/userdb.db/people_payment/hour=201312* .
hadoop fs -get /data/warehouse/userdb.db/people_payment/hour=201401* .
hadoop fs -get /data/warehouse/userdb.db/people_payment/hour=201402* .
hadoop fs -get /data/warehouse/userdb.db/people_payment/hour=201403* .
cd /tmp/test
tar -czf people_payment_log.tgz people_payment_log
压缩,copy到hdp7,/home/abc/cdh/people_payment,解压缩
on hdp7,scp -Cr hadoop4:/tmp/test/people_payment_log.tgz /home/abc/cdh/people_payment
cd /home/abc/cdh/people_payment;tar -xzf people_payment_log.tgz
将数据上传到cdh6集群的people_payment表中,shell内容如下:
base_dir=/home/abc/cdh/people_payment
data_dir=$base_dir/people_payment_log
ls $data_dir >$base_dir/hour.txt
cd $data_dir
cat $base_dir/hour.txt |while read oneHour
do
echo $oneHour
hadoop fs -put $oneHour /user/hive/warehouse/userdb.db/people_payment/
done
然后需要让hive metastore知道这些分区的存在,生成分区alert语句。
base_dir=/home/abc/cdh/people_payment
cd $base_dir
echo "use userdb;">$base_dir/alert.txt
cat $base_dir/hour.txt |while read oneHour
do
realy_hour=`echo $oneHour|awk -F '=' '{print $2}'`
echo "ALTER TABLE people_payment ADD PARTITION (hour = '$realy_hour');">>$base_dir/alert.txt
done
alert.txt的内容类似
use userdb;
ALTER TABLE people_payment ADD PARTITION (hour = '2013090100');
ALTER TABLE people_payment ADD PARTITION (hour = '2013090101');
然后调用hive -f alert.txt集中进行alert partition。
直接有文件存在的话,可以用下面的方式导入hive
脚本内容如下:
base_dir=/home/abc/cdh/people_payment
data_dir=/data/login/data_login_raw
hive_db=userdb
table=user_login
ls $data_dir/a.bc.d.201408*|awk -F '.' '{print $5}'>$base_dir/hour.txt
cat $base_dir/hour.txt |while read oneHour
do
echo $oneHour
sql="use $hive_db;LOAD DATA LOCAL INPATH '$data_dir/a.bc.d.$oneHour' OVERWRITE INTO table $table partition ( hour=$oneHour);"
echo "===================================================$sql"
/home/abc/cdh/hive/bin/hive -e "$sql"
done
最好是生成一个批量的LOAD DATA LOCAL INPATH。..语句
然后hive -f调用,避免了多次启动hive client.
到此,关于“hive数据怎么迁移”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。