-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpgwarmsby.sh
executable file
·112 lines (90 loc) · 2.15 KB
/
pgwarmsby.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/sh
. pgcommon.sh
PGSTANDBY=$PGBIN/pg_standby
ACTDATA=$CURDIR/data
ACTCONF=$ACTDATA/$GUCFILENAME
ACTPORT=5432
ACTPREFIX=data
SBYDATA=$CURDIR/sby
SBYCONF=$SBYDATA/$GUCFILENAME
SBYPORT=5433
SBYPREFIX=sby
PGARCH=$ACTDATA.arch
PGBKP=$ACTDATA.bkp
TRIGGER=$CURDIR/trigger
RECOVERYCONF=$SBYDATA/$RECFILENAME
RECOVERYSIGNAL=$SBYDATA/$RECSIGNALNAME
STANDBYSIGNAL=$SBYDATA/$SBYSIGNALNAME
COPYMODE=false
usage ()
{
cat <<EOF
$PROGNAME configures warm-standby
Usage:
$PROGNAME [OPTIONS]
Description:
$PROGNAME creates warm-standby environement by using pg_standby as
restore_command by default.
Options:
-c, --copy use 'cp' as restore_command (possible in 9.0 or later)
EOF
}
while [ $# -gt 0 ]; do
case "$1" in
-c|--copy)
COPYMODE=true;;
"-?"|--help)
usage
exit 0;;
*)
elog "invalid option: $1";;
esac
shift
done
here_is_installation
validate_archiving
if [ $PGMAJOR -lt 82 ]; then
elog "warm-standby is not supported"
fi
if [ "$COPYMODE" = "true" ]; then
if [ $PGMAJOR -lt 90 ]; then
elog "copy mode (-c) requires v9.0 or later"
fi
else
if [ ! -f $PGSTANDBY ]; then
elog "pg_standby must be installed"
fi
fi
rm -rf $ACTDATA $SBYDATA $PGARCH $TRIGGER
pginitdb.sh $ACTDATA
pgarch.sh $ACTDATA
set_guc port $ACTPORT $ACTCONF
set_guc log_line_prefix "'$LOGLINEPREFIX $ACTPREFIX '" $ACTCONF
pgstart.sh -w $ACTDATA
pgbackup.sh $ACTDATA
cp -r $PGBKP $SBYDATA
set_guc port $SBYPORT $SBYCONF
set_guc log_line_prefix "'$LOGLINEPREFIX $SBYPREFIX '" $SBYCONF
if [ $PGMAJOR -ge 90 ]; then
set_guc hot_standby on $SBYCONF
fi
if [ "$COPYMODE" = "true" ]; then
if [ $PGMAJOR -ge 120 ]; then
set_guc restore_command "'cp $PGARCH/%f %p'" $SBYCONF
set_guc promote_trigger_file "'$TRIGGER'" $SBYCONF
touch $STANDBYSIGNAL
else
echo "standby_mode = 'on'" >> $RECOVERYCONF
echo "restore_command = 'cp $PGARCH/%f %p'" >> $RECOVERYCONF
echo "trigger_file = '$TRIGGER'" >> $RECOVERYCONF
fi
else
RESTORECMD="$PGSTANDBY -t $TRIGGER -r 1 $PGARCH %f %p"
if [ $PGMAJOR -ge 120 ]; then
set_guc restore_command "'$RESTORECMD'" $SBYCONF
touch $RECOVERYSIGNAL
else
echo "restore_command = '$RESTORECMD'" > $RECOVERYCONF
fi
fi
pgstart.sh $SBYDATA