Created
September 22, 2015 15:35
-
-
Save annttu/316a08062662e1fd6ed0 to your computer and use it in GitHub Desktop.
mysql backup script
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 | |
| # Path to directory where backups should be stored. | |
| DIR="path/to/mysql_backup" | |
| mysqldump -A |gzip -c - > ${DIR}/`date +%Y-%m-%d`.sql.gz | |
| if [ "`date +%d`" == "01" ] | |
| then | |
| cp ${DIR}/`date +%Y-%m-%d`.sql.gz ${DIR}/month_`date +%Y-%m`.sql.gz | |
| touch ${DIR}/month_*.sql.gz | |
| fi | |
| find ${DIR}/2[0-9][0-9][0-9]*.sql.gz -mtime +32 -exec rm {} + | |
| find ${DIR}/month_*.sql.gz -mtime +180 -exec rm {} + |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment