DBIx::Copy 0.02 - For copying database content from one db to another


use DBIx::Copy; use DBI;

my $dbh_source=DBI->connect(...); my $dbh_target=DBI->connect(...);

my %options=();

my $copy_handler= DBIx::Copy->new($dbh_source, $dbh_target, \%options);

$copy_handler->copy (['tabletobecopied', 'anothertabletobecopied', ...]);


For copying a DB. Future versions might handle mirroring as well, but it's generally better if the source might send over a transaction log somehow.

The current version takes a crude "select * from table" from the source table, and crudely puts it all into the destination table, with a "delete from table" and "insert into table values (?, ?, ?, ...)". Eventually column names are specified (option column_translation_table). There might be problems with this approach for all I know. Anyway, I think I can promise that the synopsis above will behave the same way also for future versions of DBIx::Copy.

Currently the module can only copy data content. Data definitions might be handled in a future version.



If a table called FOO in the source database should be called Bar in the destination database, it's possible to specify it in the options:

    $options{'table_tanslation_table'}={'FOO' => 'Bar'};


If the table FOO contains a column with the name "LASTUPDATEDTIMESTAMP", and we want to call it "LastUpdated" in the table Bar, it's possible to specify it:

        'ID' => 'id',
        'TITLE' => 'Title',
        'LASTUPDATEDTIMESTAMP' => 'LastUpdated'
        # _All_ columns you want to copy must be mentionated here.  I
        # will eventually fix a sub for initializing such a hash
        # reference.


DBIx::Copy->new will die unless it's feeded with at least two arguments.

copy will just return undef if it fails somewhere.

The exception will probably be raised within the DBI. By adjusting settings within the DBI object, the error handling might be improved. Check the options AutoCommit, PrintError and RaiseError.

Currently the module is optimisticly lacking all kind of locking. This will have to be done outside the module.

Be aware that the testing script following this package is NOT GOOD ENOUGH, it should be tested by hand using the synopsis above.



The module should also be capable of copying data definitions


It should be possible to avoid deleting the old table before inserting a new. The module should (by first running a select call) avoid inserting duplicates. This option will only insert new rows, not update old ones.


Do not delete old data in the destination table unless it is to be replaced by new data from the source table.

max_timestamp / mirror

Check the timestamps and only import rows that has been modified after max_timestamp (typically the timestamp for the last import).

mirror will try to fetch the last timestamp from the database, and store the new timestamp in the database.


If the same row is edited in both databases, try to merge the result.


Locking should be supported somehow.


Except for all the "buts" and "ifs" and missing features above - none yet - but this module is very poorly tested!


Copyright (c) 2000 Tobias Brox. All rights reserved. This program is released under the GNU Public License. It might also be released under The Artistic License if you send me a mail why GPL is insufficient.


Tobias Brox <>. Comments, bug reports, patches and flames are appreciated.