-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpgdbdump_common.sh
More file actions
76 lines (74 loc) · 1.49 KB
/
pgdbdump_common.sh
File metadata and controls
76 lines (74 loc) · 1.49 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
67
68
69
70
71
72
73
74
75
76
#####################
# pgdbdump_common v1.0
#####################
# Common parts for scripts related to creating dumps of postgres databases
# (C) 2023-2024 Sergey Merzlikin sm@smsoft.ru
#####################
# Licensed under the GNU General Public License v3.0
#####################
Exists()
{
command -v "$1" >/dev/null 2>&1
}
Compress()
{
if [ "$compress" = "auto" ] ; then
size=$(stat -c %s "$1")
if [ "$size" -gt 52428800 ] ; then
if Exists "lrzip" ; then
compress="lrzipz"
elif Exists "pixz" ; then
compress="pixz"
else
compress="xz"
fi
else
if Exists "pixz" ; then
compress="pixz"
else
compress="xz"
fi
fi
fi
case "$compress" in
lrzip)
echo ".lrz"
lrzip -D -f -Q "$1" > /dev/null
;;
lrzipz)
echo ".lrz"
lrzip -D -f -Q -z "$1" > /dev/null
;;
7-zip)
echo ".7z"
7za a "$1.7z" "$1" -bd -sdel > /dev/null
;;
pixz)
echo ".xz"
pixz "$1" > /dev/null
;;
*)
echo ".xz"
xz -T0 -q -f "$1" > /dev/null
;;
esac
}
#####################
# Execution starts here
# Some defaults
compress="auto"
pguser="postgres"
# Process config file
. /etc/pgdbdump/dumpconfig.sh
if [ -z "$1" ] ; then
echo "Database name not specified"
exit 7
fi
if [ -z "$backdir" ] ; then
echo "Backup directory not specified"
exit 8
fi
# if base name contains characters '_' or '%' replace them by '%1' and '%0' accordingly
dbname=$(echo "$1" | sed -e 's/%/%0/g; s/_/%1/g')
backpath="$backdir/$dbname"
#####################