/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 82 - (show annotations)
Thu Sep 11 18:44:04 2008 UTC (15 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 1221 byte(s)
experimental PostgreSQL dump splitter with git
as storage

1 #!/usr/bin/perl
2
3 # split PostgreSQL dump into individual files for backup with git
4 #
5 # 09/11/08 20:10:39 CEST Dobrica Pavlinusic <dpavlin@rot13.org>
6
7 use warnings;
8 use strict;
9
10 use Getopt::Long;
11 my $git = '/tmp/pgsql-git-backup/';
12 my $verbose = 0;
13 my $database = '';
14
15 my $usage = "Usage: $0 --database name < name-dump.sql\n";
16
17 GetOptions(
18 'git=s' => \$git,
19 'database=s' => \$database,
20 'verbose+' => \$verbose,
21 ) or die $usage;
22
23 die $usage unless $database;
24
25 my $nr = 0;
26 my $name = $database;
27 my $d;
28
29 sub write_chunk {
30 my $path = sprintf("%s/%02d%s.sql", $database, $nr++, $name);
31 open(my $fh, '>', $path) or die "can't open file $path: $!";
32 print $fh $d;
33 close($fh);
34 warn ">> $path ", -s $path, "\n" if $verbose;
35 system "git-add '$path'";
36 }
37
38 if ( ! -e $git ) {
39 mkdir $git or die "can't create $git: $!";
40 chdir $git;
41 system 'git-init-db';
42 }
43
44 if ( ! -e $database ) {
45 mkdir $database or die "can't create $database: $!";
46 # system "git-add '$database'";
47 # system "git-commit -m 'added $database directory' $database";
48 }
49
50 while(<STDIN>) {
51 if (/-- Name: (.+?);/) {
52 write_chunk;
53 $name = " $1";
54 $name =~ s/\W+/ /g;
55 $d = '';
56 }
57 $d .= $_;
58 }
59
60 write_chunk;
61
62 system "git-commit -m '$database' '$database'";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26