Skip to content

Instantly share code, notes, and snippets.

@seanbehan
Created June 28, 2011 18:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanbehan/1051786 to your computer and use it in GitHub Desktop.
Save seanbehan/1051786 to your computer and use it in GitHub Desktop.
Nightly Mysql Backups
#!/bin/bash
# installed as root in /root/backups/mysql
# needs to be installed via cron
# will run at 3:10 am every morning
#
# crontab -e
# 10 3 * * * /root/mysql_backups.sh > /backups/status.log
# change DB_USER and DB_PASSWD as per configuration
export DB_BACKUP="/root/backups/mysql"
export DB_USER="root"
export DB_PASSWD="******************"
echo ""
echo "Backup and rotate all mysql databases"
echo "--------------------------"
rm -rf $DB_BACKUP/04
mv $DB_BACKUP/03 $DB_BACKUP/04
mv $DB_BACKUP/02 $DB_BACKUP/03
mv $DB_BACKUP/01 $DB_BACKUP/02
mkdir $DB_BACKUP/01
echo "* Creating backup..."
mysqldump --user=$DB_USER --password=$DB_PASSWD --all-databases | bzip2 > $DB_BACKUP/01/mysql-`date +%Y-%m-%d`.bz2
echo "----------------------"
echo "Done"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment