/[rserv]/bin/Replicate
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /bin/Replicate

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Tue Aug 5 09:20:08 2003 UTC (20 years, 10 months ago) by dpavlin
Branch: MAIN
CVS Tags: debian
Changes since 1.1: +4 -2 lines
change paths to support Debian

1 dpavlin 1.2 #!/usr/bin/perl
2 dpavlin 1.1 # Replicate
3     # Vadim Mikheev, (c) 2000, PostgreSQL Inc.
4    
5     eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
6     & eval 'exec perl -S $0 $argv:q'
7     if 0;
8    
9 dpavlin 1.2 use lib "/usr/share/postgresql/contrib";
10 dpavlin 1.1
11     use IO::File;
12     use Getopt::Long;
13     use RServ;
14    
15     $| = 1;
16    
17     $result = GetOptions("debug!", "verbose!", "help", "snapshot=s",
18     "masterhost=s", "slavehost=s", "host=s",
19     "masteruser=s", "slaveuser=s", "user=s",
20     "masterpassword=s", "slavepassword=s", "password=s");
21    
22     my $debug = $opt_debug || 0;
23     my $verbose = $opt_verbose || 0;
24     my $snapshot = $opt_snapshot || "__Snapshot";
25    
26     if (defined($opt_help) || (scalar(@ARGV) < 2)) {
27     print "Usage: $0 --snapshot=file --host=name --user=name --password=string masterdb slavedb\n";
28     print "\t--masterhost=name --masteruser=name --masterpassword=string\n";
29     print "\t--slavehost=name --slaveuser=name --slavepassword=string\n";
30     exit ((scalar(@ARGV) < 2)? 1:0);
31     }
32    
33     my $master = $ARGV[0] || "master";
34     my $slave = $ARGV[1] || "slave";
35     my $server = 0;
36    
37     my $minfo = "dbname=$master";
38     $minfo = "$minfo host=$opt_masterhost" if (defined($opt_masterhost));
39     $minfo = "$minfo user=$opt_masteruser" if (defined($opt_masteruser));
40     $minfo = "$minfo password=$opt_masterpassword" if (defined($opt_masterpassword));
41     my $sinfo = "dbname=$slave";
42     $sinfo = "$sinfo host=$opt_slavehost" if (defined($opt_slavehost));
43     $sinfo = "$sinfo user=$opt_slaveuser" if (defined($opt_slaveuser));
44     $sinfo = "$sinfo password=$opt_slavepassword" if (defined($opt_slavepassword));
45    
46     print "Master connection is $minfo\n" if ($debug);
47     print "Slave connection is $sinfo\n" if ($debug);
48    
49     my $mconn = Pg::connectdb($minfo);
50     my $sconn = Pg::connectdb($sinfo);
51    
52 dpavlin 1.2 $RServ::quiet = !$verbose;
53    
54 dpavlin 1.1 SyncSync($mconn, $sconn);
55    
56     my $outf = new IO::File;
57     open $outf, ">$snapshot";
58     print "\n>>>>>>>>>>>>> Prepare Snapshot\n\n" if ($verbose);
59     $res = PrepareSnapshot($mconn, $outf, $server);
60     close $outf;
61     die "\n>>>>>>>>>>>>> ERROR\n" if $res < 0;
62     if ($res == 0)
63     {
64     print "\n>>>>>>>>>>>>> DBases are sync-ed\n" if ($verbose);
65     exit(0);
66     }
67    
68     my $inpf = new IO::File;
69     open $inpf, "<$snapshot";
70     print "\n>>>>>>>>>>>>> Apply Snapshot\n\n" if ($verbose);
71     $res = ApplySnapshot($sconn, $inpf);
72     close $inpf;
73     die "\n>>>>>>>>>>>>> ERROR\n" if $res < 0;
74    
75     if ($res > 0)
76     {
77     print "Snapshot applied\n" if ($verbose);
78     unlink $snapshot unless ($debug);
79     SyncSync($mconn, $sconn);
80     }
81    
82     exit(0);
83    
84     ###########################################################################
85    
86     sub SyncSync
87     {
88     ($mconn, $sconn) = @_;
89    
90     print "\n>>>>>>>>>>>>> Sync SyncID\n\n" if ($verbose);
91     print "Get last SyncID from Slave DB\n" if ($verbose);
92     $syncid = GetSyncID($sconn);
93     if ($syncid > 0)
94     {
95     print "Last SyncID applied: $syncid\n" if ($verbose);
96     print "Sync SyncID\n" if ($verbose);
97    
98     $res = SyncSyncID($mconn, $server, $syncid);
99    
100     print "Succeeded\n" if (($res > 0) && ($verbose));
101     }
102     }

  ViewVC Help
Powered by ViewVC 1.1.26