22 |
my ($help,$masterhost,$masterport,$masteruser,$masterpassword, |
my ($help,$masterhost,$masterport,$masteruser,$masterpassword, |
23 |
$slavehost,$slaveport,$slaveuser,$slavepassword); |
$slavehost,$slaveport,$slaveuser,$slavepassword); |
24 |
my $snapshot = ".__Snapshot"; |
my $snapshot = ".__Snapshot"; |
25 |
my $multiplemaster = 0; |
my $multimaster = 0; |
26 |
|
|
27 |
my $result = GetOptions( |
my $result = GetOptions( |
28 |
"debug!" => \$debug, "verbose!" => \$verbose, "help" => \$help, |
"debug!" => \$debug, "verbose!" => \$verbose, "help" => \$help, |
31 |
"slavehost=s" => \$slavehost, "slaveport=i" => \$slaveport, |
"slavehost=s" => \$slavehost, "slaveport=i" => \$slaveport, |
32 |
"slaveuser=s" => \$slaveuser, "slavepassword=s" => \$slavepassword, |
"slaveuser=s" => \$slaveuser, "slavepassword=s" => \$slavepassword, |
33 |
"snapshot=s" => \$snapshot, |
"snapshot=s" => \$snapshot, |
34 |
"multiplemaster" => \$multiplemaster, |
"multimaster" => \$multimaster, |
35 |
); |
); |
36 |
|
|
37 |
if (defined($help) || (scalar(@ARGV) < 2)) { |
if (defined($help) || (scalar(@ARGV) < 2)) { |
102 |
print "Master connection is $minfo\n" if ($debug); |
print "Master connection is $minfo\n" if ($debug); |
103 |
print "Slave connection is $sinfo\n" if ($debug); |
print "Slave connection is $sinfo\n" if ($debug); |
104 |
|
|
105 |
my $mconn = Pg::connectdb($minfo); |
my $mconn = Connect($minfo); |
106 |
if ($mconn->status != Pg::PGRES_CONNECTION_OK) { |
my $sconn = Connect($sinfo); |
|
print STDERR "Failed opening $minfo\n"; |
|
|
unlink $fname; |
|
|
exit 1; |
|
|
} |
|
|
my $sconn = Pg::connectdb($sinfo); |
|
|
if ($sconn->status != Pg::PGRES_CONNECTION_OK) { |
|
|
print STDERR "Failed opening $sinfo\n"; |
|
|
unlink $fname; |
|
|
exit 1; |
|
|
} |
|
107 |
|
|
108 |
$slavehost = 'localhost' if (! $slavehost); |
$slavehost = 'localhost' if (! $slavehost); |
109 |
$masterhost = 'localhost' if (! $masterhost); |
$masterhost = 'localhost' if (! $masterhost); |
116 |
unlink $fname; |
unlink $fname; |
117 |
die "\n>>>>>>>>>>>>> ERROR: GetServerId returned $slaveId < 0\n"; |
die "\n>>>>>>>>>>>>> ERROR: GetServerId returned $slaveId < 0\n"; |
118 |
} |
} |
119 |
SyncSync($mconn, $sconn); |
#SyncSync($mconn, $sconn); |
120 |
|
|
121 |
my $masterId = 0; |
my $masterId = GetServerId($mconn, $master, $masterhost); |
|
if ($multiplemaster || $slaveId == 0) { |
|
|
$masterId = GetServerId($mconn, $master, $masterhost); |
|
122 |
|
|
123 |
die "\n>>>>>>>>>>>>> ERROR: Can't GetServerId for $sinfo\n" if (! defined($masterId)); |
die "\n>>>>>>>>>>>>> ERROR: Can't GetServerId for $sinfo\n" if (! defined($masterId)); |
124 |
|
|
125 |
if ($masterId < 0) { |
if ($masterId < 0) { |
126 |
unlink $fname; |
unlink $fname; |
127 |
die "\n>>>>>>>>>>>>> ERROR: GetServerId returned $masterId < 0\n"; |
die "\n>>>>>>>>>>>>> ERROR: GetServerId returned $masterId < 0\n"; |
|
} |
|
|
SyncSync($sconn, $mconn); |
|
128 |
} |
} |
129 |
|
#SyncSync($sconn, $mconn); |
130 |
|
|
131 |
print "Using snapshot file: $snapshot\n" if ($debug); |
print "Using snapshot file: $snapshot\n" if ($debug); |
132 |
|
|
134 |
open $outf, ">$snapshot"; |
open $outf, ">$snapshot"; |
135 |
print "\n>>>>>>>>>>>>> Prepare Snapshot\n\n" if ($verbose); |
print "\n>>>>>>>>>>>>> Prepare Snapshot\n\n" if ($verbose); |
136 |
print "master id: $masterId slave id: $slaveId\n" if ($debug); |
print "master id: $masterId slave id: $slaveId\n" if ($debug); |
137 |
my $res = PrepareSnapshot($mconn, $sconn, $outf, $masterId, $slaveId, $multiplemaster, $tables); |
#my $res = PrepareSnapshot($mconn, $sconn, $outf, $masterId, $slaveId, $multimaster, $tables); |
138 |
|
my $res = PrepareSnapshot($mconn, $sconn, $outf, $masterId, $slaveId, $multimaster); |
139 |
close $outf; |
close $outf; |
140 |
if ($res < 0) { |
if ($res < 0) { |
141 |
unlink $fname; |
unlink $fname; |
152 |
my $inpf = new IO::File; |
my $inpf = new IO::File; |
153 |
open $inpf, "<$snapshot"; |
open $inpf, "<$snapshot"; |
154 |
print "\n>>>>>>>>>>>>> Apply Snapshot\n\n" if ($verbose); |
print "\n>>>>>>>>>>>>> Apply Snapshot\n\n" if ($verbose); |
155 |
$res = ApplySnapshot($sconn, $inpf, $multiplemaster, $tables); |
#$res = ApplySnapshot($sconn, $inpf, $multimaster, $tables); |
156 |
|
$res = ApplySnapshot($sconn, $inpf, $multimaster); |
157 |
close $inpf; |
close $inpf; |
158 |
if ($res < 0) { |
if ($res < 0) { |
159 |
unlink $fname; |
unlink $fname; |