-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpgrsync.sh
executable file
·73 lines (62 loc) · 1.33 KB
/
pgrsync.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
#!/bin/sh
. pgcommon.sh
SRCDIR=
DSTDIR=
OPT="-a --delete"
BACKUP_MODE="FALSE"
make_path_canonical ()
{
DIRNAME=$(dirname "$1")
FILENAME=$(basename "$1")
echo "$DIRNAME/$FILENAME"
}
usage ()
{
cat <<EOF
$PROGNAME is a fast PostgreSQL-related file-copying tool.
Usage:
$PROGNAME [OPTIONS] SRCDIR DSTDIR
Description:
This utility is a wrapper of rsync, especially customized for PostgreSQL-related files and directories.
Options:
-b backup mode (excludes pg_xlog/pg_wal and postmaster.pid and deletes extraneous files)
-v increases verbosity
EOF
}
while [ $# -gt 0 ]; do
case "$1" in
"-?"|--help)
usage
exit 0;;
-b)
OPT="$OPT --delete --exclude=pg_xlog/* --exclude=pg_wal/* --exclude=postmaster.pid"
BACKUP_MODE="TRUE";;
-v)
OPT="$OPT -v";;
-*)
elog "invalid option: $1";;
*)
if [ -z "$SRCDIR" ]; then
SRCDIR=$(make_path_canonical "$1")
elif [ -z "$DSTDIR" ]; then
DSTDIR=$(make_path_canonical "$1")
else
elog "too many arguments"
fi
;;
esac
shift
done
if [ -z "$SRCDIR" -o -z "$DSTDIR" ]; then
elog "SRCDIR and DSTDIR must be supplied"
fi
rsync $OPT $SRCDIR/ $DSTDIR
if [ "$BACKUP_MODE" = "TRUE" ]; then
if [ -d $DSTDIR/pg_xlog ]; then
rm -rf $DSTDIR/pg_xlog/*
mkdir $DSTDIR/pg_xlog/archive_status
else
rm -rf $DSTDIR/pg_wal/*
mkdir $DSTDIR/pg_wal/archive_status
fi
fi