3 ###############################################################################
10 A wrapper around the pg_dump command that saves a table in the mig schema with a time stamp in the working directory.
14 B<mig-dump> [arguments...]
18 ###############################################################################
24 HOME PGHOST PGPORT PGUSER PGDATABASE MIGSCHEMA
25 MIGBASEWORKDIR MIGBASEGITDIR MIGGITDIR MIGWORKDIR
32 my $mig_bin = "$FindBin::Bin/";
33 use lib "$FindBin::Bin/";
35 use open ':encoding(utf8)';
37 pod2usage(-verbose => 2) if defined $ARGV[0] && $ARGV[0] eq '--help';
38 pod2usage(-verbose => 1) if ! $ARGV[1];
44 my $next_arg_is_table;
46 foreach my $arg (@ARGV) {
47 if ($arg eq '--table') {
48 $next_arg_is_table = 1;
51 if ($next_arg_is_table) {
53 $next_arg_is_table = 0;
58 my $outfilewpath = create_dumpfile_name($table);
60 my $syscmd = 'pg_dump --format plain --data-only --file ' . $outfilewpath . ' --table ' . $MIGSCHEMA . '.' . $table . ' ' . $PGUSER;
62 print "pgdump command: \n";
67 ####### beyond here be functions
69 sub create_dumpfile_name {
70 my $table_name = shift;
71 $table_name =~ s/\./_/;
72 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
74 my $date = $year . '-' . $mon . '-' . $mday;
75 my $dump_file = $table_name . ' ' . $date . '.pg';
76 $dump_file =~ s/ /_/g;
77 $dump_file = $MIGGITDIR . $dump_file;
78 print "$dump_file \n";
84 print STDERR "$0: $msg", "\n";