/[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 82 by dpavlin, Thu Sep 11 18:44:04 2008 UTC revision 85 by dpavlin, Thu Sep 11 20:16:05 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 = '';
# Line 26  my $nr = 0; Line 27  my $nr = 0;
27  my $name = $database;  my $name = $database;
28  my $d;  my $d;
29    
30    sub git {
31            my $cmd = shift or die "no cmd?";
32            system($cmd) == 0 or die "$cmd FAILED $?";
33    }
34    
35  sub write_chunk {  sub write_chunk {
36          my $path = sprintf("%s/%02d%s.sql", $database, $nr++, $name);          my $path = sprintf("%s/%04d%s.sql", $database, $nr++, $name);
37          open(my $fh, '>', $path) or die "can't open file $path: $!";          open(my $fh, '>', $path) or die "can't open file $path: $!";
38          print $fh $d;          print $fh $d;
39          close($fh);          close($fh);
40          warn ">> $path ", -s $path, "\n" if $verbose;          warn ">> $path ", -s $path, "\n" if $verbose;
41          system "git-add '$path'";          git "git-add '$path'";
42  }  }
43    
44  if ( ! -e $git ) {  mkdir $git if ! -e $git;
45          mkdir $git or die "can't create $git: $!";  
46          chdir $git;  chdir $git;
47          system 'git-init-db';  warn "## using $git\n" if $verbose;
48  }  
49    git 'git-init-db' if ! -e "$git/.git";
50    
51  if ( ! -e $database ) {  if ( ! -e $database ) {
52          mkdir $database or die "can't create $database: $!";          mkdir $database;
53  #       system "git-add '$database'";  #       git "git-add '$database'";
54  #       system "git-commit -m 'added $database directory' $database";  #       git "git-commit -m 'added $database directory' $database";
55  }  }
56    
57  while(<STDIN>) {  while(<STDIN>) {
# Line 52  while(<STDIN>) { Line 59  while(<STDIN>) {
59                  write_chunk;                  write_chunk;
60                  $name = " $1";                  $name = " $1";
61                  $name =~ s/\W+/ /g;                  $name =~ s/\W+/ /g;
62                    undef $d;
63                  $d = '';                  $d = '';
64          }          }
65          $d .= $_;          $d .= $_;
# Line 59  while(<STDIN>) { Line 67  while(<STDIN>) {
67    
68  write_chunk;  write_chunk;
69    
70  system "git-commit -m '$database' '$database'";  git "git-commit -m '$database' '$database'";

Legend:
Removed from v.82  
changed lines
  Added in v.85

  ViewVC Help
Powered by ViewVC 1.1.26