hive数据迁移,cdh3u5的hive中数据迁移到cdh5.1的hive中

hive数据迁移,cdh3u5的hive中数据迁移到cdh5.1的hive中,由于distcp不能使用,需要手动导出数据

on hadoop4

cd /tmp/test/people_payment_log

hadoop fs -get /data/warehouse/userdb.db/people_payment/hour=201309* .

hadoop fs -get /data/warehouse/userdb.db/people_payment/hour=201310* .

hadoop fs -get /data/warehouse/userdb.db/people_payment/hour=201311* .

hadoop fs -get /data/warehouse/userdb.db/people_payment/hour=201312* .

hadoop fs -get /data/warehouse/userdb.db/people_payment/hour=201401* .

hadoop fs -get /data/warehouse/userdb.db/people_payment/hour=201402* .

hadoop fs -get /data/warehouse/userdb.db/people_payment/hour=201403* .


cd /tmp/test

tar -czf people_payment_log.tgz people_payment_log


压缩,copy到hdp7,/home/abc/cdh/people_payment,解压缩

on hdp7,scp -Cr hadoop4:/tmp/test/people_payment_log.tgz /home/abc/cdh/people_payment

cd /home/abc/cdh/people_payment;tar -xzf people_payment_log.tgz

将数据上传到cdh5集群的people_payment表中,shell内容如下:

base_dir=/home/abc/cdh/people_payment

data_dir=$base_dir/people_payment_log

ls $data_dir >$base_dir/hour.txt

cd $data_dir

 cat $base_dir/hour.txt |while read oneHour

do

    echo $oneHour

hadoop fs -put $oneHour /user/hive/warehouse/userdb.db/people_payment/

done


然后需要让hive metastore知道这些分区的存在,生成分区alert语句。

base_dir=/home/abc/cdh/people_payment

cd $base_dir 

echo "use userdb;">$base_dir/alert.txt

cat $base_dir/hour.txt |while read oneHour

do

    realy_hour=`echo $oneHour|awk -F '=' '{print $2}'`

echo "ALTER TABLE people_payment ADD PARTITION (hour = '$realy_hour');">>$base_dir/alert.txt 

done


alert.txt的内容类似

use userdb;

ALTER TABLE people_payment ADD PARTITION (hour = '2013090100');

ALTER TABLE people_payment ADD PARTITION (hour = '2013090101');


然后调用hive -f alert.txt集中进行alert partition。


直接有文件存在的话,可以用下面的方式导入hive

脚本内容如下:

base_dir=/home/abc/cdh/people_payment

data_dir=/data/login/data_login_raw

hive_db=userdb

table=user_login


 ls $data_dir/a.bc.d.201408*|awk -F '.' '{print $5}'>$base_dir/hour.txt

 cat $base_dir/hour.txt |while read oneHour

do

    echo $oneHour

    sql="use $hive_db;LOAD DATA LOCAL INPATH '$data_dir/a.bc.d.$oneHour'  OVERWRITE INTO table $table partition ( hour=$oneHour);"

    echo "===================================================$sql"

    /home/abc/cdh/hive/bin/hive -e "$sql"

done


最好是生成一个批量的LOAD DATA LOCAL INPATH。..语句

然后hive -f调用,避免了多次启动hive client.


你可能感兴趣的:(hive数据迁移,cdh3u5的hive中数据迁移到cdh5.1的hive中)