hive集羣間數據遷移,export+import

官方參考鏈接:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+ImportExport

The EXPORT and IMPORT commands were added in Hive 0.8.0 (see HIVE-1918).

Replication extensions to the EXPORT and IMPORT commands were added in Hive 1.2.0 (see HIVE-7973 and Hive Replication Development).


1.生成導出腳本

beeline -u 'jdbc:hive2://bigdata01.younge.club:10000' -n test-user -p 123456 -e "use bigdata_ods;show tables" | grep 'ods*' | awk '{print $2}' | awk '{printf "export table bigdata_ods.%s to @/tmp/hive_export/%s@;\n",$1,$1}' | sed "s/@/'/g" > hive_export.hql


3.執行導出腳本
beeline -u 'jdbc:hive2://bigdata01.younge.club:10000' -n test-user -p 123456 -f hive_export.hql


4.下載hdfs數據到本地
hdfs dfs -get /tmp/hive_export/


5.壓縮生成的本地的hive_export文件夾
tar -czvf hive_export.tar.gz hive_export


6.上傳到目標集羣並解壓縮
tar -xvzf hive_export.tar.gz


7.上傳到目標集羣的HDFS目錄中
hdfs dfs -put hive_export /tmp/hive_export


8.構造導入腳本
cp hive_export.sql hive_import.sql
sed -i 's/export table/import table/g' hive_import.sql
sed -i 's/ to / from /g' hive_import.sql


9.hive新建目標數據庫
create database bigdata_ods;


10.執行導入腳本,導入數據
beeline -u 'jdbc:hive2://bigdata01.younge.club:10000' -n test-user -p 123456 -f hive_import.hql
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章