@@ -61,6 +61,12 @@ def do_ssl(self):
6161 def do_ssl_insecure (self ):
6262 return parse_config_bool (self .config .ssl .insecure )
6363
64+ def is_version_gte (self , compare ):
65+ if os .path .isfile (self .binary ) and os .access (self .binary , os .X_OK ):
66+ if tuple (compare .split ("." )) <= tuple (self .version .split ("." )):
67+ return True
68+ return False
69+
6470 def parse_mongodump_line (self , line ):
6571 try :
6672 line = line .rstrip ()
@@ -127,31 +133,40 @@ def mongodump_cmd(self):
127133 mongodump_flags = ["--host" , mongodump_uri .host , "--port" , str (mongodump_uri .port ), "--oplog" , "--out" , "%s/dump" % self .backup_dir ]
128134 if self .threads > 0 :
129135 mongodump_flags .extend (["--numParallelCollections=" + str (self .threads )])
136+
130137 if self .dump_gzip :
131138 mongodump_flags .extend (["--gzip" ])
132- if tuple ("3.4.0" .split ("." )) <= tuple (self .version .split ("." )):
139+
140+ if self .is_version_gte ("3.4.0" ):
133141 mongodump_flags .extend (["--readPreference=secondary" ])
142+
134143 if self .authdb and self .authdb != "admin" :
135144 logging .debug ("Using database %s for authentication" % self .authdb )
136145 mongodump_flags .extend (["--authenticationDatabase" , self .authdb ])
137146 if self .user and self .password :
138147 # >= 3.0.2 supports password input via stdin to mask from ps
139- if tuple ( self .version . split ( "." )) >= tuple ( " 3.0.2". split ( "." ) ):
148+ if self .is_version_gte ( " 3.0.2" ):
140149 mongodump_flags .extend (["-u" , self .user , "-p" , '""' ])
141150 self .do_stdin_passwd = True
142151 else :
143152 logging .warning ("Mongodump is too old to set password securely! Upgrade to mongodump >= 3.0.2 to resolve this" )
144153 mongodump_flags .extend (["-u" , self .user , "-p" , self .password ])
154+
145155 if self .do_ssl ():
146- mongodump_flags .append ("--ssl" )
147- if self .ssl_ca_file :
148- mongodump_flags .extend (["--sslCAFile" , self .ssl_ca_file ])
149- if self .ssl_crl_file :
150- mongodump_flags .extend (["--sslCRLFile" , self .ssl_crl_file ])
151- if self .client_cert_file :
152- mongodump_flags .extend (["--sslPEMKeyFile" , self .ssl_cert_file ])
153- if self .do_ssl_insecure ():
154- mongodump_flags .extend (["--sslAllowInvalidCertificates" , "--sslAllowInvalidHostnames" ])
156+ if self .is_version_gte ("2.6.0" ):
157+ mongodump_flags .append ("--ssl" )
158+ if self .ssl_ca_file :
159+ mongodump_flags .extend (["--sslCAFile" , self .ssl_ca_file ])
160+ if self .ssl_crl_file :
161+ mongodump_flags .extend (["--sslCRLFile" , self .ssl_crl_file ])
162+ if self .client_cert_file :
163+ mongodump_flags .extend (["--sslPEMKeyFile" , self .ssl_cert_file ])
164+ if self .do_ssl_insecure ():
165+ mongodump_flags .extend (["--sslAllowInvalidCertificates" , "--sslAllowInvalidHostnames" ])
166+ else :
167+ logging .fatal ("Mongodump must be >= 2.6.0 to enable SSL encryption!" )
168+ sys .exit (1 )
169+
155170 mongodump_cmd .extend (mongodump_flags )
156171 return mongodump_cmd
157172
0 commit comments