CVS User Account cvsuser
Mon Jan 10 18:22:59 PST 2005
Log Message:
-----------
Steve Simms changes - have usage, common config parameter, allow nodes
to be called 123 as well as node123

Modified Files:
--------------
    slony1-engine/tools/altperl:
        merge_sets.pl (r1.4 -> r1.5)

-------------- next part --------------
Index: merge_sets.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/merge_sets.pl,v
retrieving revision 1.4
retrieving revision 1.5
diff -Ltools/altperl/merge_sets.pl -Ltools/altperl/merge_sets.pl -u -w -r1.4 -r1.5
--- tools/altperl/merge_sets.pl
+++ tools/altperl/merge_sets.pl
@@ -1,45 +1,65 @@
-#!perl # -*- perl -*-
+#!/usr/bin/perl
 # $Id$
 # Author: Christopher Browne
 # Copyright 2004 Afilias Canada
 
+use Getopt::Long;
+
+$SLON_ENV_FILE = 'slon.env'; # Where to find the slon.env file
+$SHOW_USAGE    = 0;          # Show usage, then quit
+
+# Read command-line options
+GetOptions("config=s"  => \$SLON_ENV_FILE,
+	   "help"      => \$SHOW_USAGE);
+
+my $USAGE =
+"Usage: merge_sets.pl [--config file] node# set# set#
+
+    Merges the contents of the second set into the first one.
+
+";
+
+if ($SHOW_USAGE) {
+  print $USAGE;
+  exit 0;
+}
+
 require 'slon-tools.pm';
-require 'slon.env';
+require $SLON_ENV_FILE;
 
 my ($node, $set1, $set2) = @ARGV;
-if ($node =~ /^node(\d+)$/) {
+if ($node =~ /^(?:node)?(\d+)$/) {
   # Set name is in proper form
   $node = $1;
 } else {
   print "Valid node names are node1, node2, ...\n\n";
-  die "Usage: ./merge_sets.pl nodeN setOLD setNEW\n";
+  die $USAGE;
 }
 
-if ($set1 =~ /^set(\d+)$/) {
+if ($set1 =~ /^(?:set)?(\d+)$/) {
   $set1 = $1;
 } else {
   print "Valid set names are set1, set2, ...\n\n";
-  die "Usage: ./merge_sets.pl nodeN setOLD setNEW\n";
+  die $USAGE;
 }
-if ($set2 =~ /^set(\d+)$/) {
+
+if ($set2 =~ /^(?:set)?(\d+)$/) {
   $set2 = $1;
 } else {
   print "Valid set names are set1, set2, ...\n\n";
-  die "Usage: ./merge_sets.pl nodeN setOLD setNEW\n";
+  die $USAGE;
 }
 
-open(SLONIK, ">/tmp/slonik.$$");
-print SLONIK genheader();
-my ($dbname, $dbhost)=($DBNAME[1], $HOST[1]);
-print SLONIK qq[
-try {
-      merge set (id = $set1, add id = $set2, origin = $node);
-} on error {
-      echo 'Failure to merge sets $set1 and $set2 with origin $node';
-      exit 1;
-}
-echo 'Replication set $set2 merged in with $set1 on origin $node';
-];
+my ($dbname, $dbhost) = ($DBNAME[$MASTERNODE], $HOST[$MASTERNODE]);
 
+open(SLONIK, ">", "/tmp/slonik.$$");
+print SLONIK genheader();
+print SLONIK "  try {\n";
+print SLONIK "    merge set (id = $set1, add id = $set2, origin = $node);\n";
+print SLONIK "  } on error {\n";
+print SLONIK "    echo 'Failure to merge sets $set1 and $set2 with origin $node';\n";
+print SLONIK "    exit 1;\n";
+print SLONIK "  }\n";
+print SLONIK "  echo 'Replication set $set2 merged in with $set1 on origin $node';\n";
 close SLONIK;
 run_slonik_script("/tmp/slonik.$$");


More information about the Slony1-commit mailing list