集群迁移hive表(无建表语句)

生产环境账号回收,需要把所有数据表迁移到测试环境!!!
上百张表,已经找不到原始建表语句,只能自己想办法了。
百度很久,最终决定通过shell把从集群上把建表语句下载下来:
新建list_tables.sql

use db;
show tables;

新建show_create.sql

use db;
show create table ${hiveconf:table};

download_test.sh

#! /bin/bash
hive -S -f list_tables.sql > tables_name.txt
cat tables_name.txt | while read eachline
do
    hive -hiveconf table=${eachline} -S -f show_create.sql >> tables_structure.txt
    echo >> tables_structure.txt
done
hdfs dfs -put *.txt /user/asmp/shell
rm -rf tables_name.txt tables_structure.txt

最终把建表语句下载到tables_structure.txt中,经过简单处理在测试集群执行。

注意事项:
表名和字段不支持中文注释 COMMENT ‘???’,最好手动处理下。

发布了118 篇原创文章 · 获赞 25 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/lhxsir/article/details/90448768