以下脚本是对hive相关版本没有改变的
#!/bin/bash
#set -x
DB=$1
#获取hive表定义
ret=$(hive -e "use ${DB};show tables;"|grep -v _es|grep -v _hb|grep -v importinfo)
ret=$(hive -e "use ${DB};show tables;"|grep -v _es|grep -v _hb|grep -v importinfo)
for tem in $ret;
do
hive -e "use ${DB};show create table $tem" >> /home/hdfs/hivesql.sql
echo -e ';\c' >> /home/hdfs/hivesql.sql
done
#迁移hive的表数据
ret=$(hive -e "use ${DB};show tables;"|grep -v _es|grep -v _hb|grep -v importinfo)
for tem in $ret;
do
hadoop distcp hdfs://master1:8020/apps/hive/warehouse/${DB}.db/$tem hdfs://master2:8020/apps/hive/warehouse/${DB}.db/$tem
done
在目标hive集群执行 hive -f hivesql.sql