Want more features on Pastebin? Sign Up, it's FREE!
Guest

burtonator

By: a guest on Apr 17th, 2009  |  syntax: Bash  |  size: 1.43 KB  |  views: 1,234  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/sh
  2.  
  3. pct=0
  4.  
  5.  
  6. # Call the given function, require that it complete successfully, and then return the status.
  7. #
  8. rcall() {
  9.  
  10.     echo -n '+'
  11.     echo -n $@
  12.  
  13.     $@
  14.  
  15.     status=$?
  16.  
  17.     if [ $status != 0 ]; then
  18.         echo " FAILED"
  19.         exit $status
  20.     fi
  21.  
  22.     echo
  23.  
  24.     return $status
  25.  
  26. }
  27.  
  28.  
  29. if [ "$1" = "--allow_dirty_buffers" ]; then
  30.     pct=90
  31. fi
  32.  
  33.  
  34. innodb_status=$(echo "SHOW ENGINES;" | rcall mysql --user=admin --pass=p3ac3 | grep InnoDB | cut -f2)
  35.  
  36. if [ "$innodb_status" = "DISABLED" ]; then
  37.     echo "The Innodb storage engine is disabled"
  38.     exit 0
  39. fi
  40.  
  41.  
  42. # tell mysql that we need to shutdown so start flushing dirty pages to disk.
  43. # Normally InnoDB does this by itself but only when port 3306 is closed which
  44. # prevents us from monitoring the box.
  45.  
  46. rcall mysql --user=admin --pass=p3ac3 <<EOF
  47.  
  48. SLAVE STOP;
  49. SET GLOBAL innodb_max_dirty_pages_pct=$pct;
  50.  
  51. EOF
  52.  
  53. # ..... how wait until the dirty buffer size goes down to zero.
  54.  
  55. IFS=
  56. if [ "$1" = "--progress" ]; then
  57.  
  58. echo "Innodb dirty pages:"
  59.  
  60.     while [ true ]; do
  61.        
  62.         status=$(echo 'SHOW INNODB STATUS\G' | rcall mysql --user=admin --pass=p3ac3)
  63.  
  64.         modified_db_pages=$(echo $status | grep -E '^Modified db pages' | grep -Eo '[0-9]+$')
  65.  
  66.         if [ "$modified_db_pages" = "0" ]; then
  67.             echo
  68.             break
  69.         fi
  70.  
  71.         echo -ne "$modified_db_pages\r";
  72.         sleep 1
  73.     done
  74.  
  75. fi
clone this paste RAW Paste Data