Created
June 18, 2016 08:19
-
-
Save aamnah/8b5275fbd318f15ee8e4cbdd96b807c7 to your computer and use it in GitHub Desktop.
A simple script that dumps compressed mysql databases individually with a timestap
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 | |
| USER='BACKUPUSER' | |
| PASSWORD='PASSWORD' | |
| DIR='/backups/mysql' # don't use the trailing slash as it is used in the command | |
| # see `date --help` for format controls | |
| # %b = Jan | |
| # $H = hour (00..23) | |
| # %M = minute (00..59) | |
| # %T = time; same as %H:%M:%S | |
| TIMESTAMP=`date +%Y%b%d.%T` | |
| ExcludeDatabases='Database|information_schema|performance_schema|mysql|phpmyadmin' | |
| databases=`mysql -u ${USER} -p${PASSWORD} -Bse "SHOW DATABASES;" | egrep -v $ExcludeDatabases` | |
| for db in ${databases}; do | |
| echo "Dumping database: $db" | |
| mysqldump -u ${USER} -p${PASSWORD} --databases $db | gzip -9 > ${DIR}/${TIMESTAMP}.$db.sql.gz | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment