Skip to content

Instantly share code, notes, and snippets.

@erikfig
Created April 28, 2017 12:42
Show Gist options
  • Save erikfig/12efe8739db0a3775448fa0d26df0eba to your computer and use it in GitHub Desktop.
Save erikfig/12efe8739db0a3775448fa0d26df0eba 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