Commit | Line | Data |
969049ba |
1 | #!/usr/bin/env perl |
354b1807 |
2 | |
354b1807 |
3 | =head1 NAME |
4 | |
5 | sqlt-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 | |
24 | This script uses SQL::Translator to parse the SQL schema and create a |
25 | Perl script that can connect to the database and dump the data as |
5a3f5c82 |
26 | INSERT statements (a la mysqldump) or MySQL's LOAD FILE syntax. You may |
27 | specify tables to "skip" (also using a "skiplike" regular expression) |
28 | and the generated dumper script will not have those tables. However, |
29 | these will also be options in the generated dumper, so you can wait to |
30 | specify these options when you dump your database. The database |
31 | username, password, and DSN can be hardcoded into the generated |
32 | script, or part of the DSN can be intuited from the "database" |
33 | argument. |
354b1807 |
34 | |
35 | =cut |
36 | |
37 | # ------------------------------------------------------------------- |
38 | |
39 | use strict; |
969049ba |
40 | use warnings; |
354b1807 |
41 | use Pod::Usage; |
42 | use Getopt::Long; |
43 | use SQL::Translator; |
aba9fea4 |
44 | use File::Basename qw(basename); |
354b1807 |
45 | |
da06ac74 |
46 | use vars '$VERSION'; |
11ad2df9 |
47 | $VERSION = '1.59'; |
da06ac74 |
48 | |
5a3f5c82 |
49 | my ( $help, $db, $skip, $skiplike, $db_user, $db_pass, $dsn ); |
354b1807 |
50 | GetOptions( |
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 | |
60 | pod2usage(0) if $help; |
61 | pod2usage( 'No database driver specified' ) unless $db; |
62 | $db_user ||= 'username'; |
63 | $db_pass ||= 'password'; |
64 | $dsn ||= "dbi:$db:_"; |
65 | |
5a3f5c82 |
66 | my $file = shift @ARGV or pod2usage( -msg => 'No input file' ); |
67 | my $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 |
79 | print $t->translate( $file ); |
354b1807 |
80 | |
354b1807 |
81 | exit(0); |
82 | |
83 | # ------------------------------------------------------------------- |
84 | |
85 | =pod |
86 | |
87 | =head1 AUTHOR |
88 | |
969049ba |
89 | Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>. |
354b1807 |
90 | |
91 | =head1 SEE ALSO |
92 | |
5a3f5c82 |
93 | perl, SQL::Translator, SQL::Translator::Producer::Dumper. |
354b1807 |
94 | |
95 | =cut |