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

by
Share this Article: Facebook15Google+1Twitter0LinkedIn0Reddit0Pinterest0StumbleUpon0Digg

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

{codecitation style=”brush: xml;”}

#!/bin/sh

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/

perl emailsql.pl

{/codecitation}

-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 => mysqlbackup@your-email.com,

To    => you@your_distination-mail.com,

Subject => backupdb.tgz MySQL backup!,

Type => text/plain,

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

$msg->attach(Type=>application/x-tar,

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

Filename =>”backupdb.tgz”);

$msg->send;

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

0 0 * * * /myscripts/mysqlbackup
{/codecitation}

{loadposition user9}

For questions please refer to our Q/A forum at : http://ask.unixmen.com/

Share this Article: Facebook15Google+1Twitter0LinkedIn0Reddit0Pinterest0StumbleUpon0Digg