summaryrefslogtreecommitdiff
path: root/sql/configure-replication.sh
blob: 9edad3a97d2bbb2c921b8f403a836fc438e7b401 (plain)
  1. #!/bin/bash
  2. # $Id$
  3. # Global defaults
  4. CLUSTER=${CLUSTER:-"LedgerSMB"}
  5. NUMNODES=${NUMNODES:-"2"}
  6. # Defaults - origin node
  7. DB1=${DB1:-${PGDATABASE:-"ledgersmb"}}
  8. HOST1=${HOST1:-`hostname`}
  9. USER1=${USER1:-${PGUSER:-"slony"}}
  10. PORT1=${PORT1:-${PGPORT:-"5432"}}
  11. # Defaults - node 2
  12. DB2=${DB2:-${PGDATABASE:-"ledgersmb"}}
  13. HOST2=${HOST2:-"backup.example.info"}
  14. USER2=${USER2:-${PGUSER:-"slony"}}
  15. PORT2=${PORT2:-${PGPORT:-"5432"}}
  16. # Defaults - node 3
  17. DB3=${DB3:-${PGDATABASE:-"ledgersmb"}}
  18. HOST3=${HOST3:-"backup3.example.info"}
  19. USER3=${USER3:-${PGUSER:-"slony"}}
  20. PORT3=${PORT3:-${PGPORT:-"5432"}}
  21. # Defaults - node 4
  22. DB4=${DB4:-${PGDATABASE:-"ledgersmb"}}
  23. HOST4=${HOST4:-"backup4.example.info"}
  24. USER4=${USER4:-${PGUSER:-"slony"}}
  25. PORT4=${PORT4:-${PGPORT:-"5432"}}
  26. # Defaults - node 5
  27. DB5=${DB5:-${PGDATABASE:-"ledgersmb"}}
  28. HOST5=${HOST5:-"backup5.example.info"}
  29. USER5=${USER5:-${PGUSER:-"slony"}}
  30. PORT5=${PORT5:-${PGPORT:-"5432"}}
  31. store_path()
  32. {
  33. echo "include <${PREAMBLE}>;" > $mktmp/store_paths.slonik
  34. i=1
  35. while : ; do
  36. eval db=\$DB${i}
  37. eval host=\$HOST${i}
  38. eval user=\$USER${i}
  39. eval port=\$PORT${i}
  40. if [ -n "${db}" -a "${host}" -a "${user}" -a "${port}" ]; then
  41. j=1
  42. while : ; do
  43. if [ ${i} -ne ${j} ]; then
  44. eval bdb=\$DB${j}
  45. eval bhost=\$HOST${j}
  46. eval buser=\$USER${j}
  47. eval bport=\$PORT${j}
  48. if [ -n "${bdb}" -a "${bhost}" -a "${buser}" -a "${bport}" ]; then
  49. echo "STORE PATH (SERVER=${i}, CLIENT=${j}, CONNINFO='dbname=${db} host=${host} user=${user} port=${port}');" >> $mktmp/store_paths.slonik
  50. else
  51. err 3 "No conninfo"
  52. fi
  53. fi
  54. if [ ${j} -ge ${NUMNODES} ]; then
  55. break;
  56. else
  57. j=$((${j} + 1))
  58. fi
  59. done
  60. if [ ${i} -ge ${NUMNODES} ]; then
  61. break;
  62. else
  63. i=$((${i} +1))
  64. fi
  65. else
  66. err 3 "no DB"
  67. fi
  68. done
  69. }
  70. mktmp=`mktemp -d -t ledgersmb-temp.XXXXXX`
  71. if [ $MY_MKTEMP_IS_DECREPIT ] ; then
  72. mktmp=`mktemp -d /tmp/ledgersmb-temp.XXXXXX`
  73. fi
  74. PREAMBLE=${mktmp}/preamble.slonik
  75. echo "cluster name=${CLUSTER};" > $PREAMBLE
  76. alias=1
  77. while : ; do
  78. eval db=\$DB${alias}
  79. eval host=\$HOST${alias}
  80. eval user=\$USER${alias}
  81. eval port=\$PORT${alias}
  82. if [ -n "${db}" -a "${host}" -a "${user}" -a "${port}" ]; then
  83. conninfo="dbname=${db} host=${host} user=${user} port=${port}"
  84. echo "NODE ${alias} ADMIN CONNINFO = '${conninfo}';" >> $PREAMBLE
  85. if [ ${alias} -ge ${NUMNODES} ]; then
  86. break;
  87. else
  88. alias=`expr ${alias} + 1`
  89. fi
  90. else
  91. break;
  92. fi
  93. done
  94. SEQUENCES=" acc_trans_entry_id_seq audittrail_entry_id_seq
  95. custom_field_catalog_field_id_seq custom_table_catalog_table_id_seq
  96. id inventory_entry_id_seq invoiceid jcitemsid orderitemsid
  97. partscustomer_entry_id_seq partsvendor_entry_id_seq
  98. session_session_id_seq shipto_entry_id_seq "
  99. TABLES=" acc_trans ap ar assembly audittrail business chart
  100. custom_field_catalog custom_table_catalog customer customertax
  101. defaults department dpt_trans employee exchangerate gifi gl inventory
  102. invoice jcitems language makemodel oe orderitems parts partscustomer
  103. partsgroup partstax partsvendor pricegroup project recurring
  104. recurringemail recurringprint session shipto sic status tax
  105. transactions translation vendor vendortax warehouse yearend"
  106. SETUPSET=${mktmp}/create_set.slonik
  107. echo "include <${PREAMBLE}>;" > $SETUPSET
  108. echo "create set (id=1, origin=1, comment='${CLUSTER} Tables and Sequences');" >> $SETUPSET
  109. tnum=1
  110. for table in `echo $TABLES`; do
  111. echo "set add table (id=${tnum}, set id=1, origin=1, fully qualified name='public.${table}', comment='${CLUSTER} table ${table}');" >> $SETUPSET
  112. tnum=`expr ${tnum} + 1`
  113. done
  114. snum=1
  115. for seq in `echo $SEQUENCES`; do
  116. echo "set add sequence (id=${snum}, set id=1, origin=1, fully qualified name='public.${seq}', comment='${CLUSTER} sequence ${seq}');" >> $SETUPSET
  117. snum=`expr ${snum} + 1`
  118. done
  119. NODEINIT=$mktmp/create_nodes.slonik
  120. echo "include <${PREAMBLE}>;" > $NODEINIT
  121. echo "init cluster (id=1, comment='${CLUSTER} node 1');" >> $NODEINIT
  122. node=2
  123. while : ; do
  124. SUBFILE=$mktmp/subscribe_set_${node}.slonik
  125. echo "include <${PREAMBLE}>;" > $SUBFILE
  126. echo "store node (id=${node}, comment='${CLUSTER} subscriber node ${node}');" >> $NODEINIT
  127. echo "subscribe set (id=1, provider=1, receiver=${node}, forward=yes);" >> $SUBFILE
  128. if [ ${node} -ge ${NUMNODES} ]; then
  129. break;
  130. else
  131. node=`expr ${node} + 1`
  132. fi
  133. done
  134. store_path
  135. echo "
  136. $0 has generated Slony-I slonik scripts to initialize replication for LedgerSMB.
  137. Cluster name: ${CLUSTER}
  138. Number of nodes: ${NUMNODES}
  139. Scripts are in ${mktmp}
  140. =====================
  141. "
  142. ls -l $mktmp
  143. echo "
  144. =====================
  145. Be sure to verify that the contents of $PREAMBLE very carefully, as
  146. the configuration there is used widely in the other scripts.
  147. =====================
  148. ====================="