Skip to content

Instantly share code, notes, and snippets.

@bretmcg
Last active December 19, 2015 00:38
Show Gist options
  • Save bretmcg/5869717 to your computer and use it in GitHub Desktop.
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
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
@bretmcg
Copy link
Author

bretmcg commented Oct 9, 2013

Jamie, thanks for the tip! I updated the gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment