Backup MySQL Database from Cron

Backup a database from cron. Add the following to the cron tab.

  1. date=`/bin/date "+\%Y-\%m-\%d-\%H-\%M-\%S"` ; cd /home/[USERNAME]/public_html; mysqldump -u [DATABASE USERNAME] -p[PASSWORD] [DATABASE NAME] > /home/[USERNAME]/backups/[DATABASE NAME]backup_$date.sql ; gzip /home/[USERNAME]/backups/[DATABASE NAME]backup_$date.sql

Enjoy this article?

Get my best content on Javascript, CSS, PHP & Git before anyone else and special bonuses.

Get started

Add new comment