参考:https://www.cnblogs.com/lixigang/articles/4849527.html
1 #!/bin/bash 2 ssb="1" 3 password=mysql 4 database=SAJT_DZFP_PT 5 mode=`echo $1 | tr 'A-Z' 'a-z'` 6 echo "SELECT MODE : "$mode 7 8 modes="document 9 document_item 10 invoice 11 invoice_item" 12 13 flag=0 14 for m in $modes 15 do 16 if [ "${m}" != "${mode}" ];then 17 continue 18 else 19 flag=1 20 break 21 fi 22 done 23 24 if [ "$flag" != "1" ]; then 25 echo "WARNNING : ONLY document/document_item/invoice/invoice_item MODE CAN BE SELECTED !" 26 exit 27 fi 28 29 TS=`date +'%Y-%m-%d %H:%M:%S'` 30 for i in $ssb 31 do 32 echo "${mode} ssb $i" 33 tmpFile=data/${mode}/${i}.sql 34 echo "mysqldump -uroot -p ${database} tbl_ec_${mode} --single-transaction --where="fpqqlsh in (select fpqqlsh from temp where ssb='$i')" > ${tmpFile}" > tmp/a.sh 35 echo " -- START --" 36 ts=`date +'%Y-%m-%d %H:%M:%S'` 37 date 38 ./pwd.sh tmp/a.sh ${password} 39 src=tbl_ec_${mode} 40 dest=${src}_${i} 41 sed -i "s/${src}/${dest}/g" ${tmpFile} 42 sed -ri '1,150s/ENGINE=InnoDB DEFAULT CHARSET=utf8|ENGINE=InnoDB DEFAULT CHARSET=utf8 MAX_ROWS=1000000000/ENGINE=InnoDB DEFAULT CHARSET=utf8 PARTITION BY KEY(FPQQLSH) PARTITIONS 11/g' ${tmpFile} 43 echo " -- END --" 44 date 45 te=`date +'%Y-%m-%d %H:%M:%S'` 46 ts=$(date --date="${ts}" +%s) 47 te=$(date --date="${te}" +%s) 48 echo ${mode} " -- ssb:"${i}" SPENDS "$((te-ts))" Sec" 49 done 50 TE=`date +'%Y-%m-%d %H:%M:%S'` 51 TS=$(date --date="${TS}" +%s) 52 TE=$(date --date="${TE}" +%s) 53 echo ${mode}" ALL SPENDS "$((TE-TS))" Sec"