遷移hive,不同集群。

2021-09-08 05:14:12 字數 1321 閱讀 3002

step1: 設定預設需要匯出的hive資料庫為defaultdatabase

在原集群中的任意節點上,新建「.hiverc」檔案,加入如下內容:

vi ~/.hiverc

use defaultdatabase;

defaultdatabase可修改為需要遷移的其它名稱

step2: 建立資料臨時目錄

hdfs dfs -mkdir /tmp/hive-export
step3: 生成資料匯出指令碼

執行如下命令生成資料匯出指令碼:

hive -e "show tables" | awk '' | sed "s/@/'/g" > export.sql

-- 這裡是生成全部的表,如果是遷移幾個表的話,那麼直接可以自己寫export.sql

-- 例如:export table rv_cloud_source   to '/tmp/hive-export/rv_cloud_source';

step4: 手工匯出資料到hdfs

執行指令碼匯出資料

hive -f export.sql

-- 這裡可以在export.sql加上use database;

hdfs dfs -get /tmp/hive-export/   

scp -r hive-export/ export.sql root@targetdir

hdfs dfs -put hive-export/ /tmp/hive-export

step6: 生成資料匯入指令碼

執行如下命令,複製匯出指令碼,並將指令碼修改為匯入指令碼:

cp export.sql import.sql

sed -i 's/export table/import table/g' import.sql

sed -i 's/ to / from /g' import.sql

-- 這裡是匯入全部表,所以使用sed做了一下替換,如果只匯入幾個hive 表,那麼這樣即可:

-- use database; import table rv_cloud_adsdksource from '/tmp/hive-export/rv_cloud_adsdkactiveuser';

step7: 匯入資料

hive -f import.sql 

主要**: 中的hive遷移

Hive跨集群遷移

hive跨集群遷移資料工作是會出現的事情,其中涉及到資料遷移,metastore遷移,hive版本公升級等。1.遷移hdfs資料至新集群 hadoop distcp skipcrccheck update hdfs hdfs skipcrccheck 因本次遷移涉及低版本遷移高版本,如果hadoop...

集群間 Hive 資料 遷移 問題

1 從hive中匯出資料至本地目錄 insert overwrite local directory export tmp select from test1 where create time 2013 11 25 列資料之間預設以 a隔開。2 將本地資料上傳另乙個集群的hdfs usr loca...

hive集群間資料遷移,export import

theexportandimportcommands were added in hive 0.8.0 see hive 1918 replication extensions to theexportandimportcommands were added in hive 1.2.0 see hi...