0byt3m1n1
Path:
/
data
/
1
/
[
Home
]
File: snapmysql5.sh
#!/bin/sh # back up mysql via snapvault # Jie Li # 9/15/2011 # MYPWD='P*dk20s#+' # please replace with the root mysql password SNAP="snapvault" CREATION="snap create" RSHPGM="/usr/bin/ssh" #assuming we have ssh key set up for mysql and netapp servers; otherwise we will need to use expect/pexpect to automate the ssh login SNAPCONFIG='/usr/services/scripts/snap.txt' HOST=`hostname` FILER=`grep $HOST $SNAPCONFIG | awk '{print $2}'` VOL=`grep $HOST $SNAPCONFIG | awk '{print $3}'` SNAPSHOT=`grep $HOST $SNAPCONFIG | awk '{print $4}'` #SNAPSHOT="SV_`date +%d-%m-%y-%H-%M-%S`" #FILER="filer" #if [ $# -lt 2 ]; then # echo "Usage: snapmysql.sh <filer> <vol-name>" # exit 1; #fi #FILER=$1 #VOL=$2 echo "target filer : $FILER ; target volume: $VOL ; SNAPSHOT: $SNAPSHOT" #first flush the tables /usr/services/mysql/mysql/bin/mysql -uroot -p$MYPWD -e "flush tables with read lock" if [ "$?" -gt 0 ]; then source /etc/Tivoli/lcf/1/lcf_env.sh machine_name=`grep machine_name ${LCF_DATDIR}/last.cfg | sed -e 's/.*=//'` ${LCF_BINDIR}/../bin/wpostemsg -r MINOR -m "`hostname`: Unable to flush tables" hostname=${machine_name} EVENT EVENT echo "flush-tables failed" exit 1; fi #sync the file system /bin/sync /bin/sync /bin/sync #now create the snap echo "Starting nightly snap \n"; date $RSHPGM -l root $FILER $SNAP $CREATION $VOL $SNAPSHOT if [ "$?" -gt 0 ]; then source /etc/Tivoli/lcf/1/lcf_env.sh machine_name=`grep machine_name ${LCF_DATDIR}/last.cfg | sed -e 's/.*=//'` ${LCF_BINDIR}/../bin/wpostemsg -r MINOR -m "`hostname`: Unable to snap mysql lun" hostname=${machine_name} EVENT EVENT echo " creating snapshot failed" else echo "finished snap creation\n"; fi echo "now unlock tables" /usr/services/mysql/mysql/bin/mysql -uroot -p$MYPWD -e "unlock tables" if [ "$?" -gt 0 ]; then source /etc/Tivoli/lcf/1/lcf_env.sh machine_name=`grep machine_name ${LCF_DATDIR}/last.cfg | sed -e 's/.*=//'` ${LCF_BINDIR}/../bin/wpostemsg -r MINOR -m "`hostname`: Unable to unlock tables after snap" hostname=${machine_name} EVENT EVENT echo " unlock tables failed" exit 1; fi echo "Completed"