-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpgdbdump.sh
More file actions
66 lines (62 loc) · 1.81 KB
/
pgdbdump.sh
File metadata and controls
66 lines (62 loc) · 1.81 KB
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
#!/bin/sh
#####################
# pgdbdump v1.0
#####################
# Script for creating full, differential or incremental dumps of postgres databases
# (C) 2024 Sergey Merzlikin sm@smsoft.ru
#####################
# $1 = database name to dump
# $2 may be "diff", "inc" or empty, in case "diff" and "inc" differential and incremental dump created, otherwise full
# Logs informational messages to syslog/systemd journal if corresponding parameter in dumpconfig.sh exist
#####################
# Licensed under the GNU General Public License v3.0
#####################
scriptdir="$(dirname "$(realpath "$0")")"
. /etc/pgdbdump/dumpconfig.sh
Log()
# allows to log to syslog/systemd journal
{
logger -t "pgdbdump" "$@"
}
Dumpfull() {
# Make full dump
o=$("$scriptdir/pgdbdump_full.sh" "$1")
e=$?
[ "$logger" = 1 ] && [ -n "$o" ] && Log "$o"
[ -n "$o" ] && echo $o
return $e
}
Dumpdiff() {
# Make differential or incremental dump
o=$("$scriptdir/pgdbdump_diff.sh" "$1" "$2")
e=$?
[ "$logger" = 1 ] && [ -n "$o" ] && Log "$o"
if [ $e -eq 13 ] || [ $e -eq 14 ] ; then
# Make full dump if previous full or incremental dump doesn't exist
Dumpfull $1
else
[ -n "$o" ] && echo $o
return $e
fi
}
case "$2" in
diff)
[ "$logger" = 1 ] && Log "Differential dump of database \"$1\" started"
Dumpdiff "$1"
e=$?
[ "$logger" = 1 ] && [ $e -eq 0 ] && Log "Differential dump of database \"$1\" completed"
;;
inc)
[ "$logger" = 1 ] && Log "Incremental dump of database \"$1\" started"
Dumpdiff "$1" inc
e=$?
[ "$logger" = 1 ] && [ $e -eq 0 ] && Log "Incremental dump of database \"$1\" completed"
;;
*)
[ "$logger" = 1 ] && Log "Full dump of database \"$1\" started"
Dumpfull "$1"
e=$?
[ "$logger" = 1 ] && [ $e -eq 0 ] && Log "Full dump of database \"$1\" completed"
;;
esac
exit $e