Skip to content

Instantly share code, notes, and snippets.

@ajessup
Created February 13, 2012 06:37
Show Gist options
  • Save ajessup/1814302 to your computer and use it in GitHub Desktop.
Save ajessup/1814302 to your computer and use it in GitHub Desktop.
Quick and dirty shell script designed to take rolling mysqldumps from a server
#! /bin/bash
#
# Quick and dirty shell script designed to take rolling mysqldumps from a
# mysql replica server
#
MYSQL_USERNAME = '<<username>>'
MYSQL_PASSWORD = '<<password>>'
DATE_OF_DUMP=`date +%F`
BASE_DUMP_DIR=/backups
DBS=(paypygg_www)
BACKUP_FILENAME=$BASE_DUMP_DIR/mysql.backup.$DATE_OF_DUMP.tar.bz2
cd $BASE_DUMP_DIR
if [ -e $DATE_OF_DUMP ]
then
rm -rf $DATE_OF_DUMP
fi
mkdir $DATE_OF_DUMP
for DB in ${DBS[@]} ; do
mysqldump -u $MYSQL_USERNAME -p$MYSQL_PASSWORD $DB > $DATE_OF_DUMP/$DB.$DATE_OF_DUMP.sql
done
tar cjf $BACKUP_FILENAME $DATE_OF_DUMP
rm -rf $DATE_OF_DUMP
find $BASE_DUMP_DIR -type f -name "mysql.backup.*.tar.bz2" -mtime +2 | xargs rm -rf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment