MySQL: Freeze Thaw Quiesce and Unquiesce scripts for Hitachi Virtual Infrastructure Integrator

Document created by Paul Morrissey on Feb 14, 2015Last modified by Paul Morrissey on Jul 1, 2015
Version 2Show Document
  • View in full screen mode

Related Article Application Consistent Backup with Hitachi Virtual Infrastructure Integrator

 

pre-freeze-script.sh

 

#!/bin/sh

 

#pre-freeze-script

 

date >> '/scripts/pre_root.log'

echo -e "\n attempting to run pre-freeze script for MySQL as root user\n" >> /scripts/pre_root.log

test=`id –u`

if [ $test -eq 0 ]

then

python '/scripts/quiesce.py' &

echo -e "\n executing query flush tables with read lock to quiesce the database\n" >> /scripts/pre-freeze.log

echo -e "\n Database is in quiesce mode now\n" >> /scripts/pre-freeze.log

else

date >> '/scripts/pre_root.log'

echo -e "not root useri\n" >> '/scripts/pre_root.log'

fi   

post-thaw-script.sh

 

#!/bin/sh

 

#post-thaw-script

 

date >> '/scripts/post_root.log'
echo -e "\n attempting to run post-thaw script for MySQL as root user\n" >> /scripts/post_root.log
if [ "$(id -u)" -eq "0" ]; then
python '/scripts/unquiesce.py'
else
date >> '/scripts/post_root.log'
echo -e "not root useri\n" >> '/scripts/post_root.log'
fi

unquiesce.py

 

import MySQLdb
import os
import time
import datetime
dt=datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y")
outputf1 = open("/scripts/post-thaw.log","a+" )
try:
os.remove('/tmp/freeze_snap.lock')
time.sleep(2)
except Exception, e:
print e
try:
conn = MySQLdb.connect ('localhost' , 'root' , 'password' )
cur = conn.cursor()
cur.execute ("select version()")
data = cur.fetchone()
outputf1.write (dt)
outputf1.write ("````````````````````````````\n")
outputf1.write ("````````````````````````````\n")
outputf1.write ("\t MySQL Database version is %s: "%data)
outputf1.write ("````````````````````````````\n")
outputf1.write ("````````````````````````````\n")
except:
outputf1.write (dt)
outputf1.write("\t unable to connect to MySQL server\n")

 

try:
outputf1.write (dt)
outputf1.write ("\t executing query to unquiescethe database \n")
cur.execute ("unlock tables")
outputf1.write (dt)
outputf1.write ("\t Database is in unquiescemode now \n")
except:
outputf1.write(dt)
outputf1.write( "\n unexpected error from MySQL, unable to unlock tables. Please check MySql error logs for more info \n")

 

cur.close()
conn.close()

 

quiesce.py

 

import MySQLdb
import os
import time
import datetime
dt=datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y")
outputf1 = open("/scripts/pre-freeze.log","a+" )
try:
conn = MySQLdb.connect ('localhost' , 'root' , 'password' )
cur = conn.cursor()
cur.execute ("select version()")
data = cur.fetchone()
outputf1.write (dt)
outputf1.write ("````````````````````````````\n")
outputf1.write ("````````````````````````````\n")
outputf1.write ("\t MySQL Database version is %s: "%data)
outputf1.write ("````````````````````````````\n")
outputf1.write ("````````````````````````````\n")

 

except:
outputf1.write (dt)
outputf1.write("\t unable to connect to MySQL server\n")

 

file2 = open ('/tmp/freeze_snap.lock', 'w')
file2.close()

 

try:
cur.execute (" flush tables with read lock ")
outputf1.write (dt)
outputf1.write ("\t using unquiesce.py script - un-quiesce of database successful \n")
except:
outputf1.write(dt)
outputf1.write( "\n unexpected error from MySQL, unable to do flush tables with read lock, Please check MySQL error logs for more info\n")
while True:
check = os.path.exists ("/tmp/freeze_snap.lock")
if check == True:
continue
else:
break

 

____________________________________________________________

Accreditation: Hitachi Data Protection Suite Software Documentation

Attachments

    Outcomes