1515
1616# noinspection PyStringFormat
1717class MongodumpThread (Process ):
18- def __init__ (self , state , uri , timer , config , base_dir , version , threads = 0 , dump_gzip = False ):
18+ def __init__ (self , state , uri , timer , config , base_dir , version , threads = 0 , dump_gzip = False , oplog_enabled = True ):
1919 Process .__init__ (self )
20- self .state = state
21- self .uri = uri
22- self .timer = timer
23- self .config = config
24- self .base_dir = base_dir
25- self .version = version
26- self .threads = threads
27- self .dump_gzip = dump_gzip
20+ self .state = state
21+ self .uri = uri
22+ self .timer = timer
23+ self .config = config
24+ self .base_dir = base_dir
25+ self .version = version
26+ self .threads = threads
27+ self .dump_gzip = dump_gzip
28+ self .oplog_enabled = oplog_enabled
2829
2930 self .user = self .config .username
3031 self .password = self .config .password
@@ -49,6 +50,13 @@ def __init__(self, state, uri, timer, config, base_dir, version, threads=0, dump
4950 signal (SIGINT , SIG_IGN )
5051 signal (SIGTERM , self .close )
5152
53+ def oplog_enabled_parse (self ):
54+ if isinstance (self .oplog_enabled , bool ):
55+ return self .oplog_enabled
56+ elif isinstance (self .oplog_enabled , str ) and self .oplog_enabled .strip ().lower () != 'false' :
57+ return True
58+ return False
59+
5260 def close (self , exit_code = None , frame = None ):
5361 if self ._command :
5462 logging .debug ("Stopping running subprocess/command: %s" % self ._command .command )
@@ -152,8 +160,12 @@ def mongodump_cmd(self):
152160 "--port=%s" % str (mongodump_uri .port )
153161 ])
154162
163+ if self .oplog_enabled_parse ():
164+ mongodump_flags .extend ([
165+ "--oplog"
166+ ])
167+
155168 mongodump_flags .extend ([
156- "--oplog" ,
157169 "--out=%s/dump" % self .backup_dir
158170 ])
159171
@@ -233,20 +245,27 @@ def run(self):
233245 except Exception , e :
234246 logging .exception ("Error performing mongodump: %s" % e )
235247
236- try :
237- oplog = Oplog (self .oplog_file , self .dump_gzip )
238- oplog .load ()
239- except Exception , e :
240- logging .exception ("Error loading oplog: %s" % e )
248+ oplog = None
249+ if self .oplog_enabled_parse ():
250+ try :
251+ oplog = Oplog (self .oplog_file , self .dump_gzip )
252+ oplog .load ()
253+ except Exception , e :
254+ logging .exception ("Error loading oplog: %s" % e )
241255
242256 self .state .set ('running' , False )
243257 self .state .set ('completed' , True )
244- self .state .set ('count' , oplog .count ())
245- self .state .set ('first_ts' , oplog .first_ts ())
246- self .state .set ('last_ts' , oplog .last_ts ())
258+ if self .oplog_enabled_parse ():
259+ self .state .set ('count' , oplog .count ())
260+ self .state .set ('first_ts' , oplog .first_ts ())
261+ self .state .set ('last_ts' , oplog .last_ts ())
247262 self .timer .stop (self .timer_name )
248263
249- log_msg_extra = "%i oplog changes" % oplog .count ()
250- if oplog .last_ts ():
251- log_msg_extra = "%s, end ts: %s" % (log_msg_extra , oplog .last_ts ())
264+ if self .oplog_enabled_parse ():
265+ log_msg_extra = "%i oplog changes" % oplog .count ()
266+ if oplog .last_ts ():
267+ log_msg_extra = "%s, end ts: %s" % (log_msg_extra , oplog .last_ts ())
268+ else :
269+ log_msg_extra = "No oplog"
270+
252271 logging .info ("Backup %s completed in %.2f seconds, %s" % (self .uri , self .timer .duration (self .timer_name ), log_msg_extra ))
0 commit comments