Skip to content

Commit 43c2aca

Browse files
author
Tim Vaillancourt
committed
many changes to support config replset and the rs.status() to determine it
1 parent e561d4d commit 43c2aca

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

MongoBackup/Common/DB.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,19 @@ def auth_if_required(self):
4444
else:
4545
pass
4646

47-
def admin_command(self, admin_command, retry=True):
47+
def admin_command(self, admin_command, retry=True, quiet=False):
4848
tries = 0
4949
status = None
50-
while retry and not status and tries < self.retries:
50+
while not status and tries < self.retries:
5151
try:
5252
status = self._conn['admin'].command(admin_command)
5353
if not status:
5454
raise e
5555
except Exception, e:
56-
logging.error("Error running admin command '%s': %s" % (admin_command, e))
56+
if not retry:
57+
tries = self.retries
58+
if not quiet:
59+
logging.error("Error running admin command '%s': %s" % (admin_command, e))
5760
tries += 1
5861
sleep(1)
5962
if not status:

MongoBackup/Methods/Dumper.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def __init__(self, secondaries, base_dir, binary, dump_gzip=False, user=None, pa
2020
self.config_server = config_server
2121
self.verbose = verbose
2222

23-
self.config_replset = False
2423
self.response_queue = Queue()
2524
self.threads = []
2625
self._summary = {}
@@ -53,11 +52,11 @@ def run(self):
5352
self.threads.append(thread)
5453

5554
# backup a single config server:
56-
if self.config_server:
55+
if self.config_server and self.config_server['is_replset']:
5756
thread = Dump(
5857
self.response_queue,
5958
'config',
60-
self.config_server,
59+
self.config_server['host'],
6160
self.user,
6261
self.password,
6362
self.authdb,

MongoBackup/Replset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def __init__(self, db, user=None, password=None, authdb='admin', max_lag_secs=5)
2828
def close(self):
2929
pass
3030

31-
def get_rs_status(self, force=False, retry=True):
31+
def get_rs_status(self, force=False, retry=True, quiet=False):
3232
try:
3333
if force or not self.rs_status:
34-
self.rs_status = self.db.admin_command('replSetGetStatus', retry)
34+
self.rs_status = self.db.admin_command('replSetGetStatus', retry, quiet)
3535
return self.rs_status
3636
except Exception, e:
3737
raise Exception, "Error getting replica set status! Error: %s" % e, None

MongoBackup/Sharding.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,22 @@ def get_configserver(self, force=False):
112112
config_list = config_string.split(",")
113113
except Exception:
114114
config_list = [config_string]
115-
self.config_server = config_list[0]
115+
116+
config_replset = False
117+
try:
118+
config_host, config_port = config_list[0].split(":")
119+
db = DB(config_host, config_port, self.user, self.password, self.authdb)
120+
rs = Replset(db, self.user, self.password, self.authdb)
121+
try:
122+
rs.get_rs_status(True, False, True)
123+
config_replset = True
124+
except Exception:
125+
config_replset = False
126+
except Exception, e:
127+
raise e
128+
129+
self.config_server = {'host': config_list[0], 'is_replset': config_replset}
116130
else:
117131
logging.fatal("Unable to locate config servers for %s:%i!" % (self.host, self.port))
118132
raise Exception, "Unable to locate config servers for %s:%i!" % (self.host, self.port), None
119133
return self.config_server
120-
121-
def is_config_replset(self):
122-
try:
123-
config_server = self.get_configserver()
124-
config_host, config_port = config_server.split(":")
125-
db = DB(config_host, config_port, self.user, self.password, self.authdb)
126-
rs = Replset(db, self.user, self.password, self.authdb)
127-
try:
128-
rs.get_rs_status(True, False)
129-
return
130-
except Exception:
131-
return False
132-
except Exception, e:
133-
raise e
134-

0 commit comments

Comments
 (0)