应用实例
需求:
编写一个脚本
将sqoop_db中的goods_table表每天抽取所有数据并导入到hdfs:/user/hainiu/goods_table目录下。并按照每天的日期生成对应的目录保存表数据。以shell脚本的方式运行每天定时运行。
vim goods_op.sh
batch_date=$1
sqoop import \
--connect jdbc:mysql://nn1:3306/sqoop_db \
--username root \
--password 12345678 \
--target-dir /user/hainiu/goods_table/${batch_date}/ \
--delete-target-dir \
--fields-terminated-by "\t" \
--split-by Id \
--query 'select * from goods_table where $CONDITIONS'
res=$?
if [ ${res} != 0 ];then
echo 'extract goods_table error! '`date` >> /data/hainiu/extract/goods_table.log
exit 1
else
echo 'extract goods_table successful '`date` >> /data/hainiu/extract/goods_table.log
fi
执行时,需要从外界将日期传递过来
# 给脚本添加执行权
chmod a+x goods_op.sh
# 执行脚本
sh -x goods_op.sh 20230305
该文章描述了一个Shell脚本`goods_op.sh`,用于每天通过Sqoop从`sqoop_db`数据库的`goods_table`表中抽取所有数据,并导入到HDFS的`/user/hainiu/goods_table`目录下,按照日期创建子目录存储。脚本接受日期参数,当执行出错时,会将错误信息记录到日志文件。
1166

被折叠的 条评论
为什么被折叠?



