svk-commitTn2OH.tmp
[dbsrgits/SQL-Translator.git] / bin / sqlt-dumper
CommitLineData
354b1807 1#!/usr/bin/perl
2
3# -------------------------------------------------------------------
821a0fde 4# $Id$
354b1807 5# -------------------------------------------------------------------
478f608d 6# Copyright (C) 2002-2009 SQLFairy Authors
354b1807 7#
8# This program is free software; you can redistribute it and/or
9# modify it under the terms of the GNU General Public License as
10# published by the Free Software Foundation; version 2.
11#
12# This program is distributed in the hope that it will be useful, but
13# WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15# General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20# 02111-1307 USA
21# -------------------------------------------------------------------
22
23=head1 NAME
24
25sqlt-dumper - create a dumper script from a schema
26
27=head1 SYNOPSIS
28
29 sqlt-dumper -d Oracle [options] schema.sql > dumper.pl
30
31 ./dumper.pl > data.sql
32
33 Options:
34
5a3f5c82 35 -h|--help Show help and exit
36 --skip=t1[,t2] Skip tables in comma-separated list
37 --skiplike=regex Skip tables matching the regular expression
38 -u|--user Database username
39 -p|--password Database password
40 --dsn DSN for DBI
354b1807 41
42=head1 DESCRIPTION
43
44This script uses SQL::Translator to parse the SQL schema and create a
45Perl script that can connect to the database and dump the data as
5a3f5c82 46INSERT statements (a la mysqldump) or MySQL's LOAD FILE syntax. You may
47specify tables to "skip" (also using a "skiplike" regular expression)
48and the generated dumper script will not have those tables. However,
49these will also be options in the generated dumper, so you can wait to
50specify these options when you dump your database. The database
51username, password, and DSN can be hardcoded into the generated
52script, or part of the DSN can be intuited from the "database"
53argument.
354b1807 54
55=cut
56
57# -------------------------------------------------------------------
58
59use strict;
60use Pod::Usage;
61use Getopt::Long;
62use SQL::Translator;
aba9fea4 63use File::Basename qw(basename);
354b1807 64
5a3f5c82 65my ( $help, $db, $skip, $skiplike, $db_user, $db_pass, $dsn );
354b1807 66GetOptions(
67 'h|help' => \$help,
68 'd|f|from|db=s' => \$db,
354b1807 69 'skip:s' => \$skip,
5a3f5c82 70 'skiplike:s' => \$skiplike,
354b1807 71 'u|user:s' => \$db_user,
72 'p|password:s' => \$db_pass,
73 'dsn:s' => \$dsn,
74) or pod2usage;
75
76pod2usage(0) if $help;
77pod2usage( 'No database driver specified' ) unless $db;
78$db_user ||= 'username';
79$db_pass ||= 'password';
80$dsn ||= "dbi:$db:_";
81
5a3f5c82 82my $file = shift @ARGV or pod2usage( -msg => 'No input file' );
83my $t = SQL::Translator->new(
84 from => $db,
85 to => 'Dumper',
86 producer_args => {
87 skip => $skip,
88 skiplike => $skiplike,
89 db_user => $db_user,
90 db_password => $db_pass,
91 dsn => $dsn,
354b1807 92 }
5a3f5c82 93);
354b1807 94
5a3f5c82 95print $t->translate( $file );
354b1807 96
354b1807 97exit(0);
98
99# -------------------------------------------------------------------
100
101=pod
102
103=head1 AUTHOR
104
105Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
106
107=head1 SEE ALSO
108
5a3f5c82 109perl, SQL::Translator, SQL::Translator::Producer::Dumper.
354b1807 110
111=cut