You can add a pre-process script file or a post-process script file for MySQL on the Kubernetes access nodes.
Example Pre-Process Script
The following example is a pre-process script for MySQL. Edit the example script to include MySQL user credentials with root ownership.
#!/usr/bin/env python
import pymysql.cursors
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 = pymysql.connect (host='localhost' , user='<MYSQL USER>' , password='<USER PASSWORD>',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor )
with conn.cursor() as cur:
cur.execute ("select version()")
data = cur.fetchone()
file1.write (dt)
file1.write ("-------------------------------------------\n")
file1.write ("-------------------------------------------\n")
file1.write ("\t MySQL version is %s: "%data)
file1.write ("-------------------------------------------\n")
file1.write ("-------------------------------------------\n")
except:
file1.write (dt)
file1.write("\t unable to connect to MySQL server\n")
try:
cur = conn.cursor()
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")
finally:
cur.close()
conn.close()
file1.close()
Example Post-Process Script
The following example is a post-process script for MySQL. Edit the example script to include MySQL user credentials with root ownership.
#!/usr/bin/env python
import pymysql.cursors
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:
conn = pymysql.connect (host='localhost' , user='<MYSQL USER>' , password='<USER PASSWORD>',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor )
cur = conn.cursor()
cur.execute ("select version()")
data = cur.fetchone()
file1.write (dt)
file1.write ("-------------------------------------------\n")
file1.write ("-------------------------------------------\n")
file1.write ("\t MySQL version is %s: "%data)
file1.write ("-------------------------------------------\n")
file1.write ("-------------------------------------------\n")
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")
finally:
cur.close()
conn.close()
file1.close()
Output and Log Files
Output from the scripts is written to the following files on your production MySQL pod:
Pre-execution script: /scripts/pre-freeze.log
Post-execution script: /scripts/pre-thaw.log
To modify the paths, edit the scripts that are stored on your access nodes.
Caution
There is no log rotation implemented in these log files. Restore to a file system that has appropriate disk space.
Backup jobs depend on the return codes of pre- and post-scripts. Any return code value other than 0 fails backup jobs.