MySQL::Backup - Perl extension for making backups of mysql DBs.
use MySQL::Backup; my $mb = new MySQL::Backup('database','127.0.0.1','user','password',{'USE_REPLACE' => 1, 'SHOW_TABLE_NAMES' => 1}); print $mb->create_structure(); print $mb->data_backup();
MySQL::Backup should be useful for people, who needed in backuping mysql DBs by perl script and doesn't want to use mysqldump or doesn't able to do this.
MySQL::Backup
$mb->create_structure() - returns structure of current database
$mb->create_structure()
$mb->data_backup() returns a full DATA backup of current database
$mb->data_backup()
$mb->table_data($tablename) - get all data from the table with $tablename
$mb->table_data($tablename)
$mb->table_desc($tablename) - get a structure of inputed table
$mb->table_desc($tablename)
$mb->new_from_DBH($dbh) - if you have already DBI connection, you can use this
$mb->new_from_DBH($dbh)
$mb->run_restore_script($filename) - Just DROPs all from current DB and run all sql from the specified file (param is filepath to needed file)
$mb->run_restore_script($filename)
$mb->run_upgrade_script($filename) - opens file by set filepath, then analyzes differencies in proposed and current structures and tries to fix differencies in DB. For instance: you have 1 table in DB with 3 columns, and one string CREATE TABLE ... with same name in the file, but CREATE TABLE describes 4 columns,.. after running this you should have 4 columns in table in DB. Also, all INSERTs/REPLACEs from file will be executed(also, please be careful on execute stage all INSERTs will be changed to REPLACE)
$mb->run_upgrade_script($filename)
Params could be set on creating, like shown in example, or/and set/changed as you should see below:
$mb->{'param'}->{'USE_REPLACE'} - '1' means using REPLACE instead of INSERT
$mb->{'param'}->{'USE_REPLACE'}
$mb->{'param'}->{'SHOW_TABLE_NAMES'} - '1' means outputing a string in data_backup that marks actions on which table should be done
$mb->{'param'}->{'SHOW_TABLE_NAMES'}
$mb->{'param'}->{'tables'} - this param is a link to array with table names,.. can be used if you're needed to backup only few tables from DB (used by create_structure/data_backup)
$mb->{'param'}->{'tables'}
DBI, DBD::mysql and http://dev.mysql.com
Dmitry Nikolayev <dmitry@cpan.org>, http://perl.dp.ua/resume.html
Thanks for DotHost Hosting Provider: http://dothost.ru for their Tech. support.
Also, Thanks to Dree <dree@perl.it> for his comments and suggestions.
Copyright (C) 2006 by Dmitry Nikolayev
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install MySQL::Backup, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MySQL::Backup
CPAN shell
perl -MCPAN -e shell install MySQL::Backup
For more information on module installation, please visit the detailed CPAN module installation guide.