公司要完成hive數(shù)據(jù)遷移
1.創(chuàng)建hdfs臨時文件夾來保存數(shù)據(jù)
hdfs dfs -mkdir /test
- 生成數(shù)據(jù)導(dǎo)出腳本
執(zhí)行以下的命令毕荐,生成數(shù)據(jù)導(dǎo)出的腳本
hive -e "set hive.cli.print.header=false;use test;show tables" | awk '{printf "export table %s to /tmp/hive-export/%s;\n",$1,$1}' > export.sql
3.執(zhí)行導(dǎo)出腳本
hive -f export.sql
4.傳遞數(shù)據(jù)
這里可以下載數(shù)據(jù)到本地進行傳輸嚎莉,或是使用hadoop distcp送滞,關(guān)鍵在于網(wǎng)絡(luò)是否聯(lián)通
# 網(wǎng)絡(luò)聯(lián)通
hadoop distcp -skipcrccheck -update hdfs://master001:9000/test hdfs://master002:9000/test
-skipcrccheck 省略crc檢查,如果hadoop版本一樣拔恰,可以不加粘优,如果低版本向高版本遷移的話卵佛,最好帶上
-update 增量更新,通過文件名稱茧痕,大小比較野来,源文件和目標(biāo)文件不同則更新
#網(wǎng)絡(luò)不連通
hdfs dfs -get /tmp/hive-export/
scp -r hive-export/ export.sql master002
hdfs dfs -put hive-export/ /tmp/hive-export
5.生成數(shù)據(jù)導(dǎo)入腳本
cp export.sql import.sql
sed -i 's/export table/import table/g' import.sql
sed -i 's/ to / from /g' import.sql
6.導(dǎo)入數(shù)據(jù)
hive -f import.sql