Created
November 3, 2009 10:06
-
-
Save craigw/224927 to your computer and use it in GitHub Desktop.
Back up MySQL databases
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 | |
RETENTION=14 | |
BACKUP_DIRECTORY='/var/backups/mysql' | |
NICE='/usr/bin/nice -n 20' | |
MYSQLDUMP='/usr/bin/mysqldump' | |
BZIP='/bin/bzip2' | |
RM='/bin/rm' | |
PASSWORD=`cat /etc/mysql.passwd` # Make sure it's `chmod go-wrx`! | |
CWD=`/bin/pwd` | |
UMASK=`umask` | |
umask u=r,go-wrx | |
cd $BACKUP_DIRECTORY | |
SQLDUMP=`date +%Y%m%d`.sql | |
$NICE $MYSQLDUMP -u root --password='$PASSWORD' --all-databases > ./$SQLDUMP | |
$NICE $BZIP ${SQLDUMP} | |
FALLOFF="`date --date="$RETENTION days ago" +%Y%m%d`.sql" | |
[ -f $FALLOFF ] && $NICE $RM -f $FALLOFF | |
cd $CWD | |
umask $UMASK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment