Smart MySQL backup

I’m currently sysadmin for a bunch of dedicated servers, mainly running LAMP stacks. One the main issues with running a dedicated server is backups (the other being security). Remote filesystem backup can be easily performed with ribs (or any other rsync-based backup tool). ribs only copies changed files and creates hard-link snapshots to make each backup appear as a full backup. The main problem with rsync&hard-link based backup is MySQL.

It’s not wise to directly backup MySQL files; MyIsam files can be backed-up individually but their restore is not always guaranteed. Shared InnoDb tablespaces are very large and are modified each time you look at them. Single-table InnoDb tablespaces (with innodb_fle_per_table in my.cnf) are cumbersome to restore. On top of all that, data can be in a non-consistent state, so the copied file is corrupted (and useless).

Continue reading…

Running Phing from NetBeans

I use NetBeans to write PHP code. One of my biggest concern was the inability to launch external shell scripts without leaving NB. I came up with a hack a few months ago, but it was a HACK… up until yesterday.

I discovered Command-shortcuts, an awesome NB plugin. It lets you launch any external command from NB. It also lets you pass a #{file} argument, so the command can operate on the file at hand.

The only problem was the inability to launch a command and pass it the base directory of the project. Command-shortcuts has a #{mainproject} parameter, but you need to define the project you are working on as a main project in NetBeans (seems like you need to do it every time you open the project – a sure way to waste time finding why it doesn’t work).

So i wrote a simple helper script to find the project base directory and invoke the Phing buildfile in that directory.

#!/usr/bin/php -q

$logfile = sprintf('/tmp/nbphing_helper.%d.log', getmypid());

if (! isset($argv[1])) {
    file_put_contents($logfile, "\n  No file specified\n\n");

if (! is_readable($argv[1])) {
    file_put_contents($logfile, "\n  File not found\n\n");

if (! isset($argv[2])) {
    file_put_contents($logfile, "\n  No target specified\n\n");

$search = $argv[1];
do {
    $search = dirname($search);
} while(! is_readable(sprintf('%s/build.xml', $search)) && strlen($search) > 2);

if (! is_readable(sprintf('%s/build.xml', $search))) {
    file_put_contents($logfile, "\n  build.xml not found\n\n");

exec('phing ' . $argv[2], $output);
file_put_contents($logfile, implode("\n", $output));

function bailout($logfile) {
    exec('konsole -e less -r '.$logfile);

It’s a dirty hack, but I can now invoke several phing build targets without leaving the IDE.

Any suggestion, improvement, criticism is welcome!

PHP is the most widely used language for web application development. In spite of this, nobody uses PHP to develop desktop apps. I suppose one of the main problems is the lack of an easy to install, prebuilt package. There were only a few win32 binary releases, and each of them was released after a long period of silence. This is not a criticism to php-gtk developers (a BIG THANK to everyone involved), but users always had the feeling of a dead project.

The real problem is the lack of enough developers, packagers, doc-writers, so I decided to contribute some documentation to build php-gtk on Windows.

It took me a few weeks and the recipe is very long and tedious. But it should be repeatable. The recipe for PHP 5.3 is on Github, so everyone can contribute to improve it.

Symfony2: the big picture

I started playing with Symfony2 when it was in beta. The biggest obstacle in my learning process was the lack of an architectural overview; something that would describe the flow of execution of every request, at least at a very coarse grain. I tried to read the official docs and various articles on the Net: I was able to do things but didn’t know how (and why) they worked – when they did. The immediate consequence was that I was almost always unable to adapt the examples to my specific needs.

Continue reading…

Phing e NetBeans

Come strumento di build/deploy per NetBeans, l’unica opzione è ant, tramite l’apposito plugin.

Per motivi che ignoro, sembra che a nessuno sia venuto in mente di realizzare un plugin per NetBeans che permetta di eseguire comandi shell qualsiasi. Figuriamoci se qualcuno possa aver fatto un plugin per Phing.

Dovendo fare di necessità virtù, ho riadattato un hack dal blog “My toy page”.

Continue reading…

TreeGrid with ExtJS 4

ExtJS has a lot of components to rapidly develop powerful web applications.
A few days back, I was faced with the need to display hierarchical data extracted from a database. I looked at several alternatives, but none of them was so full-featured and well-integrated as ExtJS is. So I developed a prototype to learn the basics of ExtJS 4 TreeGrid component.

Continue reading…

Converting color PDF to B/W

Recently I was faced with the conversion of color PDF to B/W only. This quick hack did the job:

gs -sDEVICE=psmono -dNOPAUSE -dBATCH -dNoCancel color.pdf
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dNoCancel -sOutputFile=mono.pdf

I converted a batch of single page PDFs, but it should also work with multipage files.

Closures bring concise and elegant solutions to a wide array of coding problems. A common use is in array operations; array_map(), array_filter() and similar functions all can take advantage of Closure expressiveness and elegance.

Before PHP 5.3 the same functionality could be implemented with callback functions or “manually” iterating over the arrays. I’m currently developing an application that manipulates large arrays and soon started speculating about which is the fastest approach.
Continue reading…

PhpDay 2011

È passato un anno senza scrivere niente: shame on me! Vista l’ottima impressione dell’anno scorso, quest’anno mi sono sobbarcato i 500Km necessari per il mio secondo phpDay. Tanta bella gente e un keynote davvero “storico” di Jacopo Romei.

Continue reading…

PhpDay: the day after

2 giorni al PhpDay 2010 (venerdì e sabato) assolutamente utili; forse era opportuno andare anche al giovedì. Location un po’ naive ma in vantaggio non c’erano problemi di traffico e parcheggio; connessione Internet veloce e… a lot of smart people.