Hi,

Here is a patch to let slony1_dump.sh connect to a distant database.

Regards,

-- 
Stéphane SCHILDKNECHT
Président de PostgreSQLFr
06 13 60 37 44 - 09 53 69 97 12
http://www.PostgreSQLFr.org

Index: slony1_dump.sh
===================================================================
--- slony1_dump.sh	(révision 888)
+++ slony1_dump.sh	(copie de travail)
@@ -13,32 +13,66 @@
 # ----
 # Check for correct usage
 # ----
-if test $# -ne 2 ; then
-	echo "usage: $0 subscriber-dbname clustername" >&2
-	exit 1
+if test $# -lt 2 ; then
+        echo "usage: $0 subscriber-dbname clustername [-H host] [-P port] [-U user]" >&2
+        exit 1
 fi
+dbname=$1
+cluster=$2
+clname="\"_$2\""
 
+shift 2
+
+TEMP=`getopt -n $0 -o hU:H:P:D:I -l help,user:,port:,host:,database:,instance: -- "$@"`
+if [ $? != 0 ] ; then
+        echo "$0 error..." >&2 ;
+        echo "Type $0 --help for help" ; exit 1 ;
+fi
+eval set -- "$TEMP"
+
+while [ $# -ge 1 ]; do
+  case "$1" in
+        -h|--help)
+                echo "usage: $0 subscriber-dbname clustername [-H host] [-P port] [-U user]" >&2
+		exit 0 ;;
+        -U|--user) shift ;
+                DBUSER="$1"
+                ;;
+        -H|--host) shift ;
+                DBHOST="$1"
+                ;;
+        -P|--port) shift ;
+                DBPORT="$1"
+                ;;
+    --) shift ;
+                break
+                ;;
+    *) echo "usage: $0 subscriber-dbname clustername [-h HOST] [-P PORT] [-U user]" >&2
+                exit 1
+                ;;
+  esac
+  shift
+done
+
 # ----
 # Remember call arguments and get the nodeId of the DB specified
 # ----
-dbname=$1
-cluster=$2
-clname="\"_$2\""
 pgc="\"pg_catalog\""
-nodeid=`psql -q -At -c "select \"_$cluster\".getLocalNodeId('_$cluster')" $dbname`
+pgopts="${DBHOST:+-h $DBHOST }${DBPORT:+-p $DBPORT }${DBUSER:+-U $DBUSER}"
+nodeid=`psql $pgopts -q -At -c "select \"_$cluster\".getLocalNodeId('_$cluster')" -d $dbname`
 
 # ----
 # Get a list of all replicated table ID's this subscriber receives,
 # and remember the table names.
 # ----
-tables=`psql -q -At -d $dbname -c \
+tables=`psql $pgopts -q -At -d $dbname -c \
 		"select tab_id from $clname.sl_table, $clname.sl_set
 				where tab_set = set_id
 					and exists (select 1 from $clname.sl_subscribe
 							where sub_set = set_id
 								and sub_receiver = $nodeid)"`
 for tab in $tables ; do
-	eval tabname_$tab=`psql -q -At -d $dbname -c \
+	eval tabname_$tab=`psql $pgopts -q -At -d $dbname -c \
 			"select $pgc.quote_ident(tab_nspname) || '.' || 
 					$pgc.quote_ident(tab_relname) from 
 					$clname.sl_table where tab_id = $tab"`
@@ -48,14 +82,14 @@
 # Get a list of all replicated sequence ID's this subscriber receives,
 # and remember the sequence names.
 # ----
-sequences=`psql -q -At -d $dbname -c \
+sequences=`psql $pgopts -q -At -d $dbname -c \
 		"select seq_id from $clname.sl_sequence, $clname.sl_set
 				where seq_set = set_id
 					and exists (select 1 from $clname.sl_subscribe
 							where sub_set = set_id
 								and sub_receiver = $nodeid)"`
 for seq in $sequences ; do
-	eval seqname_$seq=`psql -q -At -d $dbname -c \
+	eval seqname_$seq=`psql $pgopts -q -At -d $dbname -c \
 			"select $pgc.quote_ident(seq_nspname) || '.' || 
 					$pgc.quote_ident(seq_relname) from 
 					$clname.sl_sequence where seq_id = $seq"`
@@ -187,7 +187,7 @@
 # ----
 echo "select 'copy $clname.sl_sequence_offline from stdin;';"
 echo "select seq_id::text || ' ' || seq_relname  || '  ' || seq_nspname from $clname.sl_sequence;"
-printf "select '\\\\\\\\.';"
+printf "select E'\\\\\\\\.';"

 for seq in $sequences ; do
        eval seqname=\$seqname_$seq
@@ -212,7 +246,7 @@
 	eval tabname=\$tabname_$tab
 
 	# Get fieldnames...
- 	fields=`psql -At -c "select $clname.copyfields($tab);" $dbname`
+ 	fields=`psql $pgopts -At -c "select $clname.copyfields($tab);" -d $dbname`
  	echo "select 'copy $tabname $fields from stdin;';"
 	echo "copy $tabname $fields to stdout;"
  	printf "select E'\\\\\\\\.';"
@@ -215,7 +215,7 @@
        fields=`psql -At -c "select $clname.copyfields($tab);" $dbname`
        echo "select 'copy $tabname $fields from stdin;';"
        echo "copy $tabname $fields to stdout;"
-       printf "select '\\\\\\\\.';"
+       printf "select E'\\\\\\\\.';"
 done

 # ----
@@ -223,7 +257,7 @@
 # with the information.
 # ----
 echo "commit;"
-) | psql -q -At -d $dbname
+) | psql $pgopts -q -At -d $dbname
 
 # ----

_______________________________________________
Slony1-general mailing list
[email protected]
http://gborg.postgresql.org/mailman/listinfo/slony1-general

Reply via email to