Google Plus

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

Written by Mel Kham on . Posted in Linux tutorials

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

Mel Kham

Founder of Unixmen, Living in Amsterdam. Am working in my free time to help people to understand the Opensource and to explain them in easy way how to make the fist steps to the the light. Working day and night with my Co-founder Zinovsky to keep this website live even with less resources.
  • Darren

    This is the script I run from a cron job every night. the [color=red]MUSER[/color] has basic access to read all databases held on the local mysql server restricted to local access only.

    It stores 1 weeks worth of backups before it starts to delete the oldest copy by which time the backups have be committed to tape.

    [code]
    #!/bin/bash

    umask 177

    MUSER="userid"
    MPASS="password"
    MHOST="localhost"
    MYSQL="$(which mysql)"
    MYSQLDUMP="$(which mysqldump)"
    PARAMS="--hex-blob --skip-extended-insert --password=$MPASS"
    DATE="$(date +%F)"
    BACKUPDIR="/home/${MUSER}/BACKUP/$DATE/"
    RMDATE="$(date -d "1 week ago" +%F)"
    RMDIR="/home/${MUSER}/BACKUP/$RMDATE"
    BACKUPLOG="/home/${MUSER}/BACKUP/backup.log"

    if [ ! -f $BACKUPLOG ] ; then
    touch $BACKUPLOG
    chmod 600 $BACKUPLOG
    fi

    if [ -d $RMDIR ]; then
    rm -rf $RMDIR
    echo "Backup DELETED from" $RMDATE >> $BACKUPLOG
    fi

    if [ ! -d $BACKUPDIR ]; then
    mkdir -m 700 -p $BACKUPDIR
    fi

    echo "Backup BEGINNING" $DATE >> $BACKUPLOG

    DBS="$($MYSQL -h $MHOST -u $MUSER -p$MPASS -Bse 'show databases')"
    for db in $DBS
    do
    $MYSQLDUMP $PARAMS $db > $BACKUPDIR$db.sql && bzip2 --best $BACKUPDIR$db.sql
    done

    echo "Backup COMPLETED" $DATE >> $BACKUPLOG
    [/code]

    Hope it’s useful.

  • pirat9

    Its usefull :) thx Darren

  • http://www.bestfinance-blog.com RobynMCINTOSH27

    Set your life more simple take the personal loans and all you want.

Like us on Facebook

This week Top Posts

Write for us

Recent Comments

cave

|

it can be used to talk or chat through the internet,

it is using strong encryption.

but for example TOR is using some obfuscation because some countrys try to block all outgoing connections which can not be scanned with DPI

And the TOR Project is facing an arms race in obfuscation and encryption detection.

cave

|

You can friend someone if you give him your public Certificate.

both peers must friend each other.

i suggest to not enter a valid e-mail address. it is not necessary, but pgp needs a mail addy. something@something.so fits perfectly… :)

http://redd.it/18vsq5 <– faq, featurelist, todo, howto, useful links to manual wiki etc, …

you can connect to chatservers, which will give you access to chatlobby, where always some people are lurking.

#1 https://www.f2f-fr.net/w2c/en/
#2 http://retrosharechatserver.no-ip.org/w2c/en/

and in this rooms, you can find other people to talk and friend.

cave

|

http://redd.it/18vsq5
please have a look at this link. it is a FAQ, QuickTip, HowTo, etc etc etc …

If you want to make friends, please use the Chatservers.
#1 https://www.f2f-fr.net/w2c/en/
#2 http://retrosharechatserver.no-ip.org/w2c/en/

if you enter your certificate, the chatserver adds you as his friend and shows his certificate too add him to your friends.

After the connection to the chatservers is established, you can join a few chatrooms where the chatserver is lurking.

in this rooms are other people too help you and make first friends and get into the network.

add friends only with wisdom. if you friend some policeman, it will be problematic like in real life.

best is to add only people you trust in real life or trust from other communitys too. and not to add random unkown strangers.

If you have questions, ask them in the chatlobbys, there is always someone to answer them.

please read http://redd.it/18vsq5

or question me here :)

Ladi Oyekanmi

|

Could you please assist in step by step on how to install nagios on solaris

Adhraa

|

Greate tutorial :)

 
IDG Tech Network
Copyright © 2008-2013 Unixmen.com .
Maintained by Anblik .