Forked from erikfig/gist:12efe8739db0a3775448fa0d26df0eba
Created
May 1, 2017 04:17
-
-
Save Arkanius/15d9070b81ac23f98a2eb58a4635f477 to your computer and use it in GitHub Desktop.
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 | |
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