單表導出正常,但在 Shell 腳本中連續執行多條 sqoop export 命令時,第二張表數據導出失敗。
#!/bin/bash
tables=("RST_ERR_1" "RST_ERR_2")
for t in "${tables[@]}"; do
sqoop export \
--connect jdbc:mysql://192.168.80.101:3306/test \
--username root --password root \
--table "$t" \
--export-dir /user/hive/warehouse/hubei.db/"$t" \
--input-fields-terminated-by '\001'
if [ $? -ne 0 ]; then
echo "導出 $t 失敗"
exit 1
fi
done
36 16 * * * /home/analysis.sh >> /dev/null 2>&1
UNION ALL 合併數據,再單次導出。生產環境建議使用調度系統(如 Azkaban、Airflow)管理依賴與重試。