source: xas-model/trunk/lib/XAS/Apps/Database/ExtractData.pm @ ec669f7d855f211d1a774ab3048a0a59d4356f13

Revision ec669f7d855f211d1a774ab3048a0a59d4356f13, 2.5 KB checked in by Kevin L. Esteb <kevin@…>, 6 years ago (diff)

Corrected documentation

  • Property mode set to 100644
Line 
1package XAS::Apps::Database::ExtractData;
2
3our $VERSION = '0.02';
4
5use Try::Tiny;
6use XAS::Class
7  version   => $VERSION,
8  base      => 'XAS::Lib::App',
9  accessors => 'table schema file'
10;
11
12# ----------------------------------------------------------------------
13# Public Methods
14# ----------------------------------------------------------------------
15
16sub parse_file {
17    my $self = shift;
18
19    my $fh;
20    my $table = $self->table;
21    my $schema = $self->schema;
22
23    open($fh, "<", $self->file);
24
25    while (<$fh>) {
26
27        if ($_ =~ m/^COPY $table \(/ ) {
28
29            printf("SET search_path = %s, pg_catalog;\n", $schema);
30            print $_;
31
32            while (<$fh>) {
33
34                print $_;
35
36                return if ($_ =~ m/^\\\./);
37
38            }
39
40        }
41
42    }
43
44}
45
46sub main {
47    my $self = shift;
48
49    $self->log->debug('starting main section');
50
51    $self->parse_file();
52
53    $self->log->debug('ending main section');
54
55}
56
57sub options {
58    my $self = shift;
59
60    $self->{file}   = '';
61    $self->{table}  = '';
62    $self->{schema} = '';
63
64    return {
65        'file=s'   => \$self->{file},
66        'table=s'  => \$self->{table},
67        'schema=s' => \$self->{schema},
68    };
69
70}
71
72# ----------------------------------------------------------------------
73# Private Methods
74# ----------------------------------------------------------------------
75
761;
77
78__END__
79
80=head1 NAME
81
82XAS::Apps::Database::ExtractData - This module will extract data from a PostgreSQL dump file
83
84=head1 SYNOPSIS
85
86 use XAS::Apps::Database::ExtractData;
87
88 my $app = XAS::Apps::Database::ExtractData->new(;
89    -throws  => 'xas-pg-extract-data',
90 );
91
92 exit $app->run();
93
94=head1 DESCRIPTION
95
96This module will extract the "copy" statements from a PostgreSQL pg_dumpall file.
97This is based on the table name. This data is then suitable to populate
98an "empty" database that already has a schema defined. This allows
99you to do selective restores.
100
101=head1 OPTIONS
102
103The following options are used to configure the module.
104
105=head2 --file
106
107Defines the dump file to use.
108
109=head2 --table
110
111Defines which table to extract data from.
112
113=head2 --schema
114
115Defines the database schema to use.
116
117=head1 SEE ALSO
118
119=over 4
120
121=item bin/xas-pg-extract-data
122
123=item L<XAS|XAS>
124
125=back
126
127=head1 AUTHOR
128
129Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt>
130
131=head1 COPYRIGHT AND LICENSE
132
133Copyright (C) 2012 by Kevin L. Esteb
134
135This library is free software; you can redistribute it and/or modify
136it under the same terms as Perl itself, either Perl version 5.8.8 or,
137at your option, any later version of Perl 5 you may have available.
138
139=cut
Note: See TracBrowser for help on using the repository browser.