Last active
August 29, 2015 14:15
-
-
Save andypotanin/b51696ef4716c55bd6d5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| ## export DB_USER=root | |
| ## export DB_PASSWORD=ktikfyefkieyknwi | |
| ## export DB_HOST=colossus.wpcloud.io | |
| ## exportDatabases root ktikfyefkieyknwi colossus.wpcloud.io | |
| function exportDatabases { | |
| export _databases=`mysql --user=${1} --pasword=${2} --host=${3} -e "SHOW DATABASES;" | tr -d "| " | grep -v Database` | |
| for db in $_databases; do | |
| if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then | |
| export _file="${db}-$(date +%Y-%m-%d-%H).sql"; | |
| if [ ! -f ${_file} ]; then | |
| echo " - Exporting database: ${db} to ${_file}" | |
| #mysqldump --host=$DB_HOST -u $USER -p$PASSWORD --databases $db > ${_file} | |
| fi; | |
| fi | |
| done | |
| echo " - Done exporting, starting batch GZIP." | |
| # gzip $(hostname)-*.sql | |
| } |
This file contains hidden or 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
| ## Export | |
| mysqldump -u root -p mysql > $(hostname)-mysql.sql | |
| gzip $(hostname)-mysql.sql | |
| ## Import | |
| gunzip $(hostname)-mysql.sql | |
| mysql -uroot -p mysql < $(hostname)-mysql.sql | |
| mysql -uroot -p -c="FLUSH PRIVILEGES" | |
This file contains hidden or 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
| # http://stackoverflow.com/questions/597732/backup-mysql-users | |
| ## Export User to DB grants | |
| mysql -BNe "select concat('\'',user,'\'@\'',host,'\'') from mysql.user where user != 'root'" | \ | |
| while read uh; do mysql -BNe "show grants for $uh" | sed 's/$/;/; s/\\\\/\\/g'; done > $(hostname)-grants.sql | |
| gzip $(hostname)-grants.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment