bzr branch
http://darksoft.org/webbzr/adei/trunk
462
by Suren A. Chilingaryan
Add log-based quick fixer for mysql database (using mysqlcheck) |
1 |
<?php
|
2 |
$mysql = new mysqli("localhost", "adei", "adei", "adei"); |
|
3 |
||
4 |
||
5 |
function resolve($postfix) { |
|
6 |
global $mysql; |
|
7 |
||
8 |
$res = $mysql->query("SELECT hash FROM md5 WHERE `postfix` LIKE \"%$postfix\""); |
|
9 |
if (($res)&&($res->num_rows > 0)) { |
|
10 |
$row = $res->fetch_assoc(); |
|
11 |
return $row["hash"]; |
|
12 |
}
|
|
13 |
||
14 |
return $postfix; |
|
15 |
}
|
|
16 |
||
17 |
||
18 |
function get_caches($postfix) { |
|
19 |
global $mysql; |
|
20 |
||
21 |
$list = array(); |
|
22 |
||
23 |
$res = $mysql->query("SHOW TABLES LIKE \"cache%{$postfix}\";"); |
|
24 |
if (($res)&&($res->num_rows > 0)) { |
|
25 |
$res->data_seek(0); |
|
26 |
while ($row = $res->fetch_array()) { |
|
27 |
array_push($list, $row[0]); |
|
28 |
}
|
|
29 |
}
|
|
30 |
return $list; |
|
31 |
}
|
|
32 |
||
33 |
||
34 |
$done = array(); |
|
35 |
||
36 |
$f = fopen("/var/spool/mail/root", "r"); |
|
37 |
while (!feof($f)) { |
|
38 |
$line = fgets($f); |
|
39 |
if (preg_match('/Server: "(.*)" Database: "?(.*)" Group: "(.*)"/', $line, $m)) { |
|
40 |
$postfix=resolve("__{$m[1]}__{$m[2]}__{$m[3]}"); |
|
41 |
||
42 |
if (!in_array($postfix, $done)) { |
|
43 |
echo "Fixing: $postfix\n"; |
|
44 |
$caches = get_caches($postfix); |
|
45 |
foreach ($caches as $cache) { |
|
46 |
system("mysqlcheck -r adei $cache\n"); |
|
47 |
}
|
|
48 |
||
49 |
array_push($done, $postfix); |
|
50 |
}
|
|
51 |
}
|
|
52 |
}
|
|
53 |
||
54 |
||
55 |
?>
|