Script to backup your MySQL tables and send them to your email


Please shareShare on Facebook0Share on Google+1Tweet about this on Twitter0Share on LinkedIn0Share on Reddit0Digg thisShare on StumbleUpon0Share on VKBuffer this page

This is a nice script  to automatically backup your MySQL tables and send them to your email. 

{codecitation style=”brush: xml;”}


mysqldump -uroot -ppwd –opt database1 > /backupdb/db1.sql

mysqldump -uroot -ppwd –opt database2 > /backupdb/db2.sql

cd /sqldata/

tar -zcvf backupdb.tgz *.sql

cd /scripts/



-This script will make a backup or databse 1 and database 2 and will dump it to /backupdb directory
-Tar will compress the databases

-The perl script with send the backup to your email.

Perl script

{codecitation style=”brush: xml;”}

#!/usr/bin/perl -w

use MIME::Lite;

$msg = MIME::Lite->new(
From =>,

To    =>,

Subject => backupdb.tgz MySQL backup!,

Type => text/plain,

Data => “Here are the MySQL database backups.”);


Path =>”/backupdb/backupdb.tgz”,

Filename =>”backupdb.tgz”);


now run this job every night at 00:00 add job to crontab -e

0 0 * * * /myscripts/mysqlbackup

{loadposition user9}