Strict Standards: Redefining already defined constructor for class MY_Model in /home/shivaram/public_html/system/cms/core/MY_Model.php on line 82

A PHP Error was encountered

Severity: Warning

Message: Creating default object from empty value

Filename: models/theme_m.php

Line Number: 142

love to learn!!! | My Blog

Send Mail using Mutt with attach compress database

There are lots of space available on gmail as well as other email provider, so keeping database as backup on mail is now a best place .This is the simple shell script to dump the database using mysqldump command and later compress that dump mysql data and finally send email along with compress data as attachment using mutt command which are easily available packages on linux OS.

Here is the Script:

# Linux bin paths, change this if it can't be autodetected via which command
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
TAR=`which tar`

MyUSER="root"     # USERNAME
MyPASS="password"       # PASSWORD
MyHOST="localhost"          # Hostname

#Database to be backup

# Backup Dest directory, change this if you have someother location

# Get hostname

# Get data in dd-mm-yyyy format
NOW="$(date +"%d-%m-%Y")"

# Main directory where backup will be stored

[ ! -d $MBD ] && mkdir -p $MBD || :

# Get database list first
      $MYSQLDUMP -u $MyUSER -h $MyHOST -p$MyPASS $db > $MBD/$db.sql

# -------------------------------------------------------------------------
#Sending Email using mutt command

# Mail Setup
MFROM=""   #From this Email Address
MTO=""     # To this Email Address
MSUB="Backup (`echo $USER @ $HOSTNAME`) as on `date`"

$TAR -zcf $OUT $MBD  >/dev/null

# create message for mail
echo "Backup successfully done. Please see attached file." > $MES
echo "" >> $MES
echo "Backup file: $OUT" >> $MES
echo "" >> $MES
# bug fix, we can't send email with attachment if mutt is not installed
which mutt > /dev/null
if [ $? -eq 0 ]; then
        # now mail backup file with this attachment
        mutt -e "unmy_hdr from; my_hdr From:$MFROM" -e "set realname=\"System Administrator" -s "$MSUB" $MTO -a "$MATT" < $MES
        echo "Command mutt not found, cannot send an email with attachment"

# clean up
/bin/rm -f $MATT
/bin/rm -f $MES