2000-12-21 01:22:35 +08:00
|
|
|
# -*- perl -*-
|
|
|
|
# ApplySnapshot
|
|
|
|
# Vadim Mikheev, (c) 2000, PostgreSQL Inc.
|
|
|
|
|
|
|
|
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
|
|
|
|
& eval 'exec perl -S $0 $argv:q'
|
|
|
|
if 0;
|
|
|
|
|
|
|
|
use lib "@LIBDIR@";
|
|
|
|
use IO::File;
|
|
|
|
use RServ;
|
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
$| = 1;
|
|
|
|
|
|
|
|
$result = GetOptions("debug!", "verbose!", "help",
|
|
|
|
"host=s", "user=s", "password=s");
|
|
|
|
|
|
|
|
my $debug = $opt_debug || 0;
|
|
|
|
my $verbose = $opt_verbose || 0;
|
|
|
|
my $snapshot = $opt_snapshot || "__Snapshot";
|
|
|
|
|
|
|
|
if (defined($opt_help) || (scalar(@ARGV) < 1)) {
|
|
|
|
print "Usage: $0 --host=name --user=name --password=string slavedb\n";
|
|
|
|
exit ((scalar(@ARGV) < 1)? 1:0);
|
|
|
|
}
|
|
|
|
|
|
|
|
my $slave = $ARGV[0] || "slave";
|
|
|
|
|
|
|
|
my $sinfo = "dbname=$slave";
|
|
|
|
$sinfo = "$sinfo host=$opt_host" if (defined($opt_host));
|
|
|
|
$sinfo = "$sinfo user=$opt_user" if (defined($opt_user));
|
|
|
|
$sinfo = "$sinfo password=$opt_password" if (defined($opt_password));
|
|
|
|
|
2002-03-07 04:41:36 +08:00
|
|
|
my $conn = Pg::connectdb($sinfo);
|
2000-12-21 01:22:35 +08:00
|
|
|
|
|
|
|
my $inpf = new IO::File;
|
|
|
|
$inpf = STDIN;
|
|
|
|
|
2002-03-07 04:41:36 +08:00
|
|
|
$RServ::quiet = !$verbose;
|
|
|
|
|
2000-12-21 01:22:35 +08:00
|
|
|
$res = ApplySnapshot ($conn, $inpf);
|
|
|
|
|
|
|
|
if ($res > 0)
|
|
|
|
{
|
|
|
|
printf STDERR "Snapshot applied\n";
|
|
|
|
}
|
|
|
|
elsif ($res != 0)
|
|
|
|
{
|
|
|
|
printf STDERR "ERROR\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(0);
|