-
-
Save opmat/ee000d261d5b64028ce53c4c1dd1d2c1 to your computer and use it in GitHub Desktop.
Quick-n-dirty script for watching RDS replication and skipping on specific error codes
This file contains hidden or 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 sys | |
import mysql.connector | |
from mysql.connector.errors import InterfaceError | |
from time import sleep | |
mydb = mysql.connector.connect(host="", user="", password="", database="mysql") | |
cursor = mydb.cursor(dictionary=True) | |
while True: | |
sleepTime = 0.5 | |
try: | |
print("Checking replication...") | |
cursor.execute("SHOW REPLICA STATUS") | |
ss = cursor.fetchone() | |
lastErNo = ss["Last_SQL_Errno"] | |
if lastErNo in [1032, 1062, 1396, 1451]: | |
print("Duplicate key/Not found/Missing user... Skipping") | |
cursor.callproc("rds_skip_repl_error") | |
elif lastErNo == 0: | |
sleepTime = 5 | |
print(f"SBM: {ss['Seconds_Behind_Master']}") | |
else: | |
print(f"Last error: {ss['Last_SQL_Errno']}") | |
sleep(sleepTime) | |
except InterfaceError as e: | |
print(e) | |
except KeyboardInterrupt: | |
print("Shuting down...") | |
cursor.close() | |
mydb.close() | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment