Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lira/2c9949a84c504965da74ea28ec479bee to your computer and use it in GitHub Desktop.
Save lira/2c9949a84c504965da74ea28ec479bee to your computer and use it in GitHub Desktop.
#!/bin/bash
MYSQL_USER="root"
MYSQL_PASS="1234"
MAIL="[email protected]"
REMOTE_REPOSITORY=https://bitbucket.org/username/backup-banco
DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$DIRECTORY"
COMMIT_COUNT=`git rev-list HEAD --count`
COMMIT_COUNT=$(($COMMIT_COUNT+1))
echo 'INICIANDO BACKUP'
echo 'Baixando bancos de dados'
for I in $(mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'show databases where `Database` not in("information_schema")');
do
if [ "$I" != 'Database' ]
then
echo "- $I"
mysqldump -u$MYSQL_USER -p$MYSQL_PASS --complete-insert "$I" > "$I".sql;
#gzip "$I".sql -f
fi
done
echo 'Empacotando alterações'
git add .
git commit -m "Backup $COMMIT_COUNT"
echo "Enviando para o repositório remoto"
git push -u origin master
echo "Avisando administrador"
mail -s "Backup do banco completo" $MAIL <<< "Para acessar o arquivo remoto vá até $REMOTE_REPOSITORY"
echo "BACKUP FINALIZADO"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment