1 |
#!/usr/bin/perl |
#!/usr/bin/perl -w |
2 |
# CleanLog |
# CleanLog |
3 |
# Vadim Mikheev, (c) 2000, PostgreSQL Inc. |
# Vadim Mikheev, (c) 2000, PostgreSQL Inc. |
4 |
|
|
6 |
& eval 'exec perl -S $0 $argv:q' |
& eval 'exec perl -S $0 $argv:q' |
7 |
if 0; |
if 0; |
8 |
|
|
9 |
use lib "/usr/share/postgresql/contrib"; |
BEGIN { |
10 |
|
my $basedir = $0; $basedir =~ s#/[^/]+$##; |
11 |
|
unshift(@INC, "$basedir/../share"); |
12 |
|
} |
13 |
|
|
14 |
|
use strict; |
15 |
use Getopt::Long; |
use Getopt::Long; |
16 |
use RServ; |
use RServ; |
17 |
|
|
18 |
$| = 1; |
$| = 1; |
19 |
|
|
20 |
$result = GetOptions("debug!", "verbose!", "help", "snapshot=s", |
my ($debug,$verbose) = (0,0); |
21 |
"host=s", "user=s", "password=s"); |
my ($help,$masterhost,$masterport,$masteruser,$masterpassword); |
22 |
|
my $snapshot = "__Snapshot"; |
23 |
my $debug = $opt_debug || 0; |
|
24 |
my $verbose = $opt_verbose || 0; |
my $result = GetOptions( |
25 |
my $snapshot = $opt_snapshot || "__Snapshot"; |
"debug!" => \$debug, "verbose!" => \$verbose, "help" => \$help, |
26 |
|
"masterhost=s" => \$masterhost, "masterport=i" => \$masterport, |
27 |
if (defined($opt_help) || (scalar(@ARGV) < 2) || ($ARGV[1] !~ /^\d+$/)) { |
"masteruser=s" => \$masteruser, "masterpassword=s" => \$masterpassword, |
28 |
print "Usage: $PROGRAM_NAME --host=name --user=name --password=string masterdb syncid\n"; |
"snapshot=s" => \$snapshot, |
29 |
exit ((scalar(@ARGV) < 2)? 1: 0); |
); |
30 |
|
|
31 |
|
if (defined($help) || (scalar(@ARGV) < 2) || ($ARGV[1] !~ /^\d+$/)) { |
32 |
|
print "Usage: $0 [options] masterdb syncid |
33 |
|
Options: |
34 |
|
--masterhost=hostname --masterport=port |
35 |
|
--masteruser=username --masterpassword=string |
36 |
|
--snapshot=snapshot |
37 |
|
"; |
38 |
|
exit ((scalar(@ARGV) < 2)? 1:0); |
39 |
} |
} |
40 |
|
|
41 |
my $dbname = $ARGV[0]; |
my $dbname = $ARGV[0]; |
42 |
my $howold = $ARGV[1]; |
my $howold = $ARGV[1]; |
43 |
|
|
44 |
my $minfo = "dbname=$dbname"; |
my $minfo = "dbname=$dbname"; |
45 |
$minfo = "$minfo host=$opt_host" if (defined($opt_host)); |
$minfo = "$minfo host=$masterhost" if (defined($masterhost)); |
46 |
$minfo = "$minfo user=$opt_user" if (defined($opt_user)); |
$minfo = "$minfo port=$masterport" if (defined($masterport)); |
47 |
$minfo = "$minfo password=$opt_password" if (defined($opt_password)); |
$minfo = "$minfo user=$masteruser" if (defined($masteruser)); |
48 |
|
$minfo = "$minfo password=$masterpassword" if (defined($masterpassword)); |
49 |
|
|
50 |
print "Master connection is $minfo\n" if ($debug); |
print "Master connection is $minfo\n" if ($debug); |
|
print "Slave connection is $sinfo\n" if ($debug); |
|
51 |
|
|
52 |
my $conn = Pg::connectdb($minfo); |
my $conn = Pg::connectdb($minfo); |
53 |
|
|
54 |
$res = CleanLog($conn, $howold); |
my $res = CleanLog($conn, $howold); |
55 |
|
|
56 |
exit(1) if $res < 0; |
exit(1) if $res < 0; |
57 |
|
|