Last active
August 31, 2019 15:51
-
-
Save asvignesh/48a2c077c4cb362703d6c244e85f1c15 to your computer and use it in GitHub Desktop.
MySQL Application consistent backup for Nimesa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MySQLdb | |
import os | |
import time | |
import datetime | |
dt=datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y") | |
file1 = open("/scripts/post-thaw.log","a+" ) | |
try: | |
os.remove('/tmp/freeze_snap.lock') | |
time.sleep(2) | |
except: | |
file1.write("\t Failed to remove the local file\n") | |
try: | |
conn = MySQLdb.connect ('localhost' , 'root' , 'password' ) | |
cur = conn.cursor() | |
cur.execute ("select version()") | |
data = cur.fetchone() | |
file1.write (dt) | |
except: | |
file1.write (dt) | |
file1.write("\t unable to connect to MySQL server\n") | |
try: | |
file1.write (dt) | |
file1.write ("\t executing query to unquiesce the database \n") | |
cur.execute ("unlock tables") | |
file1.write (dt) | |
file1.write ("\t Database is in unquiesce mode now \n") | |
except: | |
file1.write(dt) | |
file1.write( "\n unexpected error from MySQL, unable to unlock tables. Please check MySql error logs for more info \n") | |
cur.close() | |
conn.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MySQLdb | |
import os | |
import time | |
import datetime | |
dt=datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y") | |
file1 = open("/scripts/pre-freeze.log","a+" ) | |
try: | |
conn = MySQLdb.connect ('localhost' , 'root' , 'password' ) | |
cur = conn.cursor() | |
cur.execute ("select version()") | |
data = cur.fetchone() | |
file1.write (dt) | |
except: | |
file1.write (dt) | |
file1.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 ") | |
file1.write (dt) | |
file1.write ("\t using quiesce.py script - quiesce of database successful \n") | |
except: | |
file1.write(dt) | |
file1.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
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/mysql-post.py' | |
else | |
date >> '/scripts/post_root.log' | |
echo -e "not root useri\n" >> '/scripts/post_root.log' | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
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/mysql-post.py' | |
else | |
date >> '/scripts/post_root.log' | |
echo -e "not root useri\n" >> '/scripts/post_root.log' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment