主要流程
1.将旧集群的hive数据导出至其hdfs中
2.将旧集群hdfs中的导出数据下载到本地中
3.将本地的导出数据上传至新的集群hdfs中
4.将新集群hdfs中的数据导入至新集群中的hive中
vim ~/.hiverc
use export_db;
hdfs dfs -mkdir -p /tmp/export_db_export
hive -e "show tables;" | awk '{printf "export table %s to |/tmp/export_db_export/%s|;\n",$1,$1}' | sed "s/|/'/g" | grep -v tab_name > ~/export.hql
hive -f ~/export.hql
sudo scp -r export_db_export/ hr@192.168.1.xx:/opt/lzx
hdfs dfs -put ~/export_db /tmp/export_db_export
cp ~/export.sql ~/import.sql
sed -i 's/export /import /g' ~/import.sql
sed -i 's/ to / from /g' ~/import.sql
hive -f ~/import.sql
vim export.hql
export table hr_task_scan_official_3hh partition(ds='20200409') to '/tmp/export_db_export/20200409';
export table hr_task_scan_official_3hh partition(ds='20200410') to '/tmp/export_db_export/20200410';
export table hr_task_scan_official_3hh partition(ds='20200411') to '/tmp/export_db_export/20200411';
export table hr_task_scan_official_3hh partition(ds='20200412') to '/tmp/export_db_export/20200412';
export table hr_task_scan_official_3hh partition(ds='20200413') to '/tmp/export_db_export/20200413';
export table hr_task_scan_official_3hh partition(ds='20200414') to '/tmp/export_db_export/20200414';
hive -e ~/export.hql
无需建表
vim import.sql
import table hr_task_scan_official_3hh from '/tmp/export_db_export/20200409';
import table hr_task_scan_official_3hh from '/tmp/export_db_export/20200410';
import table hr_task_scan_official_3hh from '/tmp/export_db_export/20200411';
import table hr_task_scan_official_3hh from '/tmp/export_db_export/20200412';
import table hr_task_scan_official_3hh from '/tmp/export_db_export/20200413';
import table hr_task_scan_official_3hh from '/tmp/export_db_export/20200414';
hive -f ~/import.sql
beeline -u jdbc:hive2://cdh01:10000 -e "use export_db;show tables;"| awk '{printf "export table %s to |/tmp/export_db_export/%s|;\n",$2,$2}' | sed "s/|/'/g"|sed '1,3d'|sed '$d' > ~/export.hql
sed -i '1i use export_db;' ~/export.hql
beeline -u jdbc:hive2://cdh01:10000 -n hdfs -f ~/export.hql
# 新的集群hdfs目录需要提前创建
hadoop distcp hdfs://cdh01:8020/tmp/export_db_export/ hdfs://cdh02:8020/tmp/export_db_export
cp ~/export.hql ~/import.hql
sed -i 's/export /import /g' ~/import.hql
sed -i 's/ to / from /g' ~/import.hql
sed -i '1d' ~/import.hql
sed -i '1i use import_db;' ~/import.hql
create database import_db;
beeline -u jdbc:hive2://cdh02:10000 -n hdfs -f ~/import.hql