1 |
dpavlin |
1.1 |
# -*- perl -*- |
2 |
|
|
# ApplySnapshot |
3 |
|
|
# Vadim Mikheev, (c) 2000, PostgreSQL Inc. |
4 |
|
|
|
5 |
|
|
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' |
6 |
|
|
& eval 'exec perl -S $0 $argv:q' |
7 |
|
|
if 0; |
8 |
|
|
|
9 |
|
|
use lib "@LIBDIR@"; |
10 |
|
|
use IO::File; |
11 |
|
|
use RServ; |
12 |
|
|
use Getopt::Long; |
13 |
|
|
|
14 |
|
|
$| = 1; |
15 |
|
|
|
16 |
|
|
$result = GetOptions("debug!", "verbose!", "help", |
17 |
|
|
"host=s", "user=s", "password=s"); |
18 |
|
|
|
19 |
|
|
my $debug = $opt_debug || 0; |
20 |
|
|
my $verbose = $opt_verbose || 0; |
21 |
|
|
my $snapshot = $opt_snapshot || "__Snapshot"; |
22 |
|
|
|
23 |
|
|
if (defined($opt_help) || (scalar(@ARGV) < 1)) { |
24 |
|
|
print "Usage: $0 --host=name --user=name --password=string slavedb\n"; |
25 |
|
|
exit ((scalar(@ARGV) < 1)? 1:0); |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
my $slave = $ARGV[0] || "slave"; |
29 |
|
|
|
30 |
|
|
my $sinfo = "dbname=$slave"; |
31 |
|
|
$sinfo = "$sinfo host=$opt_host" if (defined($opt_host)); |
32 |
|
|
$sinfo = "$sinfo user=$opt_user" if (defined($opt_user)); |
33 |
|
|
$sinfo = "$sinfo password=$opt_password" if (defined($opt_password)); |
34 |
|
|
|
35 |
|
|
my $conn = Pg::connectdb(sinfo); |
36 |
|
|
|
37 |
|
|
my $inpf = new IO::File; |
38 |
|
|
$inpf = STDIN; |
39 |
|
|
|
40 |
|
|
$res = ApplySnapshot ($conn, $inpf); |
41 |
|
|
|
42 |
|
|
if ($res > 0) |
43 |
|
|
{ |
44 |
|
|
printf STDERR "Snapshot applied\n"; |
45 |
|
|
} |
46 |
|
|
elsif ($res != 0) |
47 |
|
|
{ |
48 |
|
|
printf STDERR "ERROR\n"; |
49 |
|
|
exit(1); |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
exit(0); |