您现在的位置是:首页 > 文章详情

hive数据迁移

日期:2016-08-21点击:506

比如需要把生产的hive集群数据迁移到另一个集群,hive提供了2个命令工具,可以实现表的批量迁移。

[export/import]

  • 设置默认需要导出的hive数据库
在hive目录/etc/alternatives/hive-conf下添加.hiverc vi ~/.hiverc use test;
  • 创建数据临时目录
hdfs dfs -mkdir /tmp/test
  • 生成导出数据脚本
hive -e "show tables " | awk '{printf "export table %s to |/tmp/hive-export/%s|;\n",$1,$1}' | sed "s/|/'/g" > /home/hive/qcf/export.hql
  • 手工导出数据到hdfs
hive -f export.hql

- 下载hdfs数据到本地并传送到目标hadoop集群的/tmp/ test 目录 先get到本地:

hdfs dfs -get /tmp/ test /*
  • 然后put到目标集群上
hdfs dfs -put * /tmp/test
  • 构造导入语句
cp export.sql import.sql sed -i 's/export table/import table/g' import.sql sed -i 's/ to / from /g' import.sql
  • 导入数据
在hive目录/etc/alternatives/hive-conf下添加.hiverc vi ~/.hiverc use test; hive -f import.sql 
原文链接:https://yq.aliyun.com/articles/66042
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章