LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-22-2011, 05:10 AM   #1
moyorakkhi
Member
 
Registered: Jan 2011
Location: Dhaka
Posts: 80

Rep: Reputation: 1
Seding email after successful mysqldump


Hello,

I've this script which takes backup of mysqldb through mysqldump. I need to send an automated email after success/failure mysqldump. How can add this feature in the script? Here's the script:

Code:
#!/bin/sh
BACKUP=/data/backup/sql2/new_backup/daily
cd $BACKUP
mkdir `date '+%d-%m-%Y'`
NOW=$(date +"%d-%m-%Y")

MUSER="root"
MPASS="45nflrbt"
MHOST="simpedia-sql4"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"

DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
 FILE=$BACKUP/$NOW/mysql-$db.$NOW-$(date +"%T").sql.gz
 $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS --lock-all-tables $db | $GZIP -9 > $FILE
done
 
Old 04-22-2011, 05:36 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
You could go with the mail prog if its installed. Something like this should do the trick
Code:
mail -s "Dump completed" your-mail@address.com
 
Old 04-22-2011, 08:06 AM   #3
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,191

Rep: Reputation: 105Reputation: 105
For a bit more detail in your email, you can do, e.g., the following

Code:
( echo "Subject: Dump completed";
  echo "Backup of $DBS";
  echo "completed on `hostname` at $BACKUP/$NOW" ) | mail -t your-mail@example.com
The statements in the parentheses become a subprocess in the script whose output is piped to the mail command. That allows you to fill out the Subject (and other headers if you want) plus some informational content in the body of the message.
 
Old 04-22-2011, 08:12 AM   #4
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,191

Rep: Reputation: 105Reputation: 105
Separate comment (and really a nitpick), you should reverse the order of:

mkdir `date '+%d-%m-%Y'`
NOW=$(date +"%d-%m-%Y")

And use the variable $NOW in the mkdir. These will happen so quickly that any problem is highly unlikely, but, in principle, the time could change between the two commands. Then your $NOW would fail to point to the directory that had been created. Partly it's just a matter of style and doing things the right way. In this case it's probably a one in a million chance of failure.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mysqldump problems izghitu *BSD 4 12-07-2009 10:11 AM
MySqlDump Issue?? rajnair0278 Linux - Software 17 06-09-2006 05:46 AM
mysqldump stops marciano Linux - Software 2 04-29-2006 09:23 PM
about mysqldump javier_ccs Programming 3 08-08-2005 07:13 PM
MySQLDump and Cron duerra Linux - Newbie 6 02-20-2004 09:18 AM


All times are GMT -5. The time now is 12:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration