LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 09-03-2013, 05:27 AM   #1
jitendra.sharma
Member
 
Registered: Mar 2013
Location: ahmedabad
Distribution: CentOS, Ubuntu, Debian
Posts: 92
Blog Entries: 1

Rep: Reputation: Disabled
Error in mysqldump script..


Hello Friends,

i have just create a mysqldump script which i am using for dumping my data base and get confirmation by email.
script working fine when i missed my destination it shows the error in mail otherwise its shows success mail. but when i stop the mysqld service and run the script again i got success!! email which should be error email becoz mysqldump is not working.
Here is my script

#!/bin/sh

export PATH="$PATH:/usr/bin:/usr/local/bin"

dumpuser="root"
dumphost="node02.gtltest.com"
backupdir="/test/"
date=$(date +%Y-%m-%d-%H)
year=$(date +"%Y")
week=$(date +"%V")
hostname=$(hostname -f)
clientmailid=jeetjaisalmer@gmail.com

############## get a list of all the databases ###########
for db in $(mysql -u root -p"redhat" -NBe "show databases")
################## send them to nas #######################

do

mysqldump -u root -p"redhat" -Q -e --event --default-character-set=latin1 --single-transaction "${db}" | bzip2 | ssh ${dumpuser}@${dumphost} "mkdir -p ${backupdir}/${year}/week-${week}; cat > ${backupdir}/${year}/week-${week}/${db}-week-${week}-${year}.sql.bz2"

done

########## Send mail to acknowledge the scripts results ############
if [ $? = 0 ]; then
echo "Mysql Script excuted sucessfully on ${hostname} all data successfully dumped with name ${db}-week-${week}-${year}.sql.bz2 ${dumphost}" | mail -s " ${hostname} ${db}-week-${week}-${year}.sql.bz2 Mysqldump successfully" ${clientmailid}
else
echo "Mysql Script did not execute sucessfully on ${hostname} there is some error while script execution" | mail -s " ${hostname} ${db}-week-${week}-${year}.sql.bz2 Error while mysqldumping " ${clientmailid}
fi


Thank you....
~
~
 
Old 09-03-2013, 06:09 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,476

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
By using the test $? at the end of your "do" loop you're not going to get the result of the mysqldump command, you're going to get the result of the end of the whole pipe.

Consider doing your dump, compress, and transfer in different stages and monitoring each stage.

for example (in pseudocode)

Code:
DUMPERROR=0
COMPRESSERROR=0
TRANSFERERROR=0

for db in listl; do

  mysqldump blah blah blah > ${db}.sql
  if [$? != 0 ] ; then
    DUMPERROR=1
  fi

  bzip2 ${db}.sql
  if [$? != 0 ] ; then
    COMPRESSERROR=1
  fi

  scp ${db}.sql.bza user@host:/folder
  if [$? != 0 ] ; then
    TRANSFERERROR=1
  fi

done

ERRORMESSAGE=""
if [$DUMPERROR = 1]; then
 ERRORMESSAGE = "Error in the dumping stage"
fi

if [$COMPRESSERROR = 1]; then
 ERRORMESSAGE = "${ERRORMESSAGE} Error in the compression stage"
fi

if [$TRANSFERERROR = 1]; then
 ERRORMESSAGE = "${ERRORMESSAGE} Error in the transfer stage"
fi

if [$ERRORMESSAGE = ""]; then
  echo "Success" | mail
else
  echo "Failure $ERRORMESSAGE" | mail
fi
Like I say, just a rough code layout rather than proper scripting syntax!
 
1 members found this post helpful.
Old 09-04-2013, 02:59 AM   #3
jitendra.sharma
Member
 
Registered: Mar 2013
Location: ahmedabad
Distribution: CentOS, Ubuntu, Debian
Posts: 92

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Its not work...
Actually i want to monitor mysqld service with script which show me error when service not running as well as error in mysqldump commands..
 
Old 09-04-2013, 03:34 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,476

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by jitendra.sharma View Post
Its not work...
So what did you write?

Quote:
Originally Posted by jitendra.sharma View Post
Actually i want to monitor mysqld service with script which show me error when service not running as well as error in mysqldump commands..
We aren't mind readers, if you don't tell us then we can't help. What have you written so far to check your mysqld service?
 
Old 09-04-2013, 03:44 AM   #5
SAbhi
Member
 
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 665

Rep: Reputation: Disabled
so what error did you see, it is very obvious it will show some error the way it is used... but i can make eny comment only after having a look on the error.. you should have tested the command line before putting into the script.
 
Old 09-04-2013, 04:18 AM   #6
jitendra.sharma
Member
 
Registered: Mar 2013
Location: ahmedabad
Distribution: CentOS, Ubuntu, Debian
Posts: 92

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Thanks for the reply..
actually i am getting success mail instead of error mail while my mysqld service stop..
there is must be error mail after script execusion..
i think mysqldump error code is 0 while mysqld service stop so i want some changes in my script in which it show me an error mail when mysqld service stop and i can get proper update mail of my mysql backup script..

Can we use this command for mysql service monitoring?
ps -ef | grep mysqld | grep -v grep;

Thank You

Last edited by jitendra.sharma; 09-04-2013 at 04:20 AM.
 
Old 09-04-2013, 04:41 AM   #7
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,476

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
If you're running these tests as root and also assuming CentOS:

Code:
#!/bin/bash

STATUS=`service mysqld status | awk {'print $NF'}`

if [ ${STATUS} != "running..." ] ; then
  echo "mysqld problem? ${STATUS}"
else
  echo Fine!
fi
 
Old 09-04-2013, 05:41 AM   #8
jitendra.sharma
Member
 
Registered: Mar 2013
Location: ahmedabad
Distribution: CentOS, Ubuntu, Debian
Posts: 92

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Thanks dear i got the logic and problem solved

Actually i run two this command

#ps -ef | grep mysqld | grep -v grep;
#errcode1=$?

and

#mysqldump
#errcode2=$?


and make statement two compare both value

if [ "${errcode1}" = "${errcode2}" ];

Thanks Dear....
 
  


Reply

Tags
mysqldump, scripts



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
Using mysqldump VeeDubbs Linux - Server 9 11-25-2011 05:40 AM
Error 1016 during mysqldump h725 Linux - Server 2 08-17-2009 04:58 AM
[Bash] mysqldump netpumber Programming 15 04-12-2009 04:22 PM
mysqldump bash script help LukeC64 Programming 1 11-15-2007 05:43 AM
about mysqldump javier_ccs Programming 3 08-08-2005 06:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:59 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
Open Source Consulting | Domain Registration