Skip to content

Instantly share code, notes, and snippets.

@smizell
Created April 27, 2012 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smizell/2511298 to your computer and use it in GitHub Desktop.
Save smizell/2511298 to your computer and use it in GitHub Desktop.
MySQL Backup Script (Bash)
#!/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