Created
February 20, 2014 13:55
-
-
Save josephdpurcell/9114079 to your computer and use it in GitHub Desktop.
Rotating Daily and Weekly MySQL Dump Cron
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
# mysqlbup.cron by josephdpurcell | |
# | |
# This cron will export all databases every day at 4am. Those exports are | |
# automatically rotating from servername.com.day0 to servername.com.day6 so you | |
# always have a bup of the last 7 days of backups. | |
# | |
# Also, this cron will export all databases every week for the last 4 weeks at | |
# 2am on Sunday. Those exports are automatically rotating from | |
# servername.com.week0 to servername.com.week3 so you always have a bup of the | |
# last 4 weeks of backups. | |
# | |
# rotating past 7 days mysql bup | |
0 4 * * * mysqldump -u mysqluser -pmysqlpasswd --all-databases > /opt/local/bup/sql/server-name.com.day$(date +\%w).sql | |
# rotating past 4 weeks mysql bup | |
0 2 * * 0 mysqldump -u mysqluser -pmysqlpasswd --all-databases > /opt/local/bup/sql/server-name.com.week$(expr $(date +\%U) \% 4).sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! I've modified it a little, trying to setup:
Unfortunately, for some reason my weekly job keeps running on other days as well, I don't know why, maybe my timezone or regional settings :P Otherwise, general idea should be ok.
Hope it helps someone! And if you know where I've made a mistake let me know ;D