/[rserv]/bin/SlaveRemove
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/SlaveRemove

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Tue Aug 5 09:52:36 2003 UTC (20 years, 10 months ago) by dpavlin
Branch: MAIN
rserv 0.2 changes by Nélio Alves Pereira Filho

1 dpavlin 1.1 #!/usr/bin/perl
2     # SlaveInit
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     use Pg;
10     use Getopt::Long;
11     use Sys::Hostname;
12    
13     $| = 1;
14    
15     $result = GetOptions("debug!", "verbose!", "quiet!", "help",
16     "masterhost=s", "masteruser=s", "masterpassword=s",
17     "slavehost=s", "slaveuser=s", "slavepassword=s");
18    
19     my $debug = $opt_debug || 0;
20     my $verbose = $opt_verbose || 0;
21     my $quiet = $opt_quiet || 0;
22    
23     if (defined($opt_help) || (scalar(@ARGV) < 1)) {
24     print "Usage: $0 --masterhost=name --masteruser=name --masterpassword=string --slavehost=name --slaveuser=name --slavepassword=string masterdb slavedb\n";
25     exit ((scalar(@ARGV) < 1)? 1:0);
26     }
27    
28     my $master = $ARGV[0] || "master";
29     my $slave = $ARGV[1] || "slave";
30    
31     my $sinfo = "dbname=$slave";
32     $sinfo = "$sinfo host=$opt_slavehost" if (defined($opt_slavehost));
33     $sinfo = "$sinfo user=$opt_slaveuser" if (defined($opt_slaveuser));
34     $sinfo = "$sinfo password=$opt_slavepassword" if (defined($opt_slavepassword));
35    
36     my $minfo = "dbname=$master";
37     $minfo = "$minfo host=$opt_masterhost" if (defined($opt_masterhost));
38     $minfo = "$minfo user=$opt_masteruser" if (defined($opt_masteruser));
39     $minfo = "$minfo password=$opt_masterpassword" if (defined($opt_masterpassword));
40    
41     sub RollbackAndQuit {
42     my $conn = shift @_;
43    
44     print STDERR $conn->errorMessage;
45     $conn->exec("ROLLBACK");
46     exit (-1);
47     }
48    
49     # First, lets add the needed information in the slave database
50    
51     print("Connecting to $sinfo\n") if ($debug || $verbose);
52     my $conn = Pg::connectdb($sinfo);
53     if ($conn->status != PGRES_CONNECTION_OK) {
54     print STDERR "Failed opening $sinfo\n";
55     exit 1;
56     }
57    
58     my $result = $conn->exec("BEGIN");
59     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
60    
61     $result = $conn->exec("set transaction isolation level serializable");
62     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
63    
64     $result = $conn->exec("DROP TABLE _RSERV_SLAVE_TABLES_");
65     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
66    
67     $result = $conn->exec("DROP TABLE _RSERV_SLAVE_SYNC_");
68     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
69    
70     $result = $conn->exec("COMMIT");
71     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
72    
73    
74     # next, let's tell the master that the slave is gone.
75    
76     print("Connecting to $minfo\n") if ($debug || $verbose);
77     $conn = Pg::connectdb($minfo);
78     if ($conn->status != PGRES_CONNECTION_OK) {
79     print STDERR "Failed opening $minfo\n";
80     exit 1;
81     }
82    
83    
84     $host = defined($opt_slavehost) ? $opt_slavehost : hostname;
85    
86     $result = $conn->exec("DELETE FROM _RSERV_SERVERS_ WHERE host='$host' AND dbase='$slave'");
87     if ($result->resultStatus ne PGRES_COMMAND_OK) {
88     print STDERR $conn->errorMessage;
89     exit (-1);
90     }
91    
92    
93     exit (0);

  ViewVC Help
Powered by ViewVC 1.1.26