Page MenuHomePhabricator
Paste P8848

export.php -- emergency generation of static configs from dbctl data
ActivePublic

Authored by CDanis on Aug 1 2019, 3:47 PM.
Tags
None
Referenced Files
F29933931: raw.txt
Aug 1 2019, 9:29 PM
F29931286: raw.txt
Aug 1 2019, 3:47 PM
Subscribers
None
#!/usr/bin/php
<?php
// This script takes dbctl-JSON-formatted configuration, as produced by e.g.
// dbctl -s eqiad config get
// and transforms it into PHP suitable for pasting into db-eqiad.php in an
// emergency.
// It can also read the JSON 'restore' files output by dbctl config commit,
// with some help from jq:
// jq '.eqiad' /var/cache/conftool/dbconfig/FOO.json
$argc == 2 or die("usage: $argv[0] INPUT-JSON-FILE\n");
$inputfilename = $argv[1] or die;
$data = json_decode(file_get_contents($inputfilename), TRUE);
$data != NULL or die;
$readOnlyBySection = $data['readOnlyBySection'];
$groupLoadsBySection = $data['groupLoadsBySection'];
$sectionLoads = [];
foreach ($data['sectionLoads'] as $section => $loads) {
$sectionLoads[$section] = array_merge($loads[0], $loads[1]);
}
print '$wgLBFactoryConf[\'sectionLoads\'] = ';
var_export($sectionLoads);
print ";\n";
print '$wgLBFactoryConf[\'readOnlyBySection\'] = ';
var_export($readOnlyBySection);
print ";\n";
print '$wgLBFactoryConf[\'groupLoadsBySection\'] = ';
var_export($groupLoadsBySection);
print ";\n";

Event Timeline

CDanis changed the title of this paste from dbctl export.php to export.php -- emergency generation of static configs from dbctl data.Aug 1 2019, 9:29 PM
CDanis edited the content of this paste. (Show Details)