lunes, 6 de mayo de 2013

Eivissa des de la ISS (Eivissa from the ISS)

L'expedició 35 de l'Estació Espacial Internacional va prendre aquesta imatge de la nostra estimada casa el 22/03/2013.



Font:
Nasa: International Space Station Imagery

lunes, 29 de abril de 2013

Apache httpd CentOS Certificate not verified: 'Server-Cert'

En CentOS, si de repente tenéis el servidor web caido y os sale este error en /var/log/nss_error_log es porque está instalado el módulo mod_nss y aunque el httpd no lo está cargando, detecta que el certificado de prueba que instala nss automáticamente está caducado.

La solución es desinstalar el módulo

yum remove mod_nss


Ejemplo de error:

[Mon Apr 29 13:37:24 2013] [error] Certificate not verified: 'Server-Cert'
[Mon Apr 29 13:37:24 2013] [error] SSL Library Error: -8181 Certificate has expired
[Mon Apr 29 13:37:24 2013] [error] Unable to verify certificate 'Server-Cert'. Add "NSSEnforceValidCerts off" to nss.conf so the server can start until the problem can be resolved.


Bug en RH:

https://bugzilla.redhat.com/show_bug.cgi?format=multiple&id=711085

miércoles, 6 de marzo de 2013

Backup de los procedimientos almacenados mysql

El mysqldump no copia los stored procedures por defecto pero si los triggers, es decir, los parámetros por defecto son:

--routines FALSE por defecto
--triggers TRUE por defecto

Para volcar sólo los procedimientos almacenados:

mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt database > procedimientos.sql

Para importar los procedimientos a otra db:


mysql database < procedimientos.sql

Para hacer un backup de datos y triggers que también copie los procedimientos almacenados:


mysqldump --routines outputfile.sql


Fuente:
http://www.ducea.com/2007/07/25/dumping-mysql-stored-procedures-functions-and-triggers/

jueves, 28 de febrero de 2013

Depurar procedimientos almacenados mysql

Depurar procedimientos de bases de datos suele ser una tarea ingrata a no ser que tengamos alguna herramienta de desarrollo. Pero aún estas herramientas suelen modificar internamente el procedimiento para efectuar el depurado además de crear multitud de tablas intermedias para guardar el estado de las variables en cualquier punto de la ejecución.

Si no te interesa este enfoque y sólo necesitas ir haciendo un log de lo que ocurre propongo el siguiente sistema que he ido mejorando a partir de diversas fuentes y experiencias.

La idea se basa en la creación de una tabla temporal donde vamos realizando el log mediante una llamada al procedimiento doLog(msg).

Primero creamos una tabla de configuración:

CREATE TABLE `internal_config` (
`debug` tinyint(4) NOT NULL DEFAULT '1'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

insert into internal_config(debug) values(0);

Que nos servirá para activar/desactivar el debug con:

update internal_config set debug=true;

El procedimiento que crea la tabla temporal es:

CREATE PROCEDURE `setupTmpLog`()
BEGIN
 CREATE TEMPORARY TABLE IF NOT EXISTS tmplog(
   lin integer NOT NULL AUTO_INCREMENT primary key,
   msg VARCHAR(512)
 ) ENGINE = MEMORY;
END

y el que escribe el log:

CREATE PROCEDURE `doLog`(IN logMsg VARCHAR(512))
BEGIN
 declare do_debug bool default false;
 DECLARE CONTINUE HANDLER FOR NOT FOUND SET do_debug=false;
 DECLARE CONTINUE HANDLER FOR 1146 -- Table not found
  BEGIN
    CALL setupTmpLog();
    INSERT INTO tmplog(msg) VALUES ('resetup tmp table');
    INSERT INTO tmplog(msg) VALUES (logMsg);
  END;

 select debug from internal_config limit 1 into do_debug;

 -- escribimos en el log solo si debug esta activado
 if (do_debug) then
   INSERT INTO tmplog(msg) VALUES (logMsg);
 end if;
END

y finalmente, un procedimiento que nos muestra el log (con el último mensaje primero) y después borra la tabla:

CREATE PROCEDURE `view_log`()
BEGIN
  DECLARE CONTINUE HANDLER FOR 1146 -- Table not found
   BEGIN
    CALL setupTmpLog();
   end;

   select msg from tmplog order by lin desc;

   drop table tmplog;
END

Ya lo tenemos todo, para ir logeando en nuestros procedimientos sólo tenemos que llamar a doLog así:

call doLog(concat("Hola", " que ", " tal " ));

Y cuando queramos ver (y limpiar) el log hacemos:

call view_log();

Espero que os sirva. Good Luck ;-)


Fuentes:
http://www.drdobbs.com/database/debugging-mysql-stored-procedures/218100564?pgno=1

jueves, 21 de febrero de 2013

entender los joins sql gráficamente

Este gráfico puede servirnos para recordar qué partes se incluyen o se excluyen en los diferentes tipos de joins:


  1. INNER JOIN
  2. LEFT JOIN
  3. RIGHT JOIN
  4. OUTER JOIN
  5. LEFT JOIN EXCLUDING INNER JOIN
  6. RIGHT JOIN EXCLUDING INNER JOIN
  7. OUTER JOIN EXCLUDING INNER JOIN





Fuente:
Visual representation of SQL joins

sábado, 22 de diciembre de 2012

Use zip

The following examples illustrate typical uses of the command zip for packaging a set of files into an "archive" file, also called "zip file". The command uses the standard zip file format. The archive files can therefore be used to tranfer files and directories between commonly used operating systems. 

 zip archivefile1 doc1 doc2 doc3
This command creates a file "archivefile1.zip" which contains a copy of the files doc1, doc2, and doc3, located in the current directory. 

 zip archivefile1 *
This command creates a file "archivefile1.zip" which contains a copy of all files in the current directory in compressed form. However, files whose name starts with a "." are not included. The extension ".zip" is added by the program. 

 zip archivefile1 .* *
This version includes the files that start with a dot. But subdirectories are still not included. 

 zip -r archivefile1 .
This copies the current directory, including all subdirectories into the archive file. 

 zip -r archivefile2 papers
This copies the directory "papers", located in the current directory, into "archivefile2.zip". 

 zip -r archivefile3 /home/joe/papers
This copies the directory "/home/joe/papers" into "archivefile3.zip". Since in this case the absolute path is given, it doesn't matter what the current directory is, except that the zip file will be created there.
The command unzip extracts the files from the zip file.
 unzip archivefile1.zip
This writes the files extracted from "archivefile1.zip" to the current directory.