Skip to content

Instantly share code, notes, and snippets.

@annttu
Created September 22, 2015 15:35
Show Gist options
  • Select an option

  • Save annttu/316a08062662e1fd6ed0 to your computer and use it in GitHub Desktop.

Select an option

Save annttu/316a08062662e1fd6ed0 to your computer and use it in GitHub Desktop.
mysql backup script
#!/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