1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
| #!/bin/bash
cd ~ source .profile
clear
ipaddress=`hostname -i` hostname=`hostname` exportId=`date +"%m%d%H%M%S"` mdate=`date "+%Y%m%d"`
if [ $# -eq 2 ];then keyword=$1 keyword=`echo $keyword|tr "[a-z]" "[A-Z]"` file_name=$2 file_dir=DS-${mdate} elif [ $# -eq 3 ];then sysname=$1 keyword=$2 keyword=`echo $keyword|tr "[a-z]" "[A-Z]"` file_name=$3 file_dir=${sysname}-${mdate} else echo "Please input the right parameter ..." echo "Eg:" echo "sh ds_eximport.sh export/import JIRA.list" echo "or" echo "sh ds_eximport.sh DS export/import JIRA.list" exit -1 fi
logpath="/home/DS/file/log/shelllog/ds_eximport/${mdate}/"
logfile="${logpath}/${keyword}_${hostname}_${exportId}.log"
Log() { createTime=`date +"%Y-%m-%d %H:%M:%S"` echo "[${createTime}] $*" |tee -a ${logfile} 2>/dev/null }
CheckDir() { if [ ! -d $1 ]; then mkdir_log=` mkdir -p -m 775 $1 ` if [ $? -ne 0 ]; then echo "[$1] create fail!" echo "[$1] does not exist!!please check..." exit 1 fi fi } CheckDir "$logpath"
if [ ${hostname} == "DSJ2PJQ" -o ${hostname} == "DS1PSD" -o ${hostname} == "DSNUAT" -o ${hostname} == "DSPJQ" ];then eximportpath="/home/DS/file/version/" listDir="/home/DS/file/version/" dsuser=$DSUSER dspassword=`java -jar /home/DSsbin/DSSHELL/java/jiemi.jar $DSPWD` dbuser=$DSDBUSER dbpass=`java -jar /home/DSsbin/DSSHELL/java/jiemi.jar $DSDBPWD`
elif [ ${hostname} == "DSJPSD" ];then eximportpath="/home/DS/file/tmp/version/${file_dir}/SQL_DS/" listDir="/home/DS/file/tmp/version/${file_dir}/" dsuser=$DSUSER dspassword=`java -jar /home/DSsbin/DSSHELL/java/jiemi.jar $DSPWD` dbuser=$DSDBUSER dbpass=`java -jar /home/DSsbin/DSSHELL/java/jiemi.jar $DSDBPWD`
elif [ ${hostname} == "MDSDS01" -o ${hostname} == "MDSDS04" -o ${hostname} == "MDSDS07" -o ${hostname} == "MDSDS10" ];then eximportpath="/home/DS/file/tmp/version/${file_dir}/SQL_DS/" listDir="/home/DS/file/tmp/version/${file_dir}/" dsuser=D_user dspassword=`java -jar /home/DSsbin/DSSHELL/java/jiemi.jar "3MwCAjIwMTkwMzIwMTQ1MjMyMDA1NhAf+TgHO77olFnvI0WgAz72EAAAAEKqkrMyPOhc9UYm/QRK1lA="` dbuser=dasuser dbpass=`java -jar /home/DSsbin/DSSHELL/java/jiemi.jar "3MwCAjIwMTkwMzIwMTQ1NDQ0MDU5MxBiOaucB9ihtBI65YJwX5Z4EAAAAK4Svtuu97iwUN/IL6wmBPw="` else echo "No this mathine[${hostname}:${ipaddress}], please check..." echo "No this mathine[${hostname}:${ipaddress}], please check...">>${logfile} exit -1 fi
if [ ${hostname} == "DSJ2PJQ" ];then dbname=DASDB elif [ ${hostname} == "DS1PSD" ];then dbname=DASDB elif [ ${hostname} == "DSNUAT" ];then dbname=DASDB1 elif [ ${hostname} == "DSPJQ" ];then dbname=DASDB elif [ ${hostname} == "DSJPSD" ];then dbname=DASDB elif [ ${hostname} == "MDSDS01" ];then dbname=DSDB1 elif [ ${hostname} == "MDSDS04" ];then dbname=DSDB2 elif [ ${hostname} == "MDSDS07" ];then dbname=DSDB3 elif [ ${hostname} == "MDSDS10" ];then dbname=DSDB4 fi
list="${listDir}/${file_name}" if [ ! -f $list ];then Log "The list file [$list] not exist, please check..." exit -1 fi
Log "--------------------------------------Datastage export & import Tools-------------------------------------------------------"
if [ ! -f /home/dsinst/InformationServer/Clients/istools/cli/istool.sh ] then Log "This machine `hostname -i` does not support istool command." exit -1 fi
if [ "$keyword" == "EXPORT" ];then for line in `cat $list` do jiraInfo=$line line=`echo $line|awk -F'|' '{print $1}'` CheckDir "${eximportpath}/tmp/${line}_${exportId}/" if [ -d ${eximportpath}/${line}/ ];then ls ${eximportpath}/${line}/|grep "\.isx"$>/dev/null if [ $? -eq 0 ];then mv ${eximportpath}/${line}/*.isx ${eximportpath}/tmp/${line}_${exportId}/ fi fi CheckDir "${eximportpath}/${line}/" jobNum=0 Log "Begin to export all the jobs which jira.no is ['${line}'], please wait..." jobcountsql="SELECT count(*) FROM DATASTAGEX_DSJOBDEF WHERE locate(':', DSNAMESPACE_XMETA ) <> 0 and SHORTDESCRIPTION_XMETA='${line}'" db2 connect to $dbname user $dbuser using $dbpass 1>/dev/null; if [ $? -ne 0 ];then Log "Connect to $dbname user $dbuser, please check..." exit -1 fi jobcountres=`db2 -nox "${jobcountsql}";` joballnum=`echo $jobcountres|tr -d ' '` if [ ${joballnum} -eq 0 ];then Log "This Jira.no [$line] there is no DS job to export." continue else >${eximportpath}/${line}/${keyword}_${line}.list jobsql="SELECT substr(DSNAMESPACE_XMETA,locate(':', DSNAMESPACE_XMETA )+1 ) as PROJECTNAME,NAME_XMETA as JOBNAME,replace(CATEGORY_XMETA,'\\\','/') as JOBPATH FROM DATASTAGEX_DSJOBDEF WHERE locate(':', DSNAMESPACE_XMETA ) <> 0 and SHORTDESCRIPTION_XMETA='${line}'" joblist=`db2 -nox "${jobsql}";` db2 disconnect "$dbname">/dev/null; echo "$joblist" | while read PROJECTNAME JOBNAME JOBPATH do jobNum=$((jobNum+1)) jobNameLine=`echo ${hostname}/${PROJECTNAME}/${JOBPATH}/${JOBNAME}.pjb` /home/dsinst/InformationServer/Clients/istools/cli/istool.sh export -domain $ipaddress:9446 -u $dsuser -p $dspassword -ar ${eximportpath}/${line}/${PROJECTNAME}.${JOBNAME}.isx -ds '-incexec "'${jobNameLine}'"'>/dev/null 2>&1 if [ ! -f ${eximportpath}/${line}/${PROJECTNAME}.${JOBNAME}.isx ];then Log "${jobNum}/${joballnum}|${PROJECTNAME}|${JOBNAME}|${line} Export Failed!" else Log "${jobNum}/${joballnum}|${PROJECTNAME}|${JOBNAME}|${line} Export Succed!" fi echo "${jobNum}/${joballnum}|${PROJECTNAME}|${JOBNAME}|${line}|${JOBPATH}"|tee -a ${eximportpath}/${line}/${keyword}_${line}.list>/dev/null 2>&1 done jobAll=0 jobSucc=0 jobFail=0 for JobIsx in `cat ${eximportpath}/${line}/${keyword}_${line}.list` do jobAll=$((jobAll+1)) PROJECTNAME=`echo "${JobIsx}"|awk -F"|" '{print $2}'` JOBNAME=`echo "${JobIsx}"|awk -F"|" '{printf $3}'` JIRANO=`echo "${JobIsx}"|awk -F"|" '{printf $4}'` if [ -f ${eximportpath}/${JIRANO}/${PROJECTNAME}.${JOBNAME}.isx ];then jobSucc=$((jobSucc+1)) else jobFail=$((jobFail+1)) fi done Log "LogFile: [${logfile}]" Log "Jira.no [$line] DS Job export over, all [${jobAll}], succ [${jobSucc}], fail [${jobFail}]!" Log "Job list: [${eximportpath}/${line}/EXPORT_${line}.list]" Log "#######################################################################" fi done elif [ "$keyword" == "IMPORT" ];then
Log "Remote excute 199.188.166.110 server import shell [/home/DSsbin/DSSHELL/EVA/ds_eximport.sh_V159]..." if [ $# -eq 2 ];then nohup ssh moiase@199.188.166.110 "sh /home/DSsbin/DSSHELL/EVA/ds_eximport.sh_V159 IMPORT ${file_name} ${logfile}" & elif [ $# -eq 3 ];then nohup ssh moiase@199.188.166.110 "sh /home/DSsbin/DSSHELL/EVA/ds_eximport.sh_V159 ${sysname} IMPORT ${file_name} ${logfile}" & fi
Log "Begin to import all the jobs of Jira.no in the jiraList [${list}], please wait..." for line in `cat ${list}|sed 's/ //g'` do jiraInfo=$line line=`echo $line|awk -F'|' '{print $1}'` if [ ! -f ${eximportpath}/${line}/EXPORT_${line}.list ];then Log "This Jira.no [$line] there is no job to import." continue else jobAll=`wc -l ${eximportpath}/${line}/EXPORT_${line}.list|awk -F' ' '{print $1}'|tr -d ' '` jobNum=0 jobFail=0 jobSucc=0 for jobIsx in `cat ${eximportpath}/${line}/EXPORT_${line}.list|sed 's/ //g'` do jobNum=$((jobNum+1)) PROJECTNAME=`echo "${jobIsx}"|awk -F"|" '{print $2}'` JOBNAME=`echo "${jobIsx}"|awk -F"|" '{printf $3}'` JIRANO=`echo "${jobIsx}"|awk -F"|" '{printf $4}'` if [ -f ${eximportpath}/${JIRANO}/${PROJECTNAME}.${JOBNAME}.isx ];then /home/dsinst/InformationServer/Clients/istools/cli/istool.sh import -domain $ipaddress:9446 -u $dsuser -p $dspassword -ar ${eximportpath}/${JIRANO}/${PROJECTNAME}.${JOBNAME}.isx -replace -ds '"'$hostname/$PROJECTNAME'"'>/dev/null 2>&1 checksql="SELECT count(*) FROM DATASTAGEX_DSJOBDEF WHERE locate(':', DSNAMESPACE_XMETA ) <> 0 and SHORTDESCRIPTION_XMETA='${JIRANO}' and substr(DSNAMESPACE_XMETA,locate(':', DSNAMESPACE_XMETA )+1 )='${PROJECTNAME}' and NAME_XMETA='${JOBNAME}'" checkres=`db2 connect to $dbname user $dbuser using $dbpass 1>/dev/null; db2 -nox "${checksql}"; db2 disconnect "$dbname">/dev/null`; if [ ${checkres} -eq 1 ];then jobSucc=$((jobSucc+1)) Log "${jobNum}/${jobAll}|[${hostname}]-${PROJECTNAME}|${JOBNAME}|${JIRANO} Import Succed!" else jobFail=$((jobFail+1)) Log "${jobNum}/${jobAll}|[${hostname}]-${PROJECTNAME}|${JOBNAME}|${JIRANO} Import Failed!" fi else jobFail=$((jobFail+1)) Log "${jobNum}/${jobAll}|[${hostname}]-${PROJECTNAME}|${JOBNAME}|${JIRANO} Import Failed, isx not exist!" fi done fi done Log "${hostname}|${line}:import over,all:${jobAll},succ:${jobSucc},fail:${jobFail}" Log "[${hostname}]LogFile: [${logfile}]" Log "#######################################################################" Log "Judge 199.188.166.110 shell over or not..." while true do ps_num=`ps -ef|grep "ds_eximport.sh_V159 IMPORT ${file_name}"|grep -v grep|wc -l` if [ ${ps_num} -ne 0 ];then Log "199.188.166.110 is running, wait 5 seconds..." sleep 5 else Log "199.188.166.110 run over!" echo "Imort log in 159:" grep "DSNUAT" ${logfile} break fi done jobAll=`expr $jobAll \* 2` jobSucc2=`grep "${hostname}|${line}:import over" ${logfile}|awk -F',' '{print $3}'|awk -F':' '{print $2}'` jobFail2=`grep "${hostname}|${line}:import over" ${logfile}|awk -F',' '{print $4}'|awk -F':' '{print $2}'` jobSucc=`expr $jobSucc + $jobSucc2` jobFail=`expr $jobFail + $jobFail2` Log "[${line}] import complete, all [${jobAll}], succ [${jobSucc}], fail [${jobFail}]]!" else Log "The first param must be export/EXPORT/import/IMPORT, please check..." exit -1 fi
|