Created
May 28, 2013 23:38
-
-
Save israelshirk/5666961 to your computer and use it in GitHub Desktop.
Fast-forwards a DB slave through specific error numbers. Nifty if there are hundreds or thousands of them (think schema updates being run with bad timing...)
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 MySQLdb, MySQLdb.cursors, time | |
skip_errno=1677L | |
db_user='' | |
db_passwd='' | |
db_host='' | |
db_db = '' | |
connection = MySQLdb.connect(host=db_host, user=db_user, passwd=db_passwd, db=db_db,cursorclass=MySQLdb.cursors.DictCursor, charset='UTF8') | |
cursor = connection.cursor() | |
while 1: | |
time.sleep(0.05) | |
cursor.execute("show slave status") | |
row = cursor.fetchone() | |
print row['Slave_SQL_Running'], row['Last_SQL_Errno'] | |
if row['Slave_SQL_Running'] == 'No' and row['Last_SQL_Errno'] == skip_errno: | |
cursor.execute("stop slave") | |
cursor.execute("set global SQL_SLAVE_SKIP_COUNTER=1") | |
cursor.execute("start slave;") | |
else: | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment