Created
June 1, 2011 10:43
-
-
Save bkenny/1002100 to your computer and use it in GitHub Desktop.
MySQL Backup Script
This file contains 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 | |
BACKUP="/backups/db" | |
DATE=`date +"%Y-%m-%d"` | |
WEEKAGO=`date --date='week ago' +"%Y-%m-%d"` | |
DAY=`date +"%a"` | |
XWEEKSAGO=`date --date='5 weeks ago' +"%Y-%m-%d"` | |
# Day on which the weekly backup is kept. Should be the 3 char abbreviation | |
WEEKLY="Sun"; | |
DIR="${BACKUP}/${DATE}/" | |
WEEKLYDIR="${BACKUP}/weekly/" | |
if [ ! -d $DIR ]; | |
then | |
mkdir -p $DIR | |
fi | |
if [ ! -d $WEEKLYDIR ] | |
then | |
mkdir -p $WEEKLYDIR | |
fi | |
for DATABASE in `echo "SHOW DATABASES" | mysql -p$password -u $user | grep -v ^Database` | |
do | |
echo -n Backing up $DATABASE ..... | |
mysqldump -p$password -u $user $DATABASE | gzip -c > ${DIR}/${DATABASE}.sql.gz 2>/dev/null | |
echo Done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment