Automatically Email MySQL Database Backup

If you are in a shared hosting environment where you are responsible for your own database backups, this is a convenient way to have the server generate a backup file of all of your MySQL databases, compress the file, and email it to the specified address. I’ve added this to the local crontab so that it runs on a regular schedule. In order for it to work, you should have a MySQL user account created with the appropriate privileges in order to access your database.

mysqldump -ce
  | gzip
  | uuencode dbbackup.gz
  | /usr/sbin/sendmail my_email_address

Leave a Comment