Last active
August 29, 2015 14:22
-
-
Save ansmirnov/86c069d9958f44542e77 to your computer and use it in GitHub Desktop.
BGBilling: удаление старых таблиц из базы данных
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 | |
# Andrey Smirnov <mail@ansmirnov.ru> | |
# http://blog.ansmirnov.ru/2015/06/05/bgbilling-clean-old-tables/ | |
MYSQL_USER='***' | |
MYSQL_PASS='***' | |
MYSQL_DB='bgbilling' | |
MODULE_ID=7 | |
START_DATE="201503" | |
TBL_NAME=npay_add_cost_detail_${MODULE_ID}_ | |
COL_NUMB=6 | |
echo "SHOW TABLES LIKE '${TBL_NAME}%';" | mysql -u${MYSQL_USER} -p${MYSQL_PASS} --skip-column-names ${MYSQL_DB} -A | | |
while read s | |
do | |
dt=`echo $s | cut -d'_' -f${COL_NUM}` | |
ddt=`echo $dt | sed 's/^0*//'` | |
if [[ $ddt -lt ${START_DATE} ]] | |
then | |
echo "DROP TABLE IF EXISTS ${TBL_NAME}${dt};" | |
fi | |
done | |
TBL_NAME=npay_detail_${MODULE_ID}_ | |
COL_NUMB=4 | |
echo "SHOW TABLES LIKE '${TBL_NAME}%';" | mysql -u${MYSQL_USER} -p${MYSQL_PASS} --skip-column-names ${MYSQL_DB} -A | | |
while read s | |
do | |
dt=`echo $s | cut -d'_' -f${COL_NUM}` | |
ddt=`echo $dt | sed 's/^0*//'` | |
if [[ $ddt -lt ${START_DATE} ]] | |
then | |
echo "DROP TABLE IF EXISTS ${TBL_NAME}${dt};" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment