Skip to content

Commit ca3fabe

Browse files
Merge pull request #7 from objectrocket/SREESC-467-disable-oplog
Sreesc 467 disable oplog
2 parents 3ab506a + 3d3f753 commit ca3fabe

File tree

3 files changed

+45
-22
lines changed

3 files changed

+45
-22
lines changed

mongodb_consistent_backup/Backup/Mongodump/Mongodump.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def __init__(self, manager, config, timer, base_dir, backup_dir, replsets, backu
2121
self.authdb = self.config.authdb
2222
self.compression_method = self.config.backup.mongodump.compression
2323
self.binary = self.config.backup.mongodump.binary
24+
self.oplog_enabled = self.config.backup.mongodump.oplog_enabled
2425
self.replsets = replsets
2526
self.backup_stop = backup_stop
2627
self.sharding = sharding
@@ -138,7 +139,8 @@ def run(self):
138139
self.backup_dir,
139140
self.version,
140141
self.threads(),
141-
self.do_gzip()
142+
self.do_gzip(),
143+
self.oplog_enabled
142144
)
143145
self.dump_threads.append(thread)
144146
except Exception, e:

mongodb_consistent_backup/Backup/Mongodump/MongodumpThread.py

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515

1616
# noinspection PyStringFormat
1717
class 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))

mongodb_consistent_backup/Backup/Mongodump/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ def config(parser):
1010
parser.add_argument("--backup.mongodump.threads", dest="backup.mongodump.threads",
1111
help="Number of threads to use for each mongodump process. There is 1 x mongodump per shard, be careful! (default: shards/CPUs)",
1212
default=0, type=int)
13+
parser.add_argument("--backup.mongodump.oplog.enabled", dest="backup.mongodump.oplog_enabled", default='true', type=str,
14+
help="Run mongodump with --oplog option")
1315
return parser

0 commit comments

Comments
 (0)