Remove copyright headers from individual scripts
[dbsrgits/SQL-Translator.git] / script / sqlt-dumper
CommitLineData
969049ba 1#!/usr/bin/env perl
354b1807 2
354b1807 3=head1 NAME
4
5sqlt-dumper - create a dumper script from a schema
6
7=head1 SYNOPSIS
8
9 sqlt-dumper -d Oracle [options] schema.sql > dumper.pl
10
11 ./dumper.pl > data.sql
12
13 Options:
14
5a3f5c82 15 -h|--help Show help and exit
16 --skip=t1[,t2] Skip tables in comma-separated list
17 --skiplike=regex Skip tables matching the regular expression
18 -u|--user Database username
19 -p|--password Database password
20 --dsn DSN for DBI
354b1807 21
22=head1 DESCRIPTION
23
24This script uses SQL::Translator to parse the SQL schema and create a
25Perl script that can connect to the database and dump the data as
5a3f5c82 26INSERT statements (a la mysqldump) or MySQL's LOAD FILE syntax. You may
27specify tables to "skip" (also using a "skiplike" regular expression)
28and the generated dumper script will not have those tables. However,
29these will also be options in the generated dumper, so you can wait to
30specify these options when you dump your database. The database
31username, password, and DSN can be hardcoded into the generated
32script, or part of the DSN can be intuited from the "database"
33argument.
354b1807 34
35=cut
36
37# -------------------------------------------------------------------
38
39use strict;
969049ba 40use warnings;
354b1807 41use Pod::Usage;
42use Getopt::Long;
43use SQL::Translator;
aba9fea4 44use File::Basename qw(basename);
354b1807 45
da06ac74 46use vars '$VERSION';
11ad2df9 47$VERSION = '1.59';
da06ac74 48
5a3f5c82 49my ( $help, $db, $skip, $skiplike, $db_user, $db_pass, $dsn );
354b1807 50GetOptions(
51 'h|help' => \$help,
52 'd|f|from|db=s' => \$db,
354b1807 53 'skip:s' => \$skip,
5a3f5c82 54 'skiplike:s' => \$skiplike,
354b1807 55 'u|user:s' => \$db_user,
56 'p|password:s' => \$db_pass,
57 'dsn:s' => \$dsn,
58) or pod2usage;
59
60pod2usage(0) if $help;
61pod2usage( 'No database driver specified' ) unless $db;
62$db_user ||= 'username';
63$db_pass ||= 'password';
64$dsn ||= "dbi:$db:_";
65
5a3f5c82 66my $file = shift @ARGV or pod2usage( -msg => 'No input file' );
67my $t = SQL::Translator->new(
68 from => $db,
69 to => 'Dumper',
70 producer_args => {
71 skip => $skip,
72 skiplike => $skiplike,
73 db_user => $db_user,
74 db_password => $db_pass,
75 dsn => $dsn,
354b1807 76 }
5a3f5c82 77);
354b1807 78
5a3f5c82 79print $t->translate( $file );
354b1807 80
354b1807 81exit(0);
82
83# -------------------------------------------------------------------
84
85=pod
86
87=head1 AUTHOR
88
969049ba 89Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>.
354b1807 90
91=head1 SEE ALSO
92
5a3f5c82 93perl, SQL::Translator, SQL::Translator::Producer::Dumper.
354b1807 94
95=cut