84 lines
2.1 KiB
PHP
Executable file
84 lines
2.1 KiB
PHP
Executable file
<?php
|
|
#php api-cli.php OP "$DB" "S{HOY}:${SUB_TAMANYO}:${RESULT}"
|
|
|
|
|
|
if ($argc < 3) {
|
|
die ("Faltan argumentos \napi.cli.php [INI|FIN] database tupla_status\n");
|
|
}
|
|
|
|
$OP = $argv[1];
|
|
$DB = $argv[2];
|
|
$HOY= 0;
|
|
$TAM= 0;
|
|
echo $argv[3]. "\n";
|
|
list($HOY, $TAM, $RES) = explode(':' , $argv[3]);
|
|
if (!isset($HOY) or !isset($TAM) or !isset($RES)) {
|
|
die ("Argumentos incorrectos\n");
|
|
}
|
|
$TAM=intval($TAM);
|
|
|
|
require_once ('./detail/Maestros.php');
|
|
$enlaceMaestro = ConectarMaestro();
|
|
if (!$enlaceMaestro) {
|
|
die ("Error conexion servidor Maestros\n");
|
|
}
|
|
mysql_select_db('db_trebol_centralizado',$enlaceMaestro);
|
|
|
|
require_once ('./detail/Conn.Respaldos.php');
|
|
$enlaceRespaldos = ConectarRespaldos();
|
|
mysql_select_db('sb_trebol_respaldos', $enlaceRespaldos);
|
|
|
|
/*
|
|
* Obtener nuestra identificacion de sucursal
|
|
*/
|
|
$sucursal['query']= <<<EOF
|
|
SELECT suc_id, suc_nombre, suc_nombre_bd, suc_conectado, suc_ip, suc_puerto FROM mae_sucursales WHERE suc_nombre_bd = "${DB}" and suc_id < 90
|
|
EOF;
|
|
|
|
$sucursal['res']= mysql_query($sucursal['query'], $enlaceMaestro);
|
|
if (mysql_num_rows($sucursal['res']) !== 1) {
|
|
die ('No se encuentra la sucursal correcta para '. $DB. ' .');
|
|
}
|
|
$suc_row = mysql_fetch_assoc($sucursal['res']);
|
|
mysql_close($enlaceMaestro);
|
|
|
|
$HORA=strftime('%H:%M:%S');
|
|
echo "${HORA} ";
|
|
|
|
switch ($OP) {
|
|
case 'INI': // INSERT
|
|
$Q = <<<EOF
|
|
INSERT INTO respaldos VALUES ( '${suc_row["suc_nombre_bd"]}', '$HOY', '$HORA', $TAM, $RES, 'SUB');
|
|
EOF;
|
|
echo $Q."\n";
|
|
$ins= mysql_query($Q, $enlaceRespaldos);
|
|
echo ' * '. mysql_error($enlaceRespaldos). "\n";
|
|
break;
|
|
|
|
case 'FIN': // UPDATE
|
|
$put_log='';
|
|
if (intval($RES) > 0) {
|
|
$put_log= @file_get_contents('_put.log');
|
|
$put_log= substr($put_log, -28);
|
|
$RES= -intval($RES);
|
|
} else {
|
|
$put_log= 'OK';
|
|
$RES= 1;
|
|
}
|
|
$msg= mysql_real_escape_string($put_log);
|
|
$Q = <<<EOF
|
|
UPDATE respaldos
|
|
SET resp_estado=${RES}, resp_hora='$HORA', resp_mensaje='$msg'
|
|
WHERE resp_suc_db= '${suc_row['suc_nombre_bd']}' AND resp_fecha='${HOY}';
|
|
EOF;
|
|
echo $Q."\n";
|
|
$upd= mysql_query($Q, $enlaceRespaldos);
|
|
break;
|
|
|
|
default:
|
|
die ("Operacion incorrecta\n");
|
|
break;
|
|
}
|
|
|
|
|
|
?>
|