Tag: hack

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
<?php

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

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

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

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

$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");
    bailout($logfile);
}

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


function bailout($logfile) {
    exec('konsole -e less -r '.$logfile);
    sleep(1);
    unlink($logfile);
    exit;
}

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

Any suggestion, improvement, criticism is welcome!

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…