source: xas-model/trunk/lib/XAS/Apps/Database/ExtractGlobals.pm @ 5250ce3bd7dfd5e59c99936400210013b992b151

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

Added procedures for manipulating Postgress database backup files

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