Created
January 12, 2015 06:20
-
-
Save udienz/bf86cf701de5ac53a3de to your computer and use it in GitHub Desktop.
mysql backup entire database
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 | |
| # 2014, Mahyuddin Susanto <[email protected]> | |
| set -x | |
| SQLPASS=WHATEVER | |
| ARGS="-u root -h 202.154.57.61 -p$SQLPASS" | |
| SAVE="$HOME/mysql-backup/$(hostname -f)/$(date +%Y%m%d%H%M)" | |
| # remove database backup older that 90 days | |
| find $HOME/mysql-backup -mtime +90 | xargs rm -rf | |
| if ! [ -d $SAVE ]; then | |
| mkdir $SAVE -p | |
| fi | |
| cd $SAVE | |
| do_process () { | |
| mysqldump $ARGS $1 | gzip -9c > $SAVE/$1.sql.gz | |
| } | |
| echo 'show databases;' | mysql $ARGS | sed -e '/Database/d' -e '/information_schema/d' -e '/performance_schema/d' -e '/mysql/d' | while read data | |
| do | |
| do_process $data | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment