全量导入
#! /bin/bash
date=`date -d today +"%Y-%m-%d"`
if [ x"$1" = x ]; then
echo "====使用自动生成的今天日期===="
else
date=$1
fi
echo "日期为:$date"
sqoop import
-D mapred.job.queue.name=hive
-D mapred.task.timeout=0
--connect jdbc:mysql://hadoop13:3306/ycak?characterEncoding=UTF-8
--username root
--password ******
--table user_alipay_baseinfo
--target-dir /user/hive/warehouse/songdb.db/to_ycak_usr_ali_d/
--delete-target-dir
--num-mappers 1
--fields-terminated-by "t"
--null-string '\N'
--null-non-string '\N'
增量导入 -append
#! /bin/bash
# date:如果传入时间使用传入的时间,如果没有传入时间,则使用今天的日期
date=`date -d today +"%Y-%m-%d"`
if [ x"$1" = x ]; then
echo "====使用自动生成的今天日期===="
else
date=$1
fi
echo "日期为:$date"
#查询hive中id的最大值,即maxid,从maxid的下一位开始增量导入hive ()
maxid=`/opt/installs/hive3.1.2/bin/hive -e "set hive.cli.print.header=false;select max(id) from songdb.TO_YCAK_USR_LOGIN_D"`
echo "hive的TO_YCAK_USR_LOGIN_D表中存储的最大id值:$maxid"
if [ "$maxid" = "NULL" ];then
maxid=0
fi
echo "hive的TO_YCAK_USR_LOGIN_D表中存储的最大id值:$maxid"
sqoop import
-D mapred.job.queue.name=hive
-D mapred.task.timeout=0
--connect jdbc:mysql://hadoop13:3306/ycak?characterEncoding=UTF-8
--username root
--password ******
--table user_login_info
--target-dir /user/hive/warehouse/songdb.db/to_ycak_usr_login_d/data_dt=$date
--num-mappers 1
--fields-terminated-by "t"
--null-string '\N'
--null-non-string '\N'
--incremental append
--check-column id
--last-value $maxid



