/[scripts]/trunk/pgsql-git-backup.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/pgsql-git-backup.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 84 by dpavlin, Thu Sep 11 19:59:52 2008 UTC revision 87 by dpavlin, Thu Sep 11 20:37:58 2008 UTC
# Line 8  use warnings; Line 8  use warnings;
8  use strict;  use strict;
9    
10  use Getopt::Long;  use Getopt::Long;
11    use Fatal qw/:void open close mkdir chdir/;
12  my $git = '/tmp/pgsql-git-backup/';  my $git = '/tmp/pgsql-git-backup/';
13  my $verbose = 0;  my $verbose = 0;
14  my $database = '';  my $database = '';
15    my $repack = 0;
16    
17  my $usage = "Usage: $0 --database name < name-dump.sql\n";  my $usage = "Usage: $0 --database name < name-dump.sql\n";
18    
19  GetOptions(  GetOptions(
20          'git=s'                 => \$git,          'git=s'         => \$git,
21          'database=s'    => \$database,          'database=s'    => \$database,
22          'verbose+'              => \$verbose,          'verbose+'      => \$verbose,
23            'repack'        => \$repack,
24  ) or die $usage;  ) or die $usage;
25    
26  die $usage unless $database;  die $usage unless $database;
# Line 32  sub git { Line 35  sub git {
35  }  }
36    
37  sub write_chunk {  sub write_chunk {
38          my $path = sprintf("%s/%02d%s.sql", $database, $nr++, $name);          my $path = sprintf("%s/%04d%s.sql", $database, $nr++, $name);
39          open(my $fh, '>', $path) or die "can't open file $path: $!";          open(my $fh, '>', $path) or die "can't open file $path: $!";
40          print $fh $d;          print $fh $d;
41          close($fh);          close($fh);
# Line 40  sub write_chunk { Line 43  sub write_chunk {
43          git "git-add '$path'";          git "git-add '$path'";
44  }  }
45    
46  if ( ! -e $git ) {  mkdir $git if ! -e $git;
47          mkdir $git or die "can't create $git: $!";  
48          git 'git-init-db';  chdir $git;
49  }  warn "## using $git\n" if $verbose;
50    
51  chdir($git) or die "can't chdir $git: $!";  git 'git-init-db' if ! -e "$git/.git";
52    
53  if ( ! -e $database ) {  if ( ! -e $database ) {
54          mkdir $database or die "can't create $database: $!";          mkdir $database;
55  #       git "git-add '$database'";  #       git "git-add '$database'";
56  #       git "git-commit -m 'added $database directory' $database";  #       git "git-commit -m 'added $database directory' $database";
57  }  }
58    
59  while(<STDIN>) {  while(<STDIN>) {
60          if (/-- Name: (.+?);/) {          if (/--.*Name: (\w+);.*Schema: (\w+)/) {
61                  write_chunk;                  write_chunk;
62                  $name = " $1";                  $name = ' ' . $2 . '.' . $1;
                 $name =~ s/\W+/ /g;  
63                  undef $d;                  undef $d;
64                  $d = '';                  $d = '';
65          }          }
# Line 67  while(<STDIN>) { Line 69  while(<STDIN>) {
69  write_chunk;  write_chunk;
70    
71  git "git-commit -m '$database' '$database'";  git "git-commit -m '$database' '$database'";
72    
73    git "git-repack" if $repack;
74    

Legend:
Removed from v.84  
changed lines
  Added in v.87

  ViewVC Help
Powered by ViewVC 1.1.26