Last active
December 19, 2015 00:38
-
-
Save bretmcg/5869717 to your computer and use it in GitHub Desktop.
MySQL Cron Backup: Can be placed in the /etc/cron.hourly folder (make sure file is executable) to take a MySQL backup and dump to a file
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
cd /home/bret/db_backups | |
DATE=$(date +"%Y%m%d%H%M") | |
# Export the MySQL database | |
mysqldump -u backup_user -p secret_password --all-databases | gzip --rsyncable > backup_db_$DATE.sql.gz | |
# Keep at most 30 files | |
ls -t | sed -e '1,30d' | xargs -d '\n' rm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Jamie, thanks for the tip! I updated the gist.