Skip to content

Commit 698c08a

Browse files
Merge pull request #124 from timvaillancourt/mongodump_read_concern
Support readPreference on mongodump 3.4.0+, set to secondary
2 parents 6b727c9 + 520d159 commit 698c08a

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

mongodb_consistent_backup/Backup/Mongodump/Mongodump.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ def __init__(self, manager, config, timer, base_dir, backup_dir, replsets, shard
4040
with hide('running', 'warnings'), settings(warn_only=True):
4141
self.version = local("%s --version|awk 'NR >1 {exit}; /version/{print $NF}'" % self.binary, capture=True)
4242

43-
if self.can_gzip():
44-
if self.compression() == 'none':
45-
self.compression('gzip')
43+
if self.can_gzip() and self.compression() == 'none':
44+
self.compression('gzip')
4645
elif self.compression() == 'gzip':
4746
logging.warning("mongodump gzip compression requested on binary that does not support gzip!")
4847

@@ -121,8 +120,9 @@ def run(self):
121120
self.authdb,
122121
self.backup_dir,
123122
self.binary,
123+
self.version,
124124
self.threads(),
125-
self.do_gzip,
125+
self.do_gzip(),
126126
self.verbose
127127
)
128128
self.dump_threads.append(thread)
@@ -152,8 +152,9 @@ def run(self):
152152
self.authdb,
153153
self.backup_dir,
154154
self.binary,
155+
self.version,
155156
self.threads(),
156-
self.do_gzip,
157+
self.do_gzip(),
157158
self.verbose
158159
)]
159160
self.dump_threads[0].start()

mongodb_consistent_backup/Backup/Mongodump/MongodumpThread.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@
1414

1515
# noinspection PyStringFormat
1616
class MongodumpThread(Process):
17-
def __init__(self, state, uri, timer, user, password, authdb, base_dir, binary,
17+
def __init__(self, state, uri, timer, user, password, authdb, base_dir, binary, version,
1818
threads=0, dump_gzip=False, verbose=False):
1919
Process.__init__(self)
20-
self.state = state
21-
self.uri = uri
22-
self.timer = timer
23-
self.user = user
24-
self.password = password
25-
self.authdb = authdb
26-
self.base_dir = base_dir
27-
self.binary = binary
28-
self.threads = threads
29-
self.dump_gzip = dump_gzip
30-
self.verbose = verbose
20+
self.state = state
21+
self.uri = uri
22+
self.timer = timer
23+
self.user = user
24+
self.password = password
25+
self.authdb = authdb
26+
self.base_dir = base_dir
27+
self.binary = binary
28+
self.version = version
29+
self.threads = threads
30+
self.dump_gzip = dump_gzip
31+
self.verbose = verbose
3132

3233
self.timer_name = "%s-%s" % (self.__class__.__name__, self.uri.replset)
3334
self.exit_code = 1
@@ -85,6 +86,8 @@ def mongodump_cmd(self):
8586
mongodump_flags.extend(["--numParallelCollections="+str(self.threads)])
8687
if self.dump_gzip:
8788
mongodump_flags.extend(["--gzip"])
89+
if tuple("3.4.0".split(".")) <= tuple(self.version.split(".")):
90+
mongodump_flags.extend(["--readPreference=secondary"])
8891
if self.authdb and self.authdb != "admin":
8992
logging.debug("Using database %s for authentication" % self.authdb)
9093
mongodump_flags.extend(["--authenticationDatabase", self.authdb])

0 commit comments

Comments
 (0)