Remove commented old code.
This commit is contained in:
parent
c4e6aafb33
commit
a0bf2ae89b
145
OLD/optimize_mysql_tables-ND.sh
Executable file
145
OLD/optimize_mysql_tables-ND.sh
Executable file
@ -0,0 +1,145 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [[ -t 1 ]] ; then
|
||||||
|
terminal=true
|
||||||
|
LOGGING=true
|
||||||
|
else
|
||||||
|
terminal=false
|
||||||
|
LOGGING=false
|
||||||
|
fi
|
||||||
|
|
||||||
|
mysql=`which mysql`
|
||||||
|
|
||||||
|
if [ -z "$mysql" ]; then
|
||||||
|
if [ -x "/usr/local/mysql/bin/mysql" ]; then
|
||||||
|
mysql=/usr/local/mysql/bin/mysql
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# - MySQL / MariaDB credentials
|
||||||
|
# -
|
||||||
|
# - Giving password on command line is insecure an sind mysql 5.5
|
||||||
|
# - you will get a warning doing so.
|
||||||
|
# -
|
||||||
|
# - Reading username/password fro file ist also possible, using MySQL/MariaDB
|
||||||
|
# - commandline parameter '--defaults-file'.
|
||||||
|
# -
|
||||||
|
# - Since Version 5.6, that method is considered as insecure.
|
||||||
|
# - To avoid giving the password on command line, we use an
|
||||||
|
# - encrypted option file
|
||||||
|
# -
|
||||||
|
# - Create (encrypted) option file:
|
||||||
|
# - $ mysql_config_editor set --login-path=local --socket=/var/run/mysqld/mysqld.sock --user=backup --password
|
||||||
|
# - $ Password:
|
||||||
|
# -
|
||||||
|
# - Use of option file:
|
||||||
|
# - $ mysql --login-path=local ...
|
||||||
|
# -
|
||||||
|
# - Example
|
||||||
|
# - mysql_credential_args="--login-path=local"
|
||||||
|
# - mysql_credential_args="--defaults-file=/etc/mysql/debian.cnf" (Debian default)
|
||||||
|
# - mysql_credential_args="--defaults-file=/usr/local/mysql/sys-maint.cnf"
|
||||||
|
# -
|
||||||
|
mysql_credential_args="--login-path=local"
|
||||||
|
|
||||||
|
|
||||||
|
if [ -n "$mysql_credential_args" ] ; then
|
||||||
|
DATABASES=`$mysql $mysql_credential_args -N -s -e "show databases"`
|
||||||
|
else
|
||||||
|
DATABASES=`$mysql -u$mysql_user -p$mysql_password -N -s -e "show databases"`
|
||||||
|
fi
|
||||||
|
|
||||||
|
_service_extension=PRODUCTION.$$
|
||||||
|
|
||||||
|
for db in $DATABASES ; do
|
||||||
|
|
||||||
|
if [ "$db" = "nd" ]; then
|
||||||
|
mv /var/www/html/projekte/nd/htdocs /var/www/html/projekte/nd/htdocs.$_service_extension
|
||||||
|
ln -s htdocs503 /var/www/html/projekte/nd/htdocs
|
||||||
|
/usr/local/apache2/bin/apachectl graceful
|
||||||
|
elif [ "$db" = "nd_archiv" ]; then
|
||||||
|
mv /var/www/html/projekte/nd-archiv/htdocs /var/www/html/projekte/nd-archiv/htdocs.$_service_extension
|
||||||
|
ln -s htdocs503 /var/www/html/projekte/nd-archiv/htdocs
|
||||||
|
/usr/local/apache2/bin/apachectl graceful
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ "$db" = "information_schema" ] && continue
|
||||||
|
[ "$db" = "performance_schema" ] && continue
|
||||||
|
[ "$db" = "mysql" ] && continue
|
||||||
|
|
||||||
|
if $LOGGING ;then
|
||||||
|
echo -e "\n[`date`] Optimize tables in database $db.."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$mysql_credential_args" ] ; then
|
||||||
|
TABLES=`$mysql $mysql_credential_args $db -N -s -e "show tables"`
|
||||||
|
else
|
||||||
|
TABLES=`$mysql -u$mysql_user -p$mysql_password $db -N -s -e "show tables"`
|
||||||
|
fi
|
||||||
|
|
||||||
|
for table in $TABLES ; do
|
||||||
|
|
||||||
|
if [ -n "$mysql_credential_args" ] ; then
|
||||||
|
if $LOGGING ;then
|
||||||
|
$mysql $mysql_credential_args $db -N -s -e "OPTIMIZE TABLE \`$table\`"
|
||||||
|
else
|
||||||
|
$mysql $mysql_credential_args $db -N -s -e "OPTIMIZE TABLE \`$table\`" > /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
$mysql -u$mysql_user -p$mysql_password $db -N -s -e "OPTIMIZE TABLE \`$table\`" > /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
if [ "$?" != "0" ]; then
|
||||||
|
echo -e "\t[ Warning ]: Optimizing table \"${table}\" of database \"$db\" failed. Trying to repair.."
|
||||||
|
if [ -n "$mysql_credential_args" ] ; then
|
||||||
|
if $LOGGING ;then
|
||||||
|
$mysql $mysql_credential_args $db -N -s -e "REPAIR TABLE \`$table\`"
|
||||||
|
else
|
||||||
|
$mysql $mysql_credential_args $db -N -s -e "REPAIR TABLE \`$table\`" > /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
if [ "$?" != "0" ]; then
|
||||||
|
echo -e "\t[ERROR]: Reparing table \"${table}\" of database \"$db\" failed !!"
|
||||||
|
else
|
||||||
|
if $LOGGING ;then
|
||||||
|
$mysql $mysql_credential_args $db -N -s -e "OPTIMIZE TABLE \`$table\`"
|
||||||
|
else
|
||||||
|
$mysql $mysql_credential_args $db -N -s -e "OPTIMIZE TABLE \`$table\`" > /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
[[ $? -gt 0 ]] && echo -e "\t[ERROR]: Optimizing table \"${table}\" of database \"$db\" failed !!"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if $LOGGING ;then
|
||||||
|
$mysql -u$mysql_user -p$mysql_password $db -N -s -e "REPAIR TABLE \`$table\`"
|
||||||
|
else
|
||||||
|
$mysql -u$mysql_user -p$mysql_password $db -N -s -e "REPAIR TABLE \`$table\`" > /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
if [ "$?" != "0" ]; then
|
||||||
|
echo -e "\t[ERROR]: Reparing table \"${table}\" of database \"$db\" failed !!"
|
||||||
|
else
|
||||||
|
if $LOGGING ;then
|
||||||
|
$mysql -u$mysql_user -p$mysql_password $db -N -s -e "OPTIMIZE TABLE \`$table\`"
|
||||||
|
else
|
||||||
|
$mysql -u$mysql_user -p$mysql_password $db -N -s -e "OPTIMIZE TABLE \`$table\`" > /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
[[ $? -gt 0 ]] && echo -e "\t[ERROR]: Optimizing table \"${table}\" of database \"$db\" failed !!"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
if $LOGGING ;then
|
||||||
|
echo -e "\n[`date`] End optimize tables in database $db.."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$db" = "nd" ]; then
|
||||||
|
rm -f /var/www/html/projekte/nd/htdocs
|
||||||
|
mv /var/www/html/projekte/nd/htdocs.$_service_extension /var/www/html/projekte/nd/htdocs
|
||||||
|
/usr/local/apache2/bin/apachectl graceful
|
||||||
|
elif [ "$db" = "nd_archiv" ]; then
|
||||||
|
rm -f /var/www/html/projekte/nd-archiv/htdocs
|
||||||
|
mv /var/www/html/projekte/nd-archiv/htdocs.$_service_extension /var/www/html/projekte/nd-archiv/htdocs
|
||||||
|
/usr/local/apache2/bin/apachectl graceful
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
exit 0
|
@ -195,11 +195,8 @@ for _val in ${mysql_credential_args_arr[@]} ; do
|
|||||||
TABLES=`$mysql $mysql_credential_args $db -N -s -e "show tables"`
|
TABLES=`$mysql $mysql_credential_args $db -N -s -e "show tables"`
|
||||||
|
|
||||||
for table in $TABLES ; do
|
for table in $TABLES ; do
|
||||||
|
|
||||||
|
|
||||||
if $terminal ; then
|
if $terminal ; then
|
||||||
#echo -en "\033[1G \033[32mOptimize table \033[1m$table\033[m \033[1G"
|
|
||||||
#echo -en "\033[1G \033[32mOptimize table \033[1m$table\033[m"
|
|
||||||
blank_signs=""
|
blank_signs=""
|
||||||
if [[ $length_table_name -gt ${#table} ]]; then
|
if [[ $length_table_name -gt ${#table} ]]; then
|
||||||
number_blank_sign=$(expr $length_table_name - ${#table})
|
number_blank_sign=$(expr $length_table_name - ${#table})
|
||||||
|
Loading…
Reference in New Issue
Block a user