Created
June 28, 2011 18:16
-
-
Save seanbehan/1051786 to your computer and use it in GitHub Desktop.
Nightly Mysql Backups
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 | |
# 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