wdl 2 yıl önce
işleme
61ac71b6cb
1 değiştirilmiş dosya ile 78 ekleme ve 0 silme
  1. 78 0
      task_day/clean_mysql.sh

+ 78 - 0
task_day/clean_mysql.sh

@@ -0,0 +1,78 @@
+#! /bin/bash
+
+. /mnt/datadisk0/saga/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=saga_dev
+
+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