forked from MasaoFujii/my-bin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pgbackup.sh
executable file
·77 lines (67 loc) · 1.32 KB
/
pgbackup.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
#!/bin/sh
. pgcommon.sh
MODE="normal" # normal, start or stop
usage ()
{
echo "$PROGNAME creates a base backup."
echo ""
echo "Usage:"
echo " $PROGNAME [OPTIONS] [PGDATA]"
echo ""
echo "Options:"
echo " --start executes only pg_start_backup"
echo " --stop executes only pg_stop_backup"
}
pg_start_backup ()
{
if [ $PGMAJOR -ge 91 ]; then
$PSQL "SET synchronous_commit TO local; SELECT pg_start_backup('pgbackup.sh', true)" template1
elif [ $PGMAJOR -ge 84 ]; then
$PSQL "SELECT pg_start_backup('pgbackup.sh', true)" template1
else
$PSQL "CHECKPOINT; SELECT pg_start_backup('pgbackup.sh')" template1
fi
}
pg_stop_backup ()
{
if [ $PGMAJOR -ge 91 ]; then
$PSQL "SET synchronous_commit TO local; SELECT pg_stop_backup()" template1
else
$PSQL "SELECT pg_stop_backup()" template1
fi
}
normal_backup ()
{
pg_start_backup
pgrsync.sh -b $PGDATA $PGDATABKP
pg_stop_backup
}
while [ $# -gt 0 ]; do
case "$1" in
"-?"|--help)
usage
exit 0;;
--start)
MODE="start";;
--stop)
MODE="stop";;
-*)
elog "invalid option: $1";;
*)
update_pgdata "$1";;
esac
shift
done
here_is_installation
validate_archiving
pgdata_exists
pgsql_is_alive
PSQL="$PGBIN/psql -p $PGPORT -c"
case "$MODE" in
normal)
normal_backup;;
start)
pg_start_backup;;
stop)
pg_stop_backup;;
esac