Last active
October 30, 2020 08:37
-
-
Save AprendendoLinux/5e88ac3a9bfc4c33ae653191f55f2f6e to your computer and use it in GitHub Desktop.
MySQL Restore
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 | |
################################################### | |
## CREDENCIAIS DO MYSQL NO ARQUIVO /root/.my.cnf ## | |
## ## | |
## [mysql] ## | |
## user=root ## | |
## password='M!nh@S3nh@' ## | |
## host='ip-ou-dns-do-servidor' ## | |
## ## | |
## [mysqldump] ## | |
## user=root ## | |
## password='M!nh@S3nh@' ## | |
## host='ip-ou-dns-do-servidor' ## | |
## ## | |
################################################### | |
DATA=`date +%Y/%m/%d` | |
BACKUP="/var/backups/mysql/$DATA" | |
gzip -d $BACKUP/*.gz | |
databases=`ls $BACKUP/ | cut -d'.' -f1` | |
for db in $databases; do | |
mysql -e "DROP DATABASE $db" 2> /dev/null | |
mysql -e "CREATE DATABASE $db" 2> /dev/null | |
mysql $db < $BACKUP/$db.sql | |
done | |
mysql -e "FLUSH PRIVILEGES" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment