123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #! /bin/bash
- . /usr/local/service/sagaApps/bi_saga/dwh_saga/task_day/config.sh
- if [ -n "$2" ] ;then
- do_date=$2
- else
- echo "====没有输入数据的日期,取当前时间的前一天===="
- do_date=$(date -d yesterday +"%Y-%m-%d")
- fi
- echo "$do_date"
- host=$MYSQL_HOST
- username=$MYSQL_USER
- password=$MYSQL_PASSWORD
- database=dwh_saga
- del_energy_15_min="truncate table energy_15_min;"
- del_co2_15_min="truncate table co2_15_min;"
- del_pm25_15_min="truncate table pm25_15_min;"
- del_hcho_15_min="truncate table hcho_15_min;"
- del_temperature_15_min="truncate table temperature_15_min;"
- del_humidity_15_min="truncate table humidity_15_min;"
- ## 历史数据一次性导入后,需要删除 mysql 中的冗余数据
- clean_energy_15(){
- mysql -h"${host}" -P3306 -u"${username}" -p"${password}" ${database} -e "${del_energy_15_min}"
- }
- clean_co2_15_min(){
- mysql -h"${host}" -P3306 -u"${username}" -p"${password}" ${database} -e "${del_co2_15_min}"
- }
- clean_pm25_15_min(){
- mysql -h"${host}" -P3306 -u"${username}" -p"${password}" ${database} -e "${del_pm25_15_min}"
- }
- clean_hcho_15_min(){
- mysql -h"${host}" -P3306 -u"${username}" -p"${password}" ${database} -e "${del_hcho_15_min}"
- }
- clean_temperature_15_min(){
- mysql -h"${host}" -P3306 -u"${username}" -p"${password}" ${database} -e "${del_temperature_15_min}"
- }
- clean_humidity_15_min(){
- mysql -h"${host}" -P3306 -u"${username}" -p"${password}" ${database} -e "${del_humidity_15_min}"
- }
- case $1 in
- "all")
- clean_energy_15
- clean_co2_15_min
- clean_pm25_15_min
- clean_hcho_15_min
- clean_temperature_15_min
- clean_humidity_15_min
- ;;
- "clean_energy_15")
- clean_energy_15
- ;;
- "clean_co2_15_min")
- clean_co2_15_min
- ;;
- "clean_pm25_15_min")
- clean_pm25_15_min
- ;;
- "clean_hcho_15_min")
- clean_hcho_15_min
- ;;
- "clean_temperature_15_min")
- clean_temperature_15_min
- ;;
- "clean_humidity_15_min")
- clean_humidity_15_min
- ;;
- esac
|