step1: 设置默认需要导出的 hive 数据库为 defaultDatabase
在原集群中的任意节点上, 新建 ".hiverc" 文件, 加入如下内容:
- vi ~/.hiverc
- use defaultDatabase;
defaultDatabase 可修改为需要迁移的其它名称
step2: 创建数据临时目录
hdfs dfs -mkdir /tmp/hive-export
step3: 生成数据导出脚本
执行如下命令生成数据导出脚本:
hive -e "show tables" | awk '{printf"export table %s to @/tmp/hive-export/%s@;\n",$1,$1}' | sed "s/@/'/g"> export.sql
-- 这里是生成全部的表, 如果是迁移几个表的话, 那么直接可以自己写 export.sql
-- 例如: export table rv_Cloud_Source to '/tmp/hive-export/rv_Cloud_Source';
step4: 手工导出数据到 HDFS
执行脚本导出数据
hive -f export.sql
-- 这里可以在 export.sql 加上 use database;
step5: 下载数据
下载 HDFS 数据到本地, 并传送到目标集群 (targetDir 为目标集群地址) 的 / tmp/hive-export 目录:
hdfs dfs -get /tmp/hive-export/
scp -r hive-export/ export.sql root@targetDir
hdfs dfs -put hive-export//tmp/hive-export
step6: 生成数据导入脚本
执行如下命令, 复制导出脚本, 并将脚本修改为导入脚本:
- cp export.sql import.sql
- sed -i 's/export table/import table/g' import.sql
- sed -i 's/ to / from /g' import.sql
-- 这里是导入全部表, 所以使用 sed 做了一下替换, 如果只导入几个 hive 表, 那么这样即可:
-- use database; import table rv_Cloud_ADSDKSource from '/tmp/hive-export/rv_Cloud_ADSDKActiveUser';
step7: 导入数据
hive -f import.sql
主要转自: https://docs.ucloud.cn/analysis/uhadoop/migration 中的 hive 迁移
来源: http://www.bubuko.com/infodetail-2594544.html