My first cron job

I needed a way to backup MySQL databases every night. So, I made my first cron job. Ubuntu has a site that explains cron, crontab, and anacron in simple enough terms that even I could understand. I ended up using anacron. That means I made a script file and placed it in /etc/cron.daily. After a few false starts I came up with the following script that works well enough for me:

#!/bin/sh
/usr/bin/mysqldump -u root -pMYPASSWORD –all-databases | gzip > /MY/BACKUP/DIR/all_data_backup_`date +'%Y-%m-%d-%H%M'`.sql.gz

After I made the script I made it executable…

chmod 755 myscript

My script runs every morning at 6-ish and creates a uniquely named gzip containing all my databases.

Leave a Reply

Your email address will not be published.