Não sei se existe algo melhor para isto, mas este fui eu que escrevi em perl. O objectivo da aplicação é fazer um backup selecionado das tabelas de uma base de dados, cria um .sql separado para cada uma das tabelas.

Not sure if already exists something bette for backing up Mysql Tables from a database but I wrote this one on Perl. The objective of the application is to do a backup of every table in the database to a file with the name of the table.
Requires from cpan:

  • DateTime
  • Time::Format
  • Time::Format_XS
  • Date::Manip
  • Time::Format

#!/usr/bin/perl -w

use strict;
use CGI qw(:standard);
use DBI;
use Time::Format qw(%time %strftime %manip); # DateTime Time::Format Time::Format_XS Date::Manip Time::Format
use File::Path;
use Socket;
use Sys::Hostname;
my $host = hostname();

print ” Backup Utility for MySQL (c) Netcrash \n”;
print ” Time: “.$time{’yyyy-mm-dd’}.”\n”;

my $dbh = DBI->connect(’DBI:mysql:users:127.0.0.1′,’root’,”);
my $tablesufix = $time{’_yyyy_m’};
my $tday = $time{’yyyy-mm-dd’};
my $password = ”; # –password=xxxx
my $host = ”; # -h host
my $userdump = ”; # user

chdir(’/tmp/’);
mkpath ‘./backup-’.$tday.’/';

my @tables = $dbh->tables();
my @targets = ( ‘users’, ‘webpages’);

foreach my $tble (@tables) {
$tble =~ s/`//gi;
print $tble;
if ( $tble =~ m/$tablesufix$/ ) {
system(’/usr/bin/mysqldump ‘.$host.’ -u ‘.$userdump.’ ‘. $password .’ users ‘.$tble.’ > ./backup-’.$tday.’/’.$tble.’.sql’);
print ” ++++++++”;
}

foreach my $t ( @targets ) {
if ( $tble =~ m/$t/ ) {
system(’/usr/bin/mysqldump ‘.$host.’ -u ‘.$userdump.’ ‘. $password .’ users ‘.$tble.’ > ./backup-’.$tday.’/’.$tble.’.sql’);
print ” ++++”;
}
}

print “\n”;
}

print ” End script \n”;