迁移hive表及hive数据

公司hadoop集群迁移,需要迁移所有的表结构及比较重要的表的数据(跨云服务机房,源广州机房,目标北京机房)

1、迁移表结构

1)、老hive中导出表结构

hive -e "use db;show tables;" > tables.txt
#!/bin/bash

cat tables.txt |while read eachline
do
hive -e "use klwarehouse;show create table $eachline" >>tablesDDL.txt
echo ";" >> tablesDDL.txt
done  

2)、新hive中导入表结构

hive -f tableDDL.txt

  

对了,执行之前要先建立db,然后在tableDDL.txt前面加上use db;

 

2、迁移表数据

目前使用的方案是一个一个将表数据导出到HDFS,接着下载到云主机中,压缩,外网传到新的hive集群网络中的主机中,解压,上传至HDFS,上传至HIVE

1)、将HIVE表数据导出至HDFS

hdfs dfs -mkdir /tmp/hive-export

use db; export table 表名 to /tmp/hive-export

  

2)、将HDFS数据下载至主机中

hdfs dfs -get /tmp/hive-export/

 

3)、将数据压缩

tar -zcvf hivetable1.tar.gz hive-export

  

4)、将数据发送至目标hive集群的内网主机中

scp hivetable1.tar.gz root@x.x.x.x:/data  

 

5)、解压数据

tar -zxvf hivetable1.tar.gz

 

6)、将数据上传至HDFS中

hdfs dfs -put hive-export/ /tmp/hive-export

  

7)、将HDFS数据上传至Hive表中

use db;
import table 表名 from /tmp/hive-export

  

 

posted @ 2020-02-01 16:22  HarkLee  阅读(5309)  评论(0编辑  收藏  举报