r17495 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17494‎ | r17495 | r17496 >
Date:16:15, 8 November 2006
Author:brion
Status:old
Tags:
Comment:
Use new getSlaveServer.php to pick a db server to pull from for each wiki
if the host script didn't pass us an explicit server name.
Picking again for each wiki means:
* Multiple sub-clusters can be mixed in one script run
* Massive host failures or reshufflings will be recognized as the next wiki
gets reached, rather than requiring the whole dump runner script to be
killed and restarted
Modified paths:
  • /trunk/backup/WikiBackup.py (modified) (history)

Diff [purge]

Index: trunk/backup/WikiBackup.py
@@ -169,8 +169,8 @@
170170
171171 class Runner(object):
172172
173 - def __init__(self, public, private, dblist, privatelist, dbserver,
174 - dbuser, dbpassword, wikidir, php="php", webroot="",
 173+ def __init__(self, public, private, dblist, privatelist, dbserver=None,
 174+ dbuser="", dbpassword="", wikidir="", php="php", webroot="",
175175 template=dirname(realpath(sys.modules[__module__].__file__)),
176176 tmp="/tmp", adminmail=None, mailfrom="root@localhost",
177177 mailserver="localhost", bzip2="bzip2", sevenzip="7za"):
@@ -178,7 +178,8 @@
179179 self.private = private
180180 self.dblist = dblist
181181 self.privatelist = privatelist
182 - self.dbserver = dbserver
 182+ self.dbserverOverride = dbserver
 183+ self.dbserver = None
183184 self.dbuser = dbuser
184185 self.dbpassword = dbpassword
185186 self.wikidir = wikidir
@@ -325,6 +326,17 @@
326327 line = proc.fromchild.readline()
327328 return proc.wait()
328329
 330+ def runAndReturn(self, command):
 331+ """Run a command and return the output as a string.
 332+ Raises BackupError on non-zero return code."""
 333+ proc = popen2.Popen4(command, 64)
 334+ output = proc.fromchild.read()
 335+ retval = proc.wait()
 336+ if retval:
 337+ raise BackupError("Non-zero return code from '%s'" % command)
 338+ else:
 339+ return output
 340+
329341 def debug(self, stuff):
330342 print "%s: %s %s" % (prettyTime(), self.db, stuff)
331343
@@ -341,12 +353,24 @@
342354 self.debug("Creating %s ..." % dir)
343355 os.makedirs(dir)
344356
 357+ def selectDatabaseServer(self):
 358+ if self.dbserverOverride:
 359+ self.dbserver = self.dbserverOverride
 360+ else:
 361+ self.dbserver = self.defaultServer()
 362+
 363+ def defaultServer(self):
 364+ command = "%s -q %s/maintenance/getSlaveServer.php %s" % shellEscape((
 365+ self.php, self.wikidir, self.db))
 366+ return self.runAndReturn(command).strip()
 367+
345368 def doBackup(self):
346369 self.makeDir(self.publicDir())
347370 self.makeDir(self.privateDir())
348371
349372 self.status("Starting backup of %s" % self.db)
350373 self.lock()
 374+ self.selectDatabaseServer()
351375
352376 self.items = [PrivateTable("user", "User account data."),
353377 PrivateTable("watchlist", "Users' watchlist settings."),