optimize_mysql_tables.sh, optimize_mysql_tables-ND.sh: some design changes..

This commit is contained in:
Christoph 2023-08-09 11:09:11 +02:00
parent 30ca2c1a72
commit 5bdb646de7
2 changed files with 276 additions and 109 deletions

View File

@ -5,16 +5,21 @@ working_dir="$(dirname $(realpath $0))"
conf_file="${working_dir}/conf/mysql_credetials.conf"
tmp_log_file="$(mktemp)"
# - Lock directory exists, until the script ends. So
# - we can check, if a previos instanze is already running.
# -
LOCK_DIR="/tmp/${script_name%%.*}.LOCK"
log_file="${LOCK_DIR}/${script_name%%.*}.log"
# -------------
# - Variable settings
# - Variable (default) settings
# -------------
DEFAULT_MYSQL_CREDENTIAL_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
DEFAULT_LOG_FILE="/var/log/${script_name%%.*}.log"
VERBOSE=false
DEFAULT_to_addresses="argus@oopen.de"
# -------------
# --- Some functions
@ -64,7 +69,14 @@ usage() {
clean_up() {
# Perform program exit housekeeping
rm -f $tmp_log_file
if [[ ${1} -gt 0 ]] ; then
[[ -f "${log_file}" ]] && cp ${log_file} "/var/log/"
else
rm -f "/var/log/$(basename "${log_file}")"
fi
rm -rf "$LOCK_DIR"
blank_line
exit $1
}
@ -159,6 +171,12 @@ trim() {
echo -n "$var"
}
blank_line() {
if $terminal ; then
echo ""
fi
}
detect_mysql_version () {
_MYSQLD_VERSION="$(mysqld -V 2>/dev/null)"
@ -182,28 +200,16 @@ detect_mysql_version () {
}
trap clean_up SIGHUP SIGINT SIGTERM
# -------------
# - Is this script running on terminal ?
# -
# -------------
if [[ -t 1 ]] ; then
terminal=true
else
terminal=false
fi
mysql=`which mysql`
if [ -z "$mysql" ]; then
if [ -x "/usr/local/mysql/bin/mysql" ]; then
mysql=/usr/local/mysql/bin/mysql
else
fatal "No binary 'mysql' found!"
fi
fi
# -------------
# - Read Commandline Parameters
@ -230,27 +236,58 @@ if [[ "$(trim $*)" =~ " -h" ]] || [[ "$(trim $*)" =~ " --help" ]] ; then
fi
# -------------
# - Job is already running?
# -------------
## - If job already runs, stop execution..
## -
if mkdir "$LOCK_DIR" 2> /dev/null ; then
## - Remove lockdir when the script finishes, or when it receives a signal
trap "clean_up 1" SIGHUP SIGINT SIGTERM
else
datum=`date +"%d.%m.%Y"`
msg="[ Error ]: A previos instance of \"`basename $0`\" seems already be running.\n\tExiting now.."
echo ""
echo "[ Error ]: A previos instance of that script \"`basename $0`\" seems already be running."
echo ""
echo -e "\tExiting now.."
echo ""
for _to_address in $to_addresses ; do
echo -e "To:${_to_address}\n${content_type}\nSubject:Error cronjob `basename $0` -- $datum\n${msg}\n" \
| sendmail -F "Error `hostname -f`" -f $from_address $_to_address
done
exit 1
fi
# -------------
# - Load Settings from configuration file
# -------------
if [[ -n "$1 " ]] ; then
DATABASES="$1"
GIVEN_DATABASE="$1"
else
DATABASES=""
GIVEN_DATABASE=""
fi
if $terminal ; then
echo ""
fi
blank_line
echononl " Loading configuration settings from $(basename ${conf_file}).."
if [[ -f "$conf_file" ]]; then
source "$conf_file" > $tmp_log_file 2>&1
source "$conf_file" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
fatal "$(cat $tmp_log_file)"
fatal "$(cat $log_file)"
fi
else
echo_skipped
@ -260,7 +297,23 @@ else
fi
#[[ -z "$mysql_credential_args" ]] && mysql_credential_args="$DEFAULT_MYSQL_CREDENTIAL_ARGS"
[[ -z "${to_addresses}" ]] && to_addresses="${DEFAULT_to_addresses}"
# -------------
# - Some default values
# -------------
mysql=`which mysql`
if [ -z "$mysql" ]; then
if [ -x "/usr/local/mysql/bin/mysql" ]; then
mysql=/usr/local/mysql/bin/mysql
else
fatal "No binary 'mysql' found!"
fi
fi
if [[ -z "$mysql_credential_args" ]]; then
@ -298,31 +351,64 @@ if [[ -z "$mysql_credential_args" ]]; then
fi
fi
[[ -z "$log_file" ]] && log_file="$DEFAULT_LOG_FILE"
if [[ ${#mysql_credential_args_arr[@]} -eq 0 ]]; then
mysql_credential_args_arr[0]="default:$mysql_credential_args"
fi
# ==========
# - Begin Main Script
# ==========
# ----------
# - Headline
# ----------
if $terminal ; then
echo ""
echo -e "\033[1m----------\033[m"
echo -e "\033[32m\033[1mRunning script \033[m\033[1m$script_name\033[32m .. \033[m"
echo -e "\033[1m----------\033[m"
fi
declare -i length_table_name
declare -i number_blank_signd
declare -i index_i
for _val in ${mysql_credential_args_arr[@]} ; do
declare -i index_arr=0
while [[ $index_arr -lt ${#mysql_credential_args_arr[@]} ]] ; do
_all_success=true
IFS=':' read -a _val_arr <<< "${_val}"
IFS=':' read -a _val_arr <<< "${mysql_credential_args_arr[$index_arr]}"
mysql_version="${_val_arr[0]}"
mysql_credential_args="${_val_arr[1]}"
if $terminal ; then
echo ""
echo -e "[ \033[37m\033[1mMySQL $mysql_version\033[m ]: optimize (and repair) tables of databases at host '$(hostname -f)'."
fi
echo -e "[ MySQL $mysql_version ]: optimize (and repair) tables of databases at host '$(hostname -f)'." > $log_file
if [[ -z "$DATABASES" ]] ; then
DATABASES=`$mysql $mysql_credential_args -N -s -e "show databases"`
DATABASES="$($mysql $mysql_credential_args -N -s -e "show databases")"
found=false
if [[ -n "$GIVEN_DATABASE" ]] ; then
for db in $DATABASES ; do
if [[ "$db" = "$GIVEN_DATABASE" ]]; then
DATABASES="$GIVEN_DATABASE"
if $terminal ; then
echo ""
echo -e "[ \033[37m\033[1mMySQL $mysql_version\033[m ]: optimize (and repair) tables of database '$GIVEN_DATABASE'."
fi
echo -e "[ MySQL $mysql_version ]: optimize (and repair) tables of database '$GIVEN_DATABASE'." > $log_file
found=true
fi
done
if ! $found ; then
continue
fi
else
if $terminal ; then
echo ""
echo -e "[ \033[37m\033[1mMySQL $mysql_version\033[m ]: optimize (and repair) tables of databases at host '$(hostname -f)'."
fi
echo -e "[ MySQL $mysql_version ]: optimize (and repair) tables of databases at host '$(hostname -f)'." > $log_file
fi
length_table_name=0
@ -350,25 +436,25 @@ for _val in ${mysql_credential_args_arr[@]} ; do
if [[ -d "/var/www/html/projekte/nd/htdocs503" ]] ; then
mv /var/www/html/projekte/nd/htdocs /var/www/html/projekte/nd/htdocs.$_service_extension > $tmp_log_file 2>&1
mv /var/www/html/projekte/nd/htdocs /var/www/html/projekte/nd/htdocs.$_service_extension > $log_file 2>&1
if [[ $? -ne 0 ]]; then
error "Error while moving '/var/www/html/projekte/nd/htdocs'.\n$(cat $tmp_log_file)"
error "Error while moving '/var/www/html/projekte/nd/htdocs'.\n$(cat $log_file)"
else
_htdocs_nd_moved=true
fi
if $_htdocs_nd_moved ; then
ln -s htdocs503 /var/www/html/projekte/nd/htdocs > $tmp_log_file 2>&1
ln -s htdocs503 /var/www/html/projekte/nd/htdocs > $log_file 2>&1
if [[ $? -ne 0 ]]; then
error "Error while linking '/var/www/html/projekte/nd/htdocs' --> 'htdocs503'.\n$(cat $tmp_log_file)"
error "Error while linking '/var/www/html/projekte/nd/htdocs' --> 'htdocs503'.\n$(cat $log_file)"
else
_htdocs_nd_symlinked=true
fi
fi
/usr/local/apache2/bin/apachectl graceful > $tmp_log_file 2>&1
/usr/local/apache2/bin/apachectl graceful > $log_file 2>&1
if [[ $? -ne 0 ]]; then
error "Restarting Apache Webservice failed.\n$(cat $tmp_log_file)"
error "Restarting Apache Webservice failed.\n$(cat $log_file)"
fi
else
@ -384,23 +470,23 @@ for _val in ${mysql_credential_args_arr[@]} ; do
if [[ -d "/var/www/html/projekte/nd-archiv/htdocs503" ]] ; then
mv /var/www/html/projekte/nd-archiv/htdocs /var/www/html/projekte/nd-archiv/htdocs.$_service_extension > $tmp_log_file 2>&1
mv /var/www/html/projekte/nd-archiv/htdocs /var/www/html/projekte/nd-archiv/htdocs.$_service_extension > $log_file 2>&1
if [[ $? -ne 0 ]]; then
error "Error while moving '/var/www/html/projekte/nd-archiv/htdocs'.\n$(cat $tmp_log_file)"
error "Error while moving '/var/www/html/projekte/nd-archiv/htdocs'.\n$(cat $log_file)"
else
_htdocs_nd_archiv_moved=true
fi
ln -s htdocs503 /var/www/html/projekte/nd-archiv/htdocs > $tmp_log_file 2>&1
ln -s htdocs503 /var/www/html/projekte/nd-archiv/htdocs > $log_file 2>&1
if [[ $? -ne 0 ]]; then
error "Error while linking '/var/www/html/projekte/nd-archiv/htdocs' --> 'htdocs503'.\n$(cat $tmp_log_file)"
error "Error while linking '/var/www/html/projekte/nd-archiv/htdocs' --> 'htdocs503'.\n$(cat $log_file)"
else
_htdocs_nd_archiv_symlinked=true
fi
/usr/local/apache2/bin/apachectl graceful > $tmp_log_file 2>&1
/usr/local/apache2/bin/apachectl graceful > $log_file 2>&1
if [[ $? -ne 0 ]]; then
error "Restarting Apache Webservice failed.\n$(cat $tmp_log_file)"
error "Restarting Apache Webservice failed.\n$(cat $log_file)"
fi
else
@ -443,7 +529,7 @@ for _val in ${mysql_credential_args_arr[@]} ; do
echo -e " [$(date)] Optimize table '$table'" >> $log_file
length_table_name=${#table}
$mysql $mysql_credential_args $db -N -s -e "OPTIMIZE TABLE \`$table\`" > $tmp_log_file 2>&1
$mysql $mysql_credential_args $db -N -s -e "OPTIMIZE TABLE \`$table\`" > $log_file 2>&1
if [[ $? -ne 0 ]]; then
@ -454,27 +540,27 @@ for _val in ${mysql_credential_args_arr[@]} ; do
echo "" >> $log_file
echo " [$(date)] Repair table '$table'" >> $log_file
$mysql $mysql_credential_args $db -N -s -e "REPAIR TABLE \`$table\`" > $tmp_log_file 2>&1
$mysql $mysql_credential_args $db -N -s -e "REPAIR TABLE \`$table\`" > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_all_success=false
error "Repairing table '$table' failed.\n$(cat "$tmp_log_file")"
error "Repairing table '$table' failed.\n$(cat "$log_file")"
error_messages_arr+=("MySQL $mysql_version: Error while repairing table '${table}' of database '$db'.")
echo "" >> $log_file
echo -e " [$(date)] error: Repairing table '$table' failed of database \"$db\" failed..\n$(cat "$tmp_log_file")" >> $log_file
echo -e " [$(date)] error: Repairing table '$table' failed of database \"$db\" failed..\n$(cat "$log_file")" >> $log_file
echo "" >> $log_file
else
echo -e " [$(date)] Optimize table '$table'" >> $log_file
$mysql $mysql_credential_args $db -N -s -e "OPTIMIZE TABLE \`$table\`" > $tmp_log_file 2>&1
$mysql $mysql_credential_args $db -N -s -e "OPTIMIZE TABLE \`$table\`" > $log_file 2>&1
if [[ $? -ne 0 ]]; then
error "Reoptimizing table \"${table}\" of database \"$db\" failed.\n$(cat "$tmp_log_file")"
error "Reoptimizing table \"${table}\" of database \"$db\" failed.\n$(cat "$log_file")"
error_messages_arr+=("MySQL $mysql_version: Error while (re-)optimizing table '${table}' of database '$db'.")
echo "" >> $log_file
echo -e " [$(date)] error: Reoptimizing table \"${table}\" of database \"$db\" failed.\n$(cat "$tmp_log_file")" >> $log_file
echo -e " [$(date)] error: Reoptimizing table \"${table}\" of database \"$db\" failed.\n$(cat "$log_file")" >> $log_file
echo "" >> $log_file
else
info "Reoptimizing table \"${table}\" of database \"$db\" was successfully."
@ -492,43 +578,43 @@ for _val in ${mysql_credential_args_arr[@]} ; do
if [[ "$db" = "nd" ]]; then
if $_htdocs_nd_symlinked ; then
rm /var/www/html/projekte/nd/htdocs > $tmp_log_file 2>&1
rm /var/www/html/projekte/nd/htdocs > $log_file 2>&1
if [[ $? -ne 0 ]]; then
error "Error while removing symlink '/var/www/html/projekte/nd/htdocs'.\n$(cat $tmp_log_file)"
error "Error while removing symlink '/var/www/html/projekte/nd/htdocs'.\n$(cat $log_file)"
fi
fi
if $_htdocs_nd_moved ; then
mv /var/www/html/projekte/nd/htdocs.$_service_extension /var/www/html/projekte/nd/htdocs > $tmp_log_file 2>&1
mv /var/www/html/projekte/nd/htdocs.$_service_extension /var/www/html/projekte/nd/htdocs > $log_file 2>&1
if [[ $? -ne 0 ]]; then
error "Error while moving back '/var/www/html/projekte/nd/htdocs'.\n$(cat $tmp_log_file)"
error "Error while moving back '/var/www/html/projekte/nd/htdocs'.\n$(cat $log_file)"
fi
fi
/usr/local/apache2/bin/apachectl graceful > $tmp_log_file 2>&1
/usr/local/apache2/bin/apachectl graceful > $log_file 2>&1
if [[ $? -ne 0 ]]; then
error "Restarting Apache Webservice failed.\n$(cat $tmp_log_file)"
error "Restarting Apache Webservice failed.\n$(cat $log_file)"
fi
elif [[ "$db" = "nd_archiv" ]]; then
if $_htdocs_nd_archiv_symlinked ; then
rm /var/www/html/projekte/nd-archiv/htdocs > $tmp_log_file 2>&1
rm /var/www/html/projekte/nd-archiv/htdocs > $log_file 2>&1
if [[ $? -ne 0 ]]; then
error "Error while removing symlink '/var/www/html/projekte/nd-archiv/htdocs'.\n$(cat $tmp_log_file)"
error "Error while removing symlink '/var/www/html/projekte/nd-archiv/htdocs'.\n$(cat $log_file)"
fi
fi
if $_htdocs_nd_archiv_moved ; then
mv /var/www/html/projekte/nd-archiv/htdocs.$_service_extension /var/www/html/projekte/nd-archiv/htdocs > $tmp_log_file 2>&1
mv /var/www/html/projekte/nd-archiv/htdocs.$_service_extension /var/www/html/projekte/nd-archiv/htdocs > $log_file 2>&1
if [[ $? -ne 0 ]]; then
error "Error while moving back '/var/www/html/projekte/nd-archiv/htdocs'.\n$(cat $tmp_log_file)"
error "Error while moving back '/var/www/html/projekte/nd-archiv/htdocs'.\n$(cat $log_file)"
fi
fi
/usr/local/apache2/bin/apachectl graceful > $tmp_log_file 2>&1
/usr/local/apache2/bin/apachectl graceful > $log_file 2>&1
if [[ $? -ne 0 ]]; then
error "Restarting Apache Webservice failed.\n$(cat $tmp_log_file)"
error "Restarting Apache Webservice failed.\n$(cat $log_file)"
fi
fi
@ -545,14 +631,28 @@ for _val in ${mysql_credential_args_arr[@]} ; do
info_messages_arr+=("MySQL $mysql_version: The optimization of the MySQL tables of all databases were successful.")
fi
if $terminal ; then
echo ""
echo -e "[ \033[37m\033[1mMySQL $mysql_version\033[m ]: Finished optimizing MySQL databases at host $(hostname -f)."
echo ""
if [[ -n "$GIVEN_DATABASE" ]] ; then
if $terminal ; then
echo ""
echo -e "[ \033[37m\033[1mMySQL $mysql_version\033[m ]: Finished optimizing MySQL database '$GIVEN_DATABASE'."
echo ""
fi
echo "" >> $log_file
echo "[ MySQL $mysql_version ]: Finished optimizing MySQL database '$GIVEN_DATABASE'." >> $log_file
echo "" >> $log_file
else
if $terminal ; then
echo ""
echo -e "[ \033[37m\033[1mMySQL $mysql_version\033[m ]: Finished optimizing MySQL databases at host $(hostname -f)."
echo ""
fi
echo "" >> $log_file
echo "[ MySQL $mysql_version ]: Finished optimizing MySQL databases at host $(hostname -f)." >> $log_file
echo "" >> $log_file
fi
echo "" >> $log_file
echo "[ MySQL $mysql_version ]: Finished optimizing MySQL databases at host $(hostname -f)." >> $log_file
echo "" >> $log_file
(( index_arr++ ))
done
if [[ ${#info_messages_arr[@]} -gt 0 ]]; then

View File

@ -5,16 +5,21 @@ working_dir="$(dirname $(realpath $0))"
conf_file="${working_dir}/conf/mysql_credetials.conf"
tmp_log_file="$(mktemp)"
# - Lock directory exists, until the script ends. So
# - we can check, if a previos instanze is already running.
# -
LOCK_DIR="/tmp/${script_name%%.*}.LOCK"
log_file="${LOCK_DIR}/${script_name%%.*}.log"
# -------------
# - Variable settings
# - Variable (default) settings
# -------------
DEFAULT_MYSQL_CREDENTIAL_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
DEFAULT_LOG_FILE="/var/log/${script_name%%.*}.log"
VERBOSE=false
DEFAULT_to_addresses="argus@oopen.de"
# -------------
# --- Some functions
@ -64,7 +69,14 @@ usage() {
clean_up() {
# Perform program exit housekeeping
rm -f $tmp_log_file
if [[ ${1} -gt 0 ]] ; then
[[ -f "${log_file}" ]] && cp ${log_file} "/var/log/"
else
rm -f "/var/log/$(basename "${log_file}")"
fi
rm -rf "$LOCK_DIR"
blank_line
exit $1
}
@ -159,6 +171,12 @@ trim() {
echo -n "$var"
}
blank_line() {
if $terminal ; then
echo ""
fi
}
detect_mysql_version () {
_MYSQLD_VERSION="$(mysqld -V 2>/dev/null)"
@ -182,29 +200,16 @@ detect_mysql_version () {
}
trap clean_up SIGHUP SIGINT SIGTERM
# -------------
# - Is this script running on terminal ?
# -
# -------------
if [[ -t 1 ]] ; then
terminal=true
else
terminal=false
fi
mysql=`which mysql`
if [ -z "$mysql" ]; then
if [ -x "/usr/local/mysql/bin/mysql" ]; then
mysql=/usr/local/mysql/bin/mysql
else
fatal "No binary 'mysql' found!"
fi
fi
# -------------
# - Read Commandline Parameters
@ -231,6 +236,39 @@ if [[ "$(trim $*)" =~ " -h" ]] || [[ "$(trim $*)" =~ " --help" ]] ; then
fi
# -------------
# - Job is already running?
# -------------
## - If job already runs, stop execution..
## -
if mkdir "$LOCK_DIR" 2> /dev/null ; then
## - Remove lockdir when the script finishes, or when it receives a signal
trap "clean_up 1" SIGHUP SIGINT SIGTERM
else
datum=`date +"%d.%m.%Y"`
msg="[ Error ]: A previos instance of \"`basename $0`\" seems already be running.\n\tExiting now.."
echo ""
echo "[ Error ]: A previos instance of that script \"`basename $0`\" seems already be running."
echo ""
echo -e "\tExiting now.."
echo ""
for _to_address in $to_addresses ; do
echo -e "To:${_to_address}\n${content_type}\nSubject:Error cronjob `basename $0` -- $datum\n${msg}\n" \
| sendmail -F "Error `hostname -f`" -f $from_address $_to_address
done
exit 1
fi
# -------------
# - Load Settings from configuration file
# -------------
@ -241,17 +279,15 @@ else
GIVEN_DATABASE=""
fi
if $terminal ; then
echo ""
fi
blank_line
echononl " Loading configuration settings from $(basename ${conf_file}).."
if [[ -f "$conf_file" ]]; then
source "$conf_file" > $tmp_log_file 2>&1
source "$conf_file" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
fatal "$(cat $tmp_log_file)"
fatal "$(cat $log_file)"
fi
else
echo_skipped
@ -261,7 +297,23 @@ else
fi
#[[ -z "$mysql_credential_args" ]] && mysql_credential_args="$DEFAULT_MYSQL_CREDENTIAL_ARGS"
[[ -z "${to_addresses}" ]] && to_addresses="${DEFAULT_to_addresses}"
# -------------
# - Some default values
# -------------
mysql=`which mysql`
if [ -z "$mysql" ]; then
if [ -x "/usr/local/mysql/bin/mysql" ]; then
mysql=/usr/local/mysql/bin/mysql
else
fatal "No binary 'mysql' found!"
fi
fi
if [[ -z "$mysql_credential_args" ]]; then
@ -299,12 +351,27 @@ if [[ -z "$mysql_credential_args" ]]; then
fi
fi
[[ -z "$log_file" ]] && log_file="$DEFAULT_LOG_FILE"
if [[ ${#mysql_credential_args_arr[@]} -eq 0 ]]; then
mysql_credential_args_arr[0]="default:$mysql_credential_args"
fi
# ==========
# - Begin Main Script
# ==========
# ----------
# - Headline
# ----------
if $terminal ; then
echo ""
echo -e "\033[1m----------\033[m"
echo -e "\033[32m\033[1mRunning script \033[m\033[1m$script_name\033[32m .. \033[m"
echo -e "\033[1m----------\033[m"
fi
declare -i length_table_name
declare -i number_blank_signd
declare -i index_i
@ -392,7 +459,7 @@ while [[ $index_arr -lt ${#mysql_credential_args_arr[@]} ]] ; do
length_table_name=${#table}
$mysql $mysql_credential_args $db -N -s -e "OPTIMIZE TABLE \`$table\`" > $tmp_log_file 2>&1
$mysql $mysql_credential_args $db -N -s -e "OPTIMIZE TABLE \`$table\`" > $log_file 2>&1
if [[ $? -ne 0 ]]; then
@ -403,27 +470,27 @@ while [[ $index_arr -lt ${#mysql_credential_args_arr[@]} ]] ; do
echo "" >> $log_file
echo " [$(date)] Repair table '$table'" >> $log_file
$mysql $mysql_credential_args $db -N -s -e "REPAIR TABLE \`$table\`" > $tmp_log_file 2>&1
$mysql $mysql_credential_args $db -N -s -e "REPAIR TABLE \`$table\`" > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_all_success=false
error "Repairing table '$table' failed.\n$(cat "$tmp_log_file")"
error "Repairing table '$table' failed.\n$(cat "$log_file")"
error_messages_arr+=("MySQL $mysql_version: Error while repairing table '${table}' of database '$db'.")
echo "" >> $log_file
echo -e " [$(date)] error: Repairing table '$table' failed of database \"$db\" failed..\n$(cat "$tmp_log_file")" >> $log_file
echo -e " [$(date)] error: Repairing table '$table' failed of database \"$db\" failed..\n$(cat "$log_file")" >> $log_file
echo "" >> $log_file
else
echo -e " [$(date)] Optimize table '$table'" >> $log_file
$mysql $mysql_credential_args $db -N -s -e "OPTIMIZE TABLE \`$table\`" > $tmp_log_file 2>&1
$mysql $mysql_credential_args $db -N -s -e "OPTIMIZE TABLE \`$table\`" > $log_file 2>&1
if [[ $? -ne 0 ]]; then
error "Reoptimizing table \"${table}\" of database \"$db\" failed.\n$(cat "$tmp_log_file")"
error "Reoptimizing table \"${table}\" of database \"$db\" failed.\n$(cat "$log_file")"
error_messages_arr+=("MySQL $mysql_version: Error while (re-)optimizing table '${table}' of database '$db'.")
echo "" >> $log_file
echo -e " [$(date)] error: Reoptimizing table \"${table}\" of database \"$db\" failed.\n$(cat "$tmp_log_file")" >> $log_file
echo -e " [$(date)] error: Reoptimizing table \"${table}\" of database \"$db\" failed.\n$(cat "$log_file")" >> $log_file
echo "" >> $log_file
else
info "Reoptimizing table \"${table}\" of database \"$db\" was successfully."