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