Created
May 3, 2019 21:42
-
-
Save asmoore82/172a9bc60fbd9e52b8bd30580fd272d8 to your computer and use it in GitHub Desktop.
BASH script for a 2 week rotation of MySQL backups with a standardized name - run as cronjob every 2 or 4 hours.
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 | |
#Copyright (c) 2019 Alamance-Burlington Schools, MIT License | |
cd "$HOME/backups" | |
usernm="usernm" | |
passwd="passwd" | |
table="dbtable" | |
week="$( date +%-V )" | |
day="$( date +%u )" | |
hour="$( date +%-H )" | |
#Use modulo 2 to flatten rotating week numbers | |
(( week = 2 - ( week % 2 ) )) | |
#Use integer division to floor to the even hour | |
(( hour = hour / 2 * 2 )) | |
mysqldump --quick --single-transaction -u"$usernm" -p"$passwd" "$table" | gzip > "$table.$week-$day-$hour.sql.gz" | |
#End of File |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment