AI智能
改变未来

shell脚本导出gbase数据库数据,并实现大于20MB自动压缩

参数一为传过来的事实表名称,用于构建查询sql

参数二为指定导出文件格式

参数三为数据集名称,用于定义文件名

#!/bin/bash

export NLS_LANG=\”AMERICAN_AMERICA.AL32UTF8\”

factName=$1
format=$2
cubeName=$3
OUT_DIR=\’/data/evap/download/data\’
OUT_FILENAME=${cubeName}\’.\’${format}
GCCLI=/disp_app/gcluster/server/bin/gbase
gbase_node=134.160.36.230
db_username=\’evap_db\’
db_con_user=\’evap\’
db_con_pwd=\’Of0#QY\’
FIELDS=\’|\’
ESCAPED_BY=\’\’
LINES=\’\\r\\n\’

if [ -f \”${OUT_DIR}/${OUT_FILENAME}\” ]; then
rm -rf ${OUT_DIR}/${OUT_FILENAME}
fi

export GCLUSTER_BASE=/disp_app/gcluster
export GCLUSTER_HOME=${GCLUSTER_BASE}/server
export GCLUSTER_SID=gcluster
export PATH=$GCLUSTER_HOME/bin:$PATH
export LD_LIBRARY_PATH=$GCLUSTER_HOME/lib/gbase:$LD_LIBRARY_PATH
alias gccli=\’/disp_app/gcluster/server/bin/gbase\’

${GCCLI} -u${db_con_user} -p${db_con_pwd} -h${gbase_node} -D${db_username} -e \”select * from ${factName} into outfile \’${OUT_DIR}/${OUT_FILENAME}\’ LINES TERMINATED BY \’${LINES}\’ FIELDS TERMINATED BY \’${FIELDS}\’ ESCAPED BY \’${ESCAPED_BY}\’\”

filesize= `ls -l ${OUT_DIR}/${OUT_FILENAME} | awk \'{ print $5 }\’`
maxsize=$((1024*20))
if [ ${filesize} -gt ${maxsize} ]; then
    zip -m -q -j ${OUT_DIR}/${OUT_FILENAME}.zip ${OUT_DIR}/${OUT_FILENAME}
    echo \’zip\’
else 
    echo \”${format}\”
fi

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » shell脚本导出gbase数据库数据,并实现大于20MB自动压缩