Script Importação MySQL

#!/bin/bash
# Script importacao MySQL

MYSQL_USER='root'
MYSQL_PASSWD='MysqlPasswordHere'
DIR_LOCAL_BACKUP_SQL=/tmp/backup_mysql

echo -e "\n[ $( date '+%d/%m/%Y %H:%M' ) ] INICIO EXECUCAO SCRIPT DE IMPORTACAO " | tee -a /var/log/$( basename $0 ).log

for i in $( ls $DIR_LOCAL_BACKUP_SQL/*.sql ); do

# Ex de nome de arquivo: intranet-2017-03-15-diario.sql
  DB=$( basename $( echo $i | awk -F- '{print $1}') )

  if [ $DB != 'mysql' ] && [ $DB != 'information_schema' ] && [ $DB != 'performance_schema' ]; then

    echo "inicio importacao $DB [ $( date '+%d/%m/%Y %H:%M' ) ]" | tee -a /var/log/$( basename $0 ).log
    mysql -u $MYSQL_USER -p$MYSQL_PASSWD -e "DROP DATABASE $DB"
    mysql -u $MYSQL_USER -p$MYSQL_PASSWD < $i
    echo "fim importacao $DB [ $( date '+%d/%m/%Y %H:%M' ) ]" | tee -a /var/log/$( basename $0 ).log
  fi

done

echo "[ $( date '+%d/%m/%Y %H:%M' ) ] FIM EXECUCAO SCRIPT DE IMPORTACAO " | tee -a /var/log/$( basename $0 ).log
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s