Created
April 27, 2012 17:56
-
-
Save smizell/2511298 to your computer and use it in GitHub Desktop.
MySQL Backup Script (Bash)
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/sh | |
#backup all mysql databases | |
# list MySQL databases and dump each | |
DIR=/backup/mysql/ | |
DATESTAMP=$(date +%Y%m%d) | |
DB_USER=mysqlbackup | |
DB_PASS=kate@racers#45 | |
# remove old backups | |
find ${DIR} -type f -mtime +5 -exec rm -rf {} \; | |
DB_LIST=`mysql -u $DB_USER -p"$DB_PASS" -e'show databases;'` | |
DB_LIST=${DB_LIST##Database} | |
for DB in $DB_LIST; | |
do | |
FILENAME=${DIR}${DB}-${DATESTAMP}.sql.gz | |
mysqldump -u $DB_USER -p"$DB_PASS" --opt --flush-logs $DB | gzip > $FILENAME | |
done | |
mysqlcheck -u $DB_USER -p"$DB_PASS" --all-databases > /root/mysql_backups/check_errors-${DATESTAMP}.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment