Created
November 24, 2014 12:07
-
-
Save adamjakab/e2177551c7fd65b02916 to your computer and use it in GitHub Desktop.
Recovery script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Author: Adam Jakab | |
# Description: | |
# 1) Shuts down critical services(httpd,mysql) | |
# 2) Attempts the recovery of damaged mysql database files | |
# 3) Restarts services | |
# | |
# Command to use to start/stop services | |
SERVICE_COMMAND="/sbin/service" | |
# Wait until we get a CPU load below this treshold after services have been stopped | |
SETTLED_DOWN_TRESHOLD=15 | |
DATABASE_FILES_FOLDER="/data_mount_1/database/www2" | |
# STOP SERVICES | |
${SERVICE_COMMAND} httpd stop | |
${SERVICE_COMMAND} mysqld stop | |
# WAIT FOR SYSTEM TO SETTLE DOWN | |
CPULOADAVG=9999 | |
while [ "${CPULOADAVG}" -ge "${SETTLED_DOWN_TRESHOLD}" ] | |
do | |
echo "CPU LOAD(${CPULOADAVG}) IS TOO HIGH - WAITING TO REACH ${SETTLED_DOWN_TRESHOLD}..." | |
CPULOADAVG_1=$(awk '{ print $1 }' /proc/loadavg) | |
CPULOADAVG=${CPULOADAVG_1%.*} | |
sleep 5 | |
done | |
# CHECK AND RECOVER MYSQL | |
/usr/bin/myisamchk --force --recover --update-state ${DATABASE_FILES_FOLDER}/*.MYI | |
# RESTART SERVICES | |
${SERVICE_COMMAND} mysqld start | |
${SERVICE_COMMAND} httpd start | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment