NAME
DBIx::Admin::BackupRestore
- Back-up all tables in a db to XML, and restore them
Synopsis
use DBIx::Admin::BackupRestore;
# Backup.
open(OUT, "> $file_name") || die("Can't open(> $file_name): $!");
print OUT DBIx::Admin::BackupRestore -> new(dbh => $dbh) -> backup('db_name');
close OUT;
# Restore.
DBIx::Admin::BackupRestore -> new(dbh => $dbh) -> restore($file_name);
Description
DBIx::Admin::BackupRestore
is a pure Perl module.
It exports all data in all tables from one database to an XML file.
Then that file can be imported into another database, possibly under a different database server.
Warning: It is designed on the assumption you have a stand-alone script which creates an appropriate set of empty tables on the destination database server. You run that script, and then run this module in 'restore' mode.
This module is used almost daily to transfer a MySQL database under MS Windows to a Postgres database under Linux.
Similar modules are discussed below.
Distributions
This module is available both as a Unix-style distro (*.tgz) and an ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file.
See http://savage.net.au/Perl-modules.html for details.
See http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and installing each type of distro.
Constructor and initialization
new(...) returns a DBIx::Admin::BackupRestore
object.
This is the class's contructor.
Usage: DBIx::Admin::BackupRestore -> new().
This method takes a set of parameters. Only the dbh parameter is mandatory.
For each parameter you wish to use, call new as new(param_1 => value_1, ...)
.
- clean
-
The default value is 0.
If new is called as
new(clean => 1)
, the backup phase deletes any characters outside the range 20 .. 7E (hex).The restore phase ignores this parameter.
This parameter is optional.
- dbh
-
This is a database handle.
This parameter is mandatory.
- fiddle_timestamp
-
The default value is 1.
If the value of this parameter is 0, then
restore()
does not fiddle the value of fields of type timestamp.If the value of the parameter is 1, then
restore()
fiddles the value of fields of type timestamp in this manner:This parameter is optional.
- skip_tables
-
The default value is [].
If new is called as
new(skip_tables => ['some_table_name'])
, the restore phase does not restore the tables named in the call tonew()
.This option is designed to work with CGI scripts using the module CGI::Sessions.
Now, the CGI script can run with the current CGI::Session data, and stale CGI::Session data is not restored from the XML file.
This parameter is optional.
- verbose
-
The default value is 0.
If new is called as
new(verbose => 1)
, the backup and restore phases both print the names of the tables to STDERR.When beginning to use this module, you are strongly encouraged to use the verbose option as a progress monitor.
This parameter is optional.
Method: backup($database_name)
Returns a potentially-huge string of XML.
You would normally write this straight to disk.
The database name is passed in here to help decorate the XML.
Method: restore($file_name)
Returns an array ref of imported table names. They are sorted by name.
Opens and reads the given file, presumably one output by a previous call to backup().
Example code
See the examples/ directory in the distro.
There are 2 demo programs:
Related Modules
On CPAN I can see 4 modules which obviously offer similar features - there may be others.
Of these, DBIx::XML_RDB is the only one I have experimented with. My thanks to Matt Sergeant for that module.
I have effectively extended his module to automatically handle all tables, and to handle importing too.
Required Modules
Carp.
Changes
See Changes.txt.
Author
DBIx::Admin::BackupRestore
was written by Ron Savage <ron@savage.net.au> in 2004.
Home page: http://savage.net.au/index.html
Copyright
Australian copyright (c) 2004, Ron Savage. All rights reserved.
All Programs of mine are 'OSI Certified Open Source Software';
you can redistribute them and/or modify them under the terms of
The Artistic License, a copy of which is available at:
http://www.opensource.org/licenses/index.html