/[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 83 by dpavlin, Thu Sep 11 19:57:14 2008 UTC revision 86 by dpavlin, Thu Sep 11 20:22:49 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 = 1;
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  }  }
# Line 58  while(<STDIN>) { Line 61  while(<STDIN>) {
61                  write_chunk;                  write_chunk;
62                  $name = " $1";                  $name = " $1";
63                  $name =~ s/\W+/ /g;                  $name =~ s/\W+/ /g;
64                    undef $d;
65                  $d = '';                  $d = '';
66          }          }
67          $d .= $_;          $d .= $_;
# Line 66  while(<STDIN>) { Line 70  while(<STDIN>) {
70  write_chunk;  write_chunk;
71    
72  git "git-commit -m '$database' '$database'";  git "git-commit -m '$database' '$database'";
73    
74    git "git-repack" if $repack;
75    

Legend:
Removed from v.83  
changed lines
  Added in v.86

  ViewVC Help
Powered by ViewVC 1.1.26