@@ -33,6 +33,32 @@ def __init__(self, secondaries, base_dir, binary, dump_gzip=False, user=None, pa
3333 def summary (self ):
3434 return self ._summary
3535
36+ def wait (self ):
37+ # wait for all threads to finish
38+ for thread in self .threads :
39+ thread .join ()
40+
41+ # sleep for 3 sec to fix logging order
42+ sleep (3 )
43+
44+ # get oplog summaries from the queue
45+ completed = 0
46+ while not self .response_queue .empty ():
47+ backup = self .response_queue .get ()
48+ host = backup ['host' ]
49+ port = backup ['port' ]
50+ if host not in self ._summary :
51+ self ._summary [host ] = {}
52+ self ._summary [host ][port ] = backup
53+ if backup ['completed' ]:
54+ completed += 1
55+
56+ # check if all threads completed
57+ if completed == len (self .threads ):
58+ logging .info ("All mongodump backups completed" )
59+ else :
60+ raise Exception , "Not all mongodump threads completed successfully!" , None
61+
3662 def run (self ):
3763 # backup a secondary from each shard:
3864 for shard in self .secondaries :
@@ -51,8 +77,8 @@ def run(self):
5177 )
5278 self .threads .append (thread )
5379
54- # backup a single config server:
55- if self .config_server and self .config_server ['replset ' ]:
80+ # backup a single replica-set config server alongside the shards, if exists :
81+ if self .config_server and self .config_server ['replSet ' ]:
5682 thread = Dump (
5783 self .response_queue ,
5884 'config' ,
@@ -70,36 +96,33 @@ def run(self):
7096 if not len (self .threads ) > 0 :
7197 raise Exception , 'No backup threads started!' , None
7298
73- # start all threads
99+ # start all threads and wait
74100 logging .info (
75101 "Starting backups in threads using mongodump %s (inline gzip: %s)" % (self .version , str (self .dump_gzip )))
76102 for thread in self .threads :
77103 thread .start ()
104+ self .wait ()
78105
79- # wait for all threads to finish
80- for thread in self .threads :
81- thread .join ()
82-
83- # sleep for 3 sec to fix logging order
84- sleep (3 )
85-
86- # get oplog summaries from the queue
87- completed = 0
88- while not self .response_queue .empty ():
89- backup = self .response_queue .get ()
90- host = backup ['host' ]
91- port = backup ['port' ]
92- if host not in self ._summary :
93- self ._summary [host ] = {}
94- self ._summary [host ][port ] = backup
95- if backup ['completed' ]:
96- completed += 1
97-
98- # check if all threads completed
99- if completed == len (self .threads ):
100- logging .info ("All mongodump backups completed" )
101- else :
102- raise Exception , "Not all mongodump threads completed successfully!" , None
106+ # backup a single non-replset config server, if exists:
107+ if self .config_server and not self .config_server ['replSet' ]:
108+ logging .debug ("Using non-replset backup method for config server" )
109+ thread = Dump (
110+ self .response_queue ,
111+ 'config' ,
112+ self .config_server ['host' ],
113+ self .user ,
114+ self .password ,
115+ self .authdb ,
116+ self .base_dir ,
117+ self .binary ,
118+ self .dump_gzip ,
119+ self .verbose
120+ )
121+ self .threads = [thread ]
122+ self .threads [0 ].start ()
123+ if not len (self .threads ) == 1 :
124+ raise Exception , 'No backup threads started!' , None
125+ self .wait ()
103126
104127 return self ._summary
105128
0 commit comments