stanley-king 3 年之前
父节点
当前提交
fca54566b2
共有 1 个文件被更改,包括 10 次插入7 次删除
  1. 10 7
      util/purge.sh

+ 10 - 7
util/purge.sh

@@ -23,7 +23,7 @@ time_diff
 if [[ $cur_diff > ${min_diff} ]]; then
   echo 'can purge'
 else
-  echo '请等到一点后删除'
+  echo '请等到凌晨一点后删除'
   exit
 fi
 
@@ -39,6 +39,7 @@ function slave_running() {
     if [[ $a == 'Yes' &&  $b == 'Yes' ]];then
         return 1
     else
+      echo a,b
       return 0
     fi
 }
@@ -47,9 +48,11 @@ function slave_behind_match() {
     r=`mysql -uroot -pXTZ@shop@951688 --host=$host -e "show slave status\G; " | grep Seconds_Behind_Master:`
     ssecs=${r#*:}
     secs=`echo $ssecs | xargs`
+    echo Seconds_Behind_Master = $secs
 
     diff=`expr $cur_diff - 3600`
-    if [[ $secs < diff ]];then
+
+    if [[ $secs < $diff ]];then
         return 1
     else
       return 0
@@ -68,6 +71,7 @@ do
   running=$?
 
   if [[ $running == 0 ]];then
+    echo "slave ${host} has stoped"
     exit
   fi
 
@@ -75,20 +79,19 @@ do
   behind_match=$?
 
   if [[ $behind_match == 0 ]];then
+    echo "slave ${host} 延迟太大"
     exit
   fi
   echo $host can purge
 done
 
 today=$(date "+%Y-%m-%d")
+command="PURGE master LOGS BEFORE '${today} 00:00:00';"
+
 # shellcheck disable=SC2068
 for host in ${allhosts[@]}
 do
-  mysql -uroot -pXTZ@shop@951688 --host=$host -e "PURGE master LOGS BEFORE '$today 00:00:00'; "
+  mysql -uroot -pXTZ@shop@951688 --host=$host -e $command
 done
 
-#mysql -uroot -pXTZ@shop@951688 --host=172.26.80.8 -e "show slave status\G; " | grep Seconds_Behind_Master:
-#mysql -uroot -pXTZ@shop@951688 --host=172.26.80.10 -e "PURGE master LOGS BEFORE '2022-03-03 02:00:00';"
-#mysql -uroot -pXTZ@shop@951688 --host=172.26.80.10 -e "show master logs;"
-