Skip to content

Instantly share code, notes, and snippets.

@jmaddington
Created April 14, 2014 03:02
Show Gist options
  • Save jmaddington/10612871 to your computer and use it in GitHub Desktop.
Save jmaddington/10612871 to your computer and use it in GitHub Desktop.
MySQL Dumps
#Change lines 6 & 10 to where you want to store your backups
echo 'show databases;'|/usr/bin/mysql --skip-column-names|while read -r db
do
fn=`date +%Y%m%d%H%S`
nice /usr/bin/mysqldump $db| bzip2 -9 > /root/backups/mysql/hourly/$fn.$db.sql.bz2
done
#Change +3 to however many days you want to keep backups
find /root/backups/mysql/hourly/ -ctime +3 -exec rm "{}" \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment