fix A/R report
[freeside.git] / bin / slony-setup
1 #!/usr/bin/perl
2 #
3 # slony replication setup
4
5 # usage: slony-setup freesideuser
6
7 use strict;
8 use DBI;
9 use FS::UID qw(adminsuidsetup);
10 use FS::Record qw(dbdef);
11
12 my $user = shift or die "usage: slony-setup username\n";
13 adminsuidsetup($user);
14
15 #---
16
17 my $MASTERHOST = '192.168.20.10';
18 my $SLAVEHOST = '192.168.20.50';
19 #my $REPLICATIONUSER='pgsql';
20 my $REPLICATIONUSER='postgres';
21
22 #--------
23
24 print <<END;
25
26 #on slave:
27 useradd freeside
28 cp -pr /etc/skel /home/freeside
29 chown -R freeside /home/freeside
30
31 su postgres -c 'createuser freeside' #n y n
32 su freeside -c 'createdb freeside'
33
34 #on master:
35 su postgres -c 'createlang plpgsql freeside'
36
37 pg_dump -s -U $REPLICATIONUSER -h $MASTERHOST freeside | psql -U $REPLICATIONUSER -h $SLAVEHOST freeside
38
39 END
40
41 #--------
42
43 #drop set ( id = 1, origin = 1);
44
45 print <<END;
46 #on master:
47 slonik <<_EOF_
48
49 cluster name = freeside;
50 node 1 admin conninfo = 'dbname=freeside host=$MASTERHOST user=$REPLICATIONUSER';
51 node 2 admin conninfo = 'dbname=freeside host=$SLAVEHOST user=$REPLICATIONUSER';
52 init cluster ( id=1, comment = 'Master Node');
53
54 create set (id=1, origin=1, comment='All freeside tables');
55
56 END
57
58 my $id = 1;
59
60 foreach my $table ( dbdef->tables ) {
61   #next if $table =~ /^sql_/i;
62   print "set add table (set id=1, origin=1, id=". $id++. ", fully qualified name = 'public.$table' );\n";
63
64 }
65
66 print <<END;
67
68 store node (id=2, comment = 'Slave node');
69 store path (server = 1, client = 2, conninfo='dbname=freeside host=$MASTERHOST user=$REPLICATIONUSER');
70 store path (server = 2, client = 1, conninfo='dbname=freeside host=$SLAVEHOST user=$REPLICATIONUSER');
71 store listen (origin=1, provider = 1, receiver =2);
72 store listen (origin=2, provider = 2, receiver =1);
73
74 _EOF_
75 END
76
77 print <<END;
78
79 ### start slon processes (both machines) (this is debian-specific)
80 mkdir /etc/slony1/freeside
81
82 cat >/etc/slony1/freeside/slon.conf <<_EOF_
83 # Set the cluster name that this instance of slon is running against
84 # default is to read it off the command line
85 cluster_name='freeside'
86
87 # Set slon's connection info, default is to read it off the command line
88 conn_info='host=localhost port=5432 dbname=freeside user=postgres'
89 _EOF_
90
91 /etc/init.d/slony1 start
92
93 END
94
95
96 print <<END;
97 #on master:
98 slonik <<_EOF_
99
100 cluster name = freeside;
101
102 node 1 admin conninfo = 'dbname=freeside host=$MASTERHOST user=$REPLICATIONUSER';
103 node 2 admin conninfo = 'dbname=freeside host=$SLAVEHOST user=$REPLICATIONUSER';
104
105 subscribe set ( id = 1, provider = 1, receiver = 2, forward = no);
106
107 _EOF_
108 END
109