From 19bce946cc24ceb5854cea21fb731a425df3d8ac Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 16 Feb 2021 13:45:36 +0800 Subject: [PATCH] Update index.py --- plugins/mysql/index.py | 43 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index f88cf9c6d..97272d1a4 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -1262,10 +1262,9 @@ def getTotalStatistics(): def findBinlogDoDb(): conf = getConf() con = mw.readFile(conf) - rep = 'binlog-do-db\s*=\s*(.*)' - tmp = re.search(rep, con) - dlist = tmp.groups()[0].strip() - return dlist.split(',') + rep = r"binlog-do-db\s*?=\s*?(.*)" + dodb = re.findall(rep, con, re.M) + return dodb def getMasterDbList(version=''): @@ -1321,26 +1320,22 @@ def setDbMaster(version): conf = getConf() con = mw.readFile(conf) - rep = 'binlog-do-db\s*=\s*(.*)' - tmp = re.search(rep, con) - dlist = tmp.groups()[0].strip() - dodb = dlist.split(',') - - if not args['name'] in dodb: - dlist = dlist + ',' + args['name'] - rep = "binlog-do-db\s*=\s*(.*)" - con = re.sub(rep, 'binlog-do-db=' + dlist, con) - mw.writeFile(conf, con) + rep = r"(binlog-do-db\s*?=\s*?(.*))" + dodb = re.findall(rep, con, re.M) - else: - new_dodb_str = '' - for x in dodb: - if x != args['name']: - new_dodb_str = x + ',' - new_dodb_str_len = len(new_dodb_str) - new_dodb_str = new_dodb_str[0:new_dodb_str_len - 1] - rep = "binlog-do-db\s*=\s*(.*)" - con = re.sub(rep, 'binlog-do-db=' + new_dodb_str, con) + isHas = False + for x in xrange(0, len(dodb)): + + if dodb[x][1] == args['name']: + isHas = True + + con = con.replace(dodb[x][0] + "\n", '') + mw.writeFile(conf, con) + + if not isHas: + prefix = '#binlog-do-db' + con = con.replace( + prefix, prefix + "\nbinlog-do-db=" + args['name']) mw.writeFile(conf, con) restart(version) @@ -1353,7 +1348,7 @@ def getMasterStatus(version=''): con = mw.readFile(conf) master_status = False if con.find('#log-bin') == -1 and con.find('log-bin') > 1: - if con.find('#binlog-do-db') == -1 and con.find('binlog-do-db') > 1: + if con.find('binlog-do-db') > 1: master_status = True data = {} data['status'] = master_status