sqoop匯出指令碼

2021-08-13 09:50:40 字數 2820 閱讀 3750

sqoop匯出指令碼:

#!/bin/sh

source exitcodecheck.sh

opts=$@

getparam()'

}incstart=`getparam inc_start`

incend=`getparam inc_end`

pg_connection=`getparam jdbc_str`

pg_username=`getparam db_user`

pg_password=`getparam db_psw`

dataname=`getparam db_sid`

queuename=`getparam hdp_queue`

hdfshostname=`getparam hdfs_host`

incstartyear=`echo $`;

incstartmonth=`echo $`;

incstartday=`echo $`;

incstartall=$"-"$"-"$" 00:00:00.0";

incstartallformat=$"-"$"-"$;

incendyear=`echo $`;

incendmonth=`echo $`;

incendday=`echo $`;

incendall=$"-"$"-"$" 00:00:00.0";

twodayago=`date -d "$incstart 2 days ago  " +%y%m%d  `;

twodayagoyear=`echo $`;

twodayagomonth=`echo $`;

twodayagoday=`echo $`;

twodayagoall=$"-"$"-"$" 00:00:00.0";

twodayagoallformat=$"-"$"-"$;

job_name=$0

#需要匯出的資料pg表名

export_table_name=n_par_life_hrm_org;

#需要匯出到pg的資料的臨時檔名

sqoop_export_data_filename=$;

#需要匯出的資料pg列名

export_table_columns=statis_date,um_num,um_name,group_id,group_name,department_id,department_name,center_id,center_name

#需要匯出到pg的資料的臨時檔案目錄

hadoop dfs -rmr $;

#建立用於匯出到pg的臨時資料

hive -v -e "set mapred.job.queue.name=$; 

set mapred.job.name=$_1;

use an_pafc_safe;

insert overwrite directory '$' 

select 

'$'  as  statis_date,

um_num,

um_name,

group_id,

group_name,

department_id,

department_name,

center_id,

center_name 

from lnc_hdw_safe.n_par_life_hrm_org ;";

exitcodecheck $?

#先刪除目的資料庫的資料2天前數

sqoop eval -dmapred.job.queue.name=$ \

--connect $ \

--username $ \

--password $ \

-query  "delete from $ a where a.statis_date=date('$')";

exitcodecheck $?

#先刪除目的資料庫的資料,支援二次執行

sqoop eval -dmapred.job.queue.name=$ \

--connect $ \

--username $ \

--password $ \

-query  "delete from $ a where a.statis_date=date('$')";

exitcodecheck $?

#再匯出資料

sqoop export -d mapred.job.name=$_2 -d sqoop.export.statements.per.transaction=4500 -d mapreduce.map.tasks=1 -d mapred.map.max.attempts=1 -d mapred.reduce.max.attempts=1 -d mapreduce.map.maxattempts=1 -d mapreduce.reduce.maxattempts=1 -d mapred.job.queue.name=$ \

--connect $ \

--username $ \

--password $ \

--export-dir $ \

--verbose \

--table $ \

--columns $ \

--input-fields-terminated-by '\001'  \

--input-lines-terminated-by '\n'  \

--input-null-string '\\n'  \

--input-null-non-string '\\n';

exitcodecheck $?

sqoop匯出指令碼

bin bash if 1 then export hive db name 1 else echo 請指定要匯出的源資料庫 exit 1 fiif 2 then export hive t name 2 else echo 請指定要匯出的源表名 exit 1 fiif 3 then export ...

sqoop匯入匯出

sqoop官方手冊位址 最近在看sqoop有些感想,就寫下來。sqoop是大資料裡面匯入匯出的乙個工具。關於import匯出 可以從mysql匯出到hdfs,hbase,hive,案例如下,這是乙個匯出到hdfs的案例 import connect jdbc mysql username root ...

sqoop匯入 匯出

全部匯入 sqoop import connect jdbc mysql hadoop01 3306 test1 username root password 1234 table students target dir user test1 delete target dir fields ter...