Data Backup and Recovery

Exit code issue when using a shell script to quiesce a MySQL database

jcbettinelli
4,145 Views

Hello,

I'm trying to setup up SnapCreator for MySQL for a customer.

At first, we tried the integrated plug-in, but it seems that we're facing a net::mysql issue, as the script doesn't work more than once when the agent is fresh started.

So I found a script to quiesce all databases with mysql commands.

#!/bin/bash

#set -x

#set $(date)

#str_Tag=$(date +%A);

MYSQL_PWD="toto"

DBASELIST=`mktemp`

mysqlshow -p$MYSQL_PWD | awk '{print $2}' | grep -v Databases | sort >$DBASELIST

# Flush of databases

for x in `cat $DBASELIST`; do

        echo $x

        mysql -u root -p$MYSQL_PWD $x -e "flush tables with read lock" -v

        mysql -u root -p$MYSQL_PWD $x -e "flush logs" -v

done;

My issue is that when the backup runs, the result of the script that is sent to the server is -1, which the server interprets as a no-go for the snapshot.

########## APPLICATION QUIESCE COMMANDS ##########

[2013-11-08 16:11:26,091] INFO: [dbmasterbkp:9090 (4.0.0.1)] Executing Application quiesce command [/home/pentaadmin/netapp/quiesce.sh] on dbmasterbkp

[2013-11-08 16:11:26,091] DEBUG: [dbmasterbkp:9090 (4.0.0.1)] Executing command [/home/pentaadmin/netapp/quiesce.sh]

[2013-11-08 16:11:26,091] TRACE: Command [/home/pentaadmin/netapp/quiesce.sh] finished with

exit code: [-1]

stdout: []

stderr: []

[2013-11-08 16:11:26,092] ERROR: [dbmasterbkp:9090 (4.0.0.1)] Command [/home/pentaadmin/netapp/quiesce.sh] failed with return code [-1] and message []

########## Application not defined. Skipping Unquiesce task ##########

########## Snap Creator Framework 4.0p1 failed ##########

########## PRE EXIT COMMANDS ##########

[2013-11-08 16:11:26,360] INFO: [dbmasterbkp:9090 (4.0.0.1)] Executing Pre Exit command [/home/pentaadmin/netapp/unquiesce.sh] on dbmasterbkp

[2013-11-08 16:11:26,360] DEBUG: [dbmasterbkp:9090 (4.0.0.1)] Executing command [/home/pentaadmin/netapp/unquiesce.sh]

[2013-11-08 16:11:26,360] TRACE: Command [/home/pentaadmin/netapp/unquiesce.sh] finished with

exit code: [-1]

stdout: []

stderr: []

[2013-11-08 16:11:26,360] ERROR: [dbmasterbkp:9090 (4.0.0.1)] Command [/home/pentaadmin/netapp/unquiesce.sh] failed with return code [-1] and message []

The script runs well, and if I run it manually, and then I enter >echo $?, the exit code comes at 0.

Do I need to add something at the end of the script ?

Thank you in advance for your help,

JC

1 REPLY 1

sivar
4,145 Views

You may want to supply your own exit code within the script.

There is a good amount of discussion here.

http://stackoverflow.com/questions/64786/error-handling-in-bash

I will also test your code in the lab and update here with my findings.

Public