2014-04-18 17:47:05 +02:00
|
|
|
#!/bin/bash
|
2015-11-05 16:57:24 +01:00
|
|
|
MYSQL_HOST=ENV_MYSQLHOST
|
|
|
|
MYSQL_USER=ENV_MYSQLUSER
|
|
|
|
MYSQL_PASS=ENV_MYSQLPASS
|
2015-09-07 15:24:16 +02:00
|
|
|
PATH_LOG=/var/lib/sphinxsearch/log
|
2015-09-07 11:21:42 +02:00
|
|
|
PATH_BIN=/usr/bin
|
|
|
|
PATH_SQL=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/sql
|
2014-04-18 17:47:05 +02:00
|
|
|
|
2015-09-23 15:02:19 +02:00
|
|
|
# Indexation déjà lancé
|
|
|
|
FILEINDEX=$PATH_LOG/ent-$(date '+%Y%m%d').idx
|
|
|
|
if [ -f "$FILEINDEX" ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2014-04-18 17:47:05 +02:00
|
|
|
# Is consolidated ?
|
|
|
|
output=$(mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS sdv1 < $PATH_SQL/consolidate-ent.sql)
|
|
|
|
idx='';
|
|
|
|
for line in "$output"; do
|
|
|
|
idx="$line";
|
|
|
|
done
|
|
|
|
# Suppression fin de ligne
|
|
|
|
idx=$(echo $idx|sed -e "s/^[idx ]*//g"||sed -e "s/[ ]*$//g")
|
|
|
|
|
|
|
|
# Lancement de l'indexation si la consolidation a eu lieu
|
|
|
|
if [ -n "$idx" ]; then
|
|
|
|
if [[ "$idx" > 0 ]]; then
|
|
|
|
|
2015-09-23 15:02:19 +02:00
|
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') === INDEXATION ENT" >> $PATH_LOG/indexer.log
|
2014-04-22 10:38:41 +02:00
|
|
|
|
2014-05-15 12:17:02 +02:00
|
|
|
# Nombre de lignes dans la table etablissements
|
|
|
|
output=$(mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS jo < $PATH_SQL/count-ent.sql)
|
|
|
|
nbC='';
|
|
|
|
for line in "$output"; do
|
|
|
|
nbC="$line"
|
|
|
|
done
|
|
|
|
# Suppression fin de ligne
|
|
|
|
nbC=$(echo $nbC|sed -e "s/^[nbC ]*//g"||sed -e "s/[ ]*$//g")
|
|
|
|
nbC=$(echo $(($nbC - 1000)))
|
2014-04-18 17:47:05 +02:00
|
|
|
|
2014-05-15 12:17:02 +02:00
|
|
|
# Nombre de lignes dans la table etablissements_tmp
|
|
|
|
output=$(mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS < $PATH_SQL/count-enttmp.sql)
|
|
|
|
nbT='';
|
|
|
|
for line in "$output"; do
|
|
|
|
nbT="$line"
|
|
|
|
done
|
|
|
|
# Suppression fin de ligne
|
|
|
|
nbT=$(echo $nbT|sed -e "s/^[nbT ]*//g"||sed -e "s/[ ]*$//g")
|
2014-04-18 17:47:05 +02:00
|
|
|
|
2014-05-15 12:17:02 +02:00
|
|
|
if [ -z "$nbC" ]; then
|
|
|
|
elif [ -z "$nbT" ]; then
|
|
|
|
elif [ "$nbT" -gt "$nbC" ]; then
|
|
|
|
|
2015-09-23 15:02:19 +02:00
|
|
|
# Create file to indicate indexing
|
|
|
|
rm -f $PATH_LOG/ent-*.idx
|
|
|
|
echo "START $(date '+%Y-%m-%d %H:%M:%S')" >> $FILEINDEX
|
|
|
|
|
2014-05-15 12:17:02 +02:00
|
|
|
# Enregistrement Debut Indexation
|
|
|
|
mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS sdv1 -e "UPDATE sphinx_idx SET indexingBegin=NOW() WHERE id=$idx" >> $PATH_LOG/indexer.log
|
|
|
|
|
|
|
|
# Sphinx rotate
|
|
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - Sphinx - Debut" >> $PATH_LOG/indexer.log
|
|
|
|
$PATH_BIN/indexer --config /etc/sphinxsearch/sphinx.conf --rotate ent ent_phx >> $PATH_LOG/indexer.log
|
|
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - Sphinx - Fin" >> $PATH_LOG/indexer.log
|
|
|
|
|
|
|
|
# Rotation des tables MySQL
|
|
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - Rotation Table - Debut" >> $PATH_LOG/indexer.log
|
|
|
|
mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS jo < $PATH_SQL/rotate-ent.sql >> $PATH_LOG/indexer.log
|
|
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - Rotation Table - Fin" >> $PATH_LOG/indexer.log
|
2014-04-18 17:47:05 +02:00
|
|
|
|
2014-05-15 12:17:02 +02:00
|
|
|
# Enregistrement Fin Indexation
|
|
|
|
mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS sdv1 -e "UPDATE sphinx_idx SET indexingEnd=NOW() WHERE id=$idx" >> $PATH_LOG/indexer.log
|
|
|
|
|
2015-09-23 15:02:19 +02:00
|
|
|
echo "FIN $(date '+%Y-%m-%d %H:%M:%S')" >> $FILEINDEX
|
|
|
|
|
2014-05-15 12:17:02 +02:00
|
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') === FIN INDEXATION ENT" >> $PATH_LOG/indexer.log
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
2014-04-18 17:47:05 +02:00
|
|
|
fi
|
|
|
|
fi
|