Shishant
Shishant

Reputation: 9294

Automatic MySQL Database backup and email through cPanel cron

Can anybody help how to setup a automatic backup of mysql database and then emailing it to me daily?

Thank You.

Upvotes: 4

Views: 18724

Answers (3)

abkrim
abkrim

Reputation: 3692

Simple. Not need more.

#!/bin/sh
# Must be installed mutt on your box
mydate=$(date +"%Y%m%d%H%M")
host=$(hostname)
databases='' #'database1  database2 databaseN'

mysqldump --opt --all-databases > /tmp/$host.$mydate.sql
# if not all mysql databases mysqldump --opt $databases > /tmp/$host.$mydate.sql
gzip --best /tmp/mysql02.$mydate.sql
echo "Backup MySQL" | mutt -a /tmp/$host.$mydate.sql.gz -s "Backup MySQL $mydate" -- [email protected]

Upvotes: 0

Paul G.
Paul G.

Reputation: 17

If you're looking to automate your MySQL database backups, say with a cron job, and you host your databases with CPanel web hosting, then there's a PHP script you can use.

You can pick it up here: http://www.hostliketoast.com/2011/10/cpanel-hosting-full-database-backup-script-free-download/

Upvotes: 0

northpole
northpole

Reputation: 10346

AutoMySQLBackup gets great reviews. I have not used it but it seems to do exactly what you are looking for. Also, here is another link with different ways to backup, including emailing.

Upvotes: 3

Related Questions