MySQL scheduled backups on Linux via CRON

The following commands can be added via crontab.  As-is, they will dump all MySQL databases to a GZIPped batch file every 2 hours and delete old dumps after 10 days.

Substitute the correct values for USER (usually "root") and PASSWORD and LOCATION.

0 0,2,4,6,8,10,12,14,16,18,20,22 * * * mysqldump -uUSER -pPASSWORD -A | gzip > /LOCATION/$(date +\%Y_\%m_\%d-\%T).sql.gz
0 1 * * *  find /LOCATION -name "*.gz" -mtime +10 -delete
Was this answer helpful? 0 Users Found This Useful (264 Votes)