Calcul des tailles des données utilisateurs après debianisation et separation des BDD alternc / BDD users
Première ébauche, idéalement il faudrait tout réécrire proprement (voir ticket #1487)
This commit is contained in:
parent
8e5205e46e
commit
31d077e328
|
@ -42,23 +42,41 @@ class DB_users extends DB_Sql {
|
|||
*/
|
||||
function DB_users() {
|
||||
global $cuid, $db, $err;
|
||||
$db->query("select db_servers.* from db_servers, membres where membres.uid=$cuid and membres.db_server_id=db_servers.id;");
|
||||
|
||||
if (!$db->next_record()) {
|
||||
$err->raise('db_user', _("There are no databases in db_servers for this user. Please contact your administrator."));
|
||||
die();
|
||||
// Check if function got args
|
||||
$num=func_num_args();
|
||||
|
||||
switch($num) {
|
||||
case 5 :
|
||||
# Create the object
|
||||
$this->HumanHostname = func_get_arg(0);
|
||||
$this->Host = func_get_arg(1);
|
||||
$this->User = func_get_arg(2);
|
||||
$this->Password = func_get_arg(3);
|
||||
$this->Client = func_get_arg(4);
|
||||
|
||||
$this->Database = "mysql"; # We have to define a dabatase when we connect, and the database must exists.
|
||||
break;
|
||||
|
||||
default :
|
||||
$db->query("select db_servers.* from db_servers, membres where membres.uid=$cuid and membres.db_server_id=db_servers.id;");
|
||||
if (!$db->next_record()) {
|
||||
$err->raise('db_user', _("There are no databases in db_servers for this user. Please contact your administrator."));
|
||||
die();
|
||||
}
|
||||
|
||||
# Create the object
|
||||
$this->HumanHostname = $db->f('name');
|
||||
$this->Host = $db->f('host');
|
||||
$this->User = $db->f('login');
|
||||
$this->Password = $db->f('password');
|
||||
$this->Client = $db->f('client');
|
||||
|
||||
$this->Database = "mysql"; # We have to define a dabatase when we connect, and the database must exist.
|
||||
break;
|
||||
}
|
||||
|
||||
# Create the object
|
||||
$this->HumanHostname = $db->f('name');
|
||||
$this->Host = $db->f('host');
|
||||
$this->User = $db->f('login');
|
||||
$this->Password = $db->f('password');
|
||||
$this->Client = $db->f('client');
|
||||
|
||||
$this->Database = "mysql"; # We have to define a dabatase when we connect, and the database must exist.
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1079,6 +1097,34 @@ class m_mysql {
|
|||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------- */
|
||||
/**
|
||||
* Return the size of each databases in a SQL Host given in parameter
|
||||
* @param $db_name the human name of the host
|
||||
* @param $db_host the host hosting the SQL databases
|
||||
* @param $db_login the login to access the SQL db
|
||||
* @param $db_password the password to access the SQL db
|
||||
* @param $db_client the client to access the SQL db
|
||||
* @return an array associating the name of the databases to their sizes : array(dbname=>size)
|
||||
*/
|
||||
function get_dbus_size($db_name,$db_host,$db_login,$db_password,$db_client) {
|
||||
global $db,$err;
|
||||
$err->log("mysql","get_dbus_size",$db_host);
|
||||
$this->dbus=new DB_users($db_name,$db_host,$db_login,$db_password,$db_client);
|
||||
$this->dbus->query("show databases;");
|
||||
$res=array();
|
||||
$d=array();
|
||||
while($this->dbus->next_record()) {
|
||||
$dbname=$this->dbus->f("Database");
|
||||
$c=mysql_query("SHOW TABLE STATUS FROM $dbname;");
|
||||
$size=0;
|
||||
while ($d=mysql_fetch_array($c)) {
|
||||
$size+=$d["Data_length"]+$d["Index_length"];
|
||||
}
|
||||
$res["$dbname"]="$size";
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
} /* Class m_mysql */
|
||||
|
||||
|
|
|
@ -5,42 +5,50 @@ require_once("/usr/share/alternc/panel/class/config_nochk.php");
|
|||
// On déverrouile le bureau AlternC :)
|
||||
@alternc_shutdown();
|
||||
|
||||
echo "---------------------------\n Generating size-cache for web accounts\n\n";
|
||||
global $db;
|
||||
|
||||
echo "\n---------------------------\n Generating size-cache for web accounts\n\n";
|
||||
$r=mysql_query("SELECT uid,login FROM membres;");
|
||||
while ($c=mysql_fetch_array($r)) {
|
||||
echo $c["login"]; flush();
|
||||
$size=exec("sudo /usr/lib/alternc/du.pl ".ALTERNC_HTML."/".substr($c["login"],0,1)."/".$c["login"]);
|
||||
mysql_query("REPLACE INTO size_web SET uid='".$c["uid"]."',size='$size';");
|
||||
$db->query("REPLACE INTO size_web SET uid='".$c["uid"]."',size='$size';");
|
||||
echo " done ($size KB) \n"; flush();
|
||||
}
|
||||
|
||||
echo "---------------------------\n Generating size-cache for MySQL databases\n\n";
|
||||
$r=mysql_query("SELECT uid,db FROM db;");
|
||||
while ($c=mysql_fetch_array($r)) {
|
||||
echo $c["uid"]."/".$c["db"]; flush();
|
||||
$s=mysql_query('SHOW TABLE STATUS FROM `'.$c["db"].'`');
|
||||
$size=0;
|
||||
while ($d=mysql_fetch_array($s)) {
|
||||
$size+=$d["Data_length"]+$d["Index_length"];
|
||||
}
|
||||
// $size/=1024;
|
||||
mysql_query("REPLACE INTO size_db SET db='".$c["db"]."',size='$size';");
|
||||
echo " done ($size B) \n"; flush();
|
||||
}
|
||||
|
||||
echo "---------------------------\n Generating size-cache for web accounts\n\n";
|
||||
$r=@mysql_query("SELECT uid, name FROM mailman;");
|
||||
if ($r) {
|
||||
echo "\n---------------------------\n Generating size-cache for MySQL databases\n\n";
|
||||
// We get all hosts on which sql users' DB are
|
||||
$r=mysql_query("select * from db_servers;");
|
||||
$tab=array();
|
||||
while ($c=mysql_fetch_array($r)) {
|
||||
echo $c["uid"]."/".$c["name"]; flush();
|
||||
$size1=exec("sudo /usr/lib/alternc/du.pl /var/lib/mailman/lists/".$c["name"]);
|
||||
$size2=exec("sudo /usr/lib/alternc/du.pl /var/lib/mailman/archives/private/".$c["name"]);
|
||||
$size3=exec("sudo /usr/lib/alternc/du.pl /var/lib/mailman/archives/private/".$c["name"].".mbox");
|
||||
$size=(intval($size1)+intval($size2)+intval($size3));
|
||||
mysql_query("REPLACE INTO size_mailman SET uid='".$c["uid"]."',list='".$c["name"]."', size='$size';");
|
||||
echo " done ($size KB) \n"; flush();
|
||||
$tab=$mysql->get_dbus_size($c["name"],$c["host"],$c["login"],$c["password"],$c["client"]);
|
||||
echo "++ Processing ".$c["name"]." ++\n";
|
||||
foreach ($tab as $dbname=>$size) {
|
||||
$db->query("REPLACE INTO size_db SET db='".$dbname."',size='$size';");
|
||||
echo " $dbname done ($size B) \n"; flush();
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo "---------------------------\n Generating size-cache for mailman\n\n";
|
||||
if ($db->query("SELECT uid, name FROM mailman;")) {
|
||||
$c=array();
|
||||
$d=array();
|
||||
if($db->num_rows()){
|
||||
while ($db->next_record()) {
|
||||
$cc[]=array("uid" => $db->f("uid"), "name" => $db->f("name"));
|
||||
}
|
||||
foreach ($cc as $c){
|
||||
echo $c["uid"]."/".$c["name"]; flush();
|
||||
$size1=exec("sudo /usr/lib/alternc/du.pl /var/lib/mailman/lists/".$c["name"]);
|
||||
$size2=exec("sudo /usr/lib/alternc/du.pl /var/lib/mailman/archives/private/".$c["name"]);
|
||||
$size3=exec("sudo /usr/lib/alternc/du.pl /var/lib/mailman/archives/private/".$c["name"].".mbox");
|
||||
$size=(intval($size1)+intval($size2)+intval($size3));
|
||||
$db->query("REPLACE INTO size_mailman SET uid='".$c["uid"]."',list='".$c["name"]."', size='$size';");
|
||||
echo " done ($size KB) \n"; flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// On relocke le bureau pour éviter un msg d'erreur.
|
||||
@sem_acquire( $alternc_sem );
|
||||
|
|
Loading…
Reference in New Issue